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
{
if (language == null)
language = "en";
Locale locale = new Locale(language);
Locale.setDefault(locale);
I18N.reinit();
I18N.setLocale(new Locale(language));
}
/**
......
......@@ -15,23 +15,28 @@ public class I18N
private static ResourceBundle applicationSpecific;
private static MessageFormat msg_fmt;
private static final MessageFormat msg_fmt = new MessageFormat("");
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", "");
if (!"".equals(appSpecific))
applicationSpecific = ResourceBundle.getBundle(appSpecific, Locale.getDefault());
applicationSpecific = ResourceBundle.getBundle(appSpecific, locale);
else
applicationSpecific = null;
msg_fmt = new MessageFormat("");
Log.log.log(java.util.logging.Level.INFO, "Setting locale: {0}", Locale.getDefault());
msg_fmt.setLocale(Locale.getDefault());
Log.log.log(java.util.logging.Level.INFO, "Setting locale: {0}", locale);
synchronized(msg_fmt) { msg_fmt.setLocale(locale); }
}
public static Locale getLocale()
{
synchronized(msg_fmt) { return msg_fmt.getLocale(); }
}
/**
......@@ -65,7 +70,7 @@ public class I18N
*/
static public String s(String key, Object args)
{
String fmt = "";
String fmt = key;
try
{
if (applicationSpecific != null)
......@@ -81,8 +86,6 @@ public class I18N
}
else
fmt = praxis.getString(key);
msg_fmt.applyPattern(fmt);
return msg_fmt.format(args);
}
catch (java.util.MissingResourceException e)
{
......@@ -92,8 +95,11 @@ public class I18N
{
Log.log.log(Level.SEVERE, "I18N: could format " + fmt, e);
}
msg_fmt.applyPattern(key);
return msg_fmt.format(args);
synchronized (msg_fmt)
{
msg_fmt.applyPattern(fmt);
return msg_fmt.format(args);
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment