/**
 * Copyright © 2016-2018 Jesse Gallagher
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package bean;

import java.text.DateFormatSymbols;
import java.text.MessageFormat;
import java.util.ResourceBundle;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.literal.NamedLiteral;
import javax.enterprise.inject.spi.CDI;
import javax.inject.Named;

// TODO switch to app scoped and use request locale
@RequestScoped
public class TranslationBean {
	@Produces @Named("translation")
	public ResourceBundle getTranslation() {
		return ResourceBundle.getBundle("translation"); //$NON-NLS-1$
	}
	
	@Produces @Named("messages")
	public Messages getMessages() {
		return Messages.INSTANCE;
	}
	
	public static final class Messages {
		public static final Messages INSTANCE = new Messages();
		
		public String format(String key, Object... params) {
			ResourceBundle translation = CDI.current().select(ResourceBundle.class, NamedLiteral.of("translation")).get(); //$NON-NLS-1$
			String message = translation.getString(key);
			return MessageFormat.format(message, params);
		}

		public String getMonth(int index) {
			return DateFormatSymbols.getInstance().getMonths()[index];
		}
	}
}

@@ -922,67 +922,89 @@
 ect.
-Named;%0A%0A// TODO switch to app scoped and use request locale
+Inject;%0Aimport javax.inject.Named;%0Aimport javax.servlet.http.HttpServletRequest;%0A
 %0A@Re
@@ -1046,16 +1046,55 @@
 nBean %7B%0A
+%09@Inject%0A%09HttpServletRequest request;%0A%0A
 %09@Produc
@@ -1207,16 +1207,37 @@
 slation%22
+, request.getLocale()
 ); //$NO
@@ -1252,21 +1252,26 @@
 %0A%09%7D%0A
-%09
 %0A%09@
-Produces 
+RequestScoped%0A%09
 @Nam
@@ -1297,160 +1297,70 @@
 lic 
-Messages getMessages() %7B%0A%09%09return Messages.INSTANCE;%0A%09%7D%0A%09%0A%09public static final class Messages %7B%0A%09%09public static final Messages INSTANCE = new Messages()
+static class Messages %7B%0A%09%09@Inject%0A%09%09HttpServletRequest request
 ;%0A%09%09
@@ -1723,16 +1723,35 @@
 nstance(
+request.getLocale()
 ).getMon

Fix translation use of locale