/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.ocelotds;

import org.ocelotds.context.ThreadLocalContextHolder;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.inject.Inject;
import org.ocelotds.annotations.OcelotLogger;
import org.slf4j.Logger;

/**
 *
 * @author hhfrancois
 */
public class OcelotI18nServices {
	@Inject
	@OcelotLogger
	private Logger logger;
	
	public Locale getUserLocale() {
		logger.debug("Get locale from OcelotServices");
		Locale locale = (Locale) ThreadLocalContextHolder.get(Constants.LOCALE);
		if(null==locale) {
			logger.debug("Get locale from OcelotServices : default");
			locale =  new Locale("en", "US");
		}
		logger.debug("Get locale from OcelotServices : {}", locale);
		return locale;
		
	}
	
	public String getLocalizedMessage(String bundleName, String entry, Object[] args) {
		ResourceBundle bundle = ResourceBundle.getBundle(bundleName, getUserLocale());
		return MessageFormat.format(bundle.getString(entry), args);
	}
}

@@ -230,63 +230,8 @@
 %0D%0A%0D%0A
-import org.ocelotds.context.ThreadLocalContextHolder;%0D%0A
 impo
@@ -255,24 +255,24 @@
 ageFormat;%0D%0A
+
 import java.
@@ -395,16 +395,60 @@
 ogger;%0D%0A
+import org.ocelotds.context.OcelotContext;%0D%0A
 import o
@@ -589,24 +589,76 @@
 logger;%0D%0A%09%0D%0A
+%09@Inject%0D%0A%09private OcelotContext ocelotContext;%0D%0A%09%0D%0A
 %09public Loca
@@ -736,293 +736,41 @@
 %0D%0A%09%09
-Locale locale = (Locale) ThreadLocalContextHolder.get(Constants.LOCALE);%0D%0A%09%09if(null==locale) %7B%0D%0A%09%09%09logger.debug(%22Get locale from OcelotServices : default%22);%0D%0A%09%09%09locale =  new Locale(%22en%22, %22US%22);%0D%0A%09%09%7D%0D%0A%09%09logger.debug(%22Get locale from OcelotServices : %7B%7D%22, locale);%0D%0A%09%09return locale;%0D%0A%09%09
+return ocelotContext.getLocale();
 %0D%0A%09%7D

use ocelotContext for get Locale