Skip to content
Snippets Groups Projects
Verified Commit 9b8553b9 authored by BIGARET Sebastien's avatar BIGARET Sebastien
Browse files

Leave the default locale untouched when the application changes its locale

This allows logging to use a different locale (the default one) thanthe locale used by the application
parent ace954fb
No related branches found
No related tags found
No related merge requests found
Pipeline #84 failed
...@@ -612,9 +612,7 @@ public final class Configuration ...@@ -612,9 +612,7 @@ public final class Configuration
{ {
if (language == null) if (language == null)
language = "en"; language = "en";
Locale locale = new Locale(language); I18N.setLocale(new Locale(language));
Locale.setDefault(locale);
I18N.reinit();
} }
/** /**
......
...@@ -15,23 +15,28 @@ public class I18N ...@@ -15,23 +15,28 @@ public class I18N
private static ResourceBundle applicationSpecific; private static ResourceBundle applicationSpecific;
private static MessageFormat msg_fmt; private static final MessageFormat msg_fmt = new MessageFormat("");
static static
{ {
reinit(); setLocale(Locale.getDefault());
} }
public static void reinit() public static void setLocale(Locale locale)
{ {
praxis = ResourceBundle.getBundle("data/i18n/praxis", Locale.getDefault()); praxis = ResourceBundle.getBundle("data/i18n/praxis", locale);
String appSpecific = Configuration.get("i18n", ""); String appSpecific = Configuration.get("i18n", "");
if (!"".equals(appSpecific)) if (!"".equals(appSpecific))
applicationSpecific = ResourceBundle.getBundle(appSpecific, Locale.getDefault()); applicationSpecific = ResourceBundle.getBundle(appSpecific, locale);
else else
applicationSpecific = null; applicationSpecific = null;
msg_fmt = new MessageFormat(""); Log.log.log(java.util.logging.Level.INFO, "Setting locale: {0}", locale);
Log.log.log(java.util.logging.Level.INFO, "Setting locale: {0}", Locale.getDefault()); synchronized(msg_fmt) { msg_fmt.setLocale(locale); }
msg_fmt.setLocale(Locale.getDefault()); }
public static Locale getLocale()
{
synchronized(msg_fmt) { return msg_fmt.getLocale(); }
} }
/** /**
...@@ -65,7 +70,7 @@ public class I18N ...@@ -65,7 +70,7 @@ public class I18N
*/ */
static public String s(String key, Object args) static public String s(String key, Object args)
{ {
String fmt = ""; String fmt = key;
try try
{ {
if (applicationSpecific != null) if (applicationSpecific != null)
...@@ -81,8 +86,6 @@ public class I18N ...@@ -81,8 +86,6 @@ public class I18N
} }
else else
fmt = praxis.getString(key); fmt = praxis.getString(key);
msg_fmt.applyPattern(fmt);
return msg_fmt.format(args);
} }
catch (java.util.MissingResourceException e) catch (java.util.MissingResourceException e)
{ {
...@@ -92,9 +95,12 @@ public class I18N ...@@ -92,9 +95,12 @@ public class I18N
{ {
Log.log.log(Level.SEVERE, "I18N: could format " + fmt, e); Log.log.log(Level.SEVERE, "I18N: could format " + fmt, e);
} }
msg_fmt.applyPattern(key); synchronized (msg_fmt)
{
msg_fmt.applyPattern(fmt);
return msg_fmt.format(args); return msg_fmt.format(args);
} }
}
/** /**
* Returns the internationalized message corresponding to the supplied key.<br> * Returns the internationalized message corresponding to the supplied key.<br>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment