GWT DefaultLocalizedNames使用当前区域设置

时间:2014-05-13 09:06:49

标签: java gwt internationalization

我想打印本地化为当前活动区域设置的国家/地区名称。因此我提出了那个代码。但它总是打印出英文名字。有没有办法在这里设置一个区域设置。我可以使用例如LocalizedNamesImpl_de显示德语名称,但我必须在语言之间切换,然后

DefaultLocalizedNames loc2 = new DefaultLocalizedNames();         
// LocalizedNames loc2 = new LocalizedNamesImpl_de();         

for (int i=0; i<loc2.getSortedRegionCodes().length; i++) {

             String code = loc2.getSortedRegionCodes()[i];
             System.out.println(loc2.getRegionName(code));                 
}

1 个答案:

答案 0 :(得分:1)

我已经在相同的上下文中分享了一篇文章。它可能有助于您解决此问题。

请看下面的帖子:


示例代码:

// a map contains mapping for all LocalizedNamesImpl based on language
Map<String, LocalizedNamesImpl> formats = new HashMap<String, LocalizedNamesImpl>();

LocalizedNamesImpl formatDE = new LocalizedNamesImpl_de();
LocalizedNamesImpl formatEN = new LocalizedNamesImpl_en();
LocalizedNamesImpl formatFR = new LocalizedNamesImpl_fr();

formats.put("de", formatDE);
formats.put("de-DE", formatDE);
formats.put("en", formatEN);
formats.put("fr", formatFR);

// browser (client) language
String language = getLanguage();
System.out.println(language);

LocalizedNamesImpl format = formats.get(language);

if (format != null) {
    for (int i = 0; i < format.getSortedRegionCodes().length; i++) {
        String code = format.getSortedRegionCodes()[i];
        System.out.println(format.getRegionName(code));
    }
}

public static final native String getLanguage() /*-{
    return navigator.language;
}-*/;