read key from LocalizedResource.properties programmatically
I able to use LocalizedResource.properties with uibinder. let say i have widget that created pro开发者_运维问答grammatically in java file. how to read in key from LocalizedResource.properties depending on language "en,fr..etc" selected by users?
@Paŭlo Ebermann
This method doesn't work for GWT because GWT can't translate java classes like Locale
and
ResourceBUndle
to JavaScript.
I just try it.
Locale loc = new Locale(LocaleInfo.getCurrentLocale().getLocaleName());
String key = "AnotherWord";
ResourceBundle bundle = ResourceBundle.getBundle("msgs", loc);
GWT Compilation fail with
[ERROR] Errors in 'file:/K:/programming/eclipse-workspace/polyglotte/src/com/mw/uibinder/client/Polyglotte.java'
[ERROR] Line 64: No source code is available for type java.util.Locale; did you forget to inherit a required module?
[ERROR] Line 67: No source code is available for type java.util.ResourceBundle; did you forget to inherit a required module?
May be it will work if I try feed GWT Compiler with java.util.* source codes. But I think it isn't good idea. Why Googlers don't follow this way?
It's difficult to say something definitely.
If your LocalizedResource.properties is generated as described by "Internationalization - UiBinder" so I don't understand why you want to read in key from it
If .properties made for Message or Constant interface so you could read *fr_CA.properties by http://*.html?locale=fr_CA and so for any languge you want.
Helpful link is Internationalizing GWT: Creating the translation for each language supported
or try @UiTemplate to switch between tamplates prepared for different languages. To find out current locale you can use
LocaleInfo.getLocaleName()
.Helpful link is Apply different XML templates to the same widget
I don't know anything about GWT and UIBinder, but in "Standard Edition" Java, you would create a ResourceBundle
of your selected language (Locale), and then use its getString
method.
Locale loc = ...;
String key = ...;
ResourceBundle bundle =
ResourceBundle.getBundle("LocalizedResource", loc);
String value = bundle.getString(key);
Then you can use this string to label your widget.
Please try this and report the success in GWT.
精彩评论