Yes. Although you cannot force Java to execute assignments again, you can move assignments to a method instead:
public static String MSG1;
public static void setLocale(Locale locale) {
MSG1 = Translator.get(locale, "MSG1");
}
static {
setLocale( Locale.getDefault() );
}
After that, you can use the method setLocale()to switch the locale. When the class is loaded for the first time, the locale is set using the static initializer block at the end.
[EDIT] , , : (= ). : - Java 1 - .
-, . . Filter .
public class I18nHelper {
public static I18nHelper get( HttpServletRequest request ) {
return (HttpServletRequest) request.getAttribute( "I18nHelper" );
}
private Locale locale;
public I18nHelper(Locale locale) {
this.locale = locale;
}
public String msg1() {
return Translator.get(locale, "MSG1");
}
}
: !
public String fileNotFoundMsg( File file ) {
... format message with parameter "file" and return it...
}