Example usage for com.google.gwt.i18n.client LocaleInfo getLocaleNativeDisplayName

List of usage examples for com.google.gwt.i18n.client LocaleInfo getLocaleNativeDisplayName

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client LocaleInfo getLocaleNativeDisplayName.

Prototype

public static String getLocaleNativeDisplayName(String localeName) 

Source Link

Document

Returns the display name of the requested locale in its native locale, if possible.

Usage

From source file:cc.kune.core.client.sitebar.SiteLanguageSelector.java

License:GNU Affero Public License

@Inject
public SiteLanguageSelector(final Session session, final EventBus eventBus) {
    super();/*from  ww  w  .  j  a  v  a 2  s .c o m*/
    final PaperButton btn = PaperButton.wrap(MENU_ID);
    setWidget(btn);
    setParent(SitebarActions.RIGHT_TOOLBAR);
    Tooltip.to(btn, I18n.t("Choose your language"));

    /* Same as in KuneProd.gwt.xml */
    final String[] availableLangs = { "ar", "ca", "de", "el", "en", "eo", "es", "eu", "fr", "gl", "he", "hu",
            "it", "pl", "pt", "pt_BR", "qu", "ro", "ru", "sl", "tr", "zh_HK", "zh_TW" };
    session.onAppStart(true, new AppStartHandler() {
        @Override
        public void onAppStart(final AppStartEvent event) {
            final String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
            btn.setText(LocaleInfo.getLocaleNativeDisplayName(currentLocale));
            btn.setIcon("translate");
            // for (final String locale : LocaleInfo.getAvailableLocaleNames()) {
            new MenuSeparatorDescriptor(SiteLanguageSelector.this);
            new MenuTitleItemDescriptor(SiteLanguageSelector.this, I18n.t("Choose another language"));

            for (final String locale : availableLangs) {
                final MenuItemDescriptor menuItem = new MenuItemDescriptor(SiteLanguageSelector.this,
                        new LocaleAction(locale));
                final String nativeName = LocaleInfo.getLocaleNativeDisplayName(locale);
                String text = TextUtils.notEmpty(nativeName) ? nativeName : locale;
                text = text.equals("qu") ? "Quechua" : text;
                menuItem.withText(text);
                if (locale.equals(currentLocale)) {
                    menuItem.setStyles(Styles.ACTIVE);
                }
            }
        }
    });
}

From source file:com.dingziran.effective.client.ShowcaseShell.java

License:Apache License

/**
 * Initialize the {@link ListBox} used for locale selection.
 *///  w  w w . j  ava  2s  . co  m
private void initializeLocaleBox() {
    final String cookieName = LocaleInfo.getLocaleCookieName();
    final String queryParam = LocaleInfo.getLocaleQueryParam();
    if (cookieName == null && queryParam == null) {
        // if there is no way for us to affect the locale, don't show the selector
        localeSelectionCell.getStyle().setDisplay(Display.NONE);
        return;
    }
    String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
    if (currentLocale.equals("default")) {
        currentLocale = "en";
    }
    String[] localeNames = LocaleInfo.getAvailableLocaleNames();
    for (String localeName : localeNames) {
        if (!localeName.equals("default")) {
            String nativeName = LocaleInfo.getLocaleNativeDisplayName(localeName);
            localeBox.addItem(nativeName, localeName);
            if (localeName.equals(currentLocale)) {
                localeBox.setSelectedIndex(localeBox.getItemCount() - 1);
            }
        }
    }
    localeBox.addChangeHandler(new ChangeHandler() {
        @SuppressWarnings("deprecation")
        public void onChange(ChangeEvent event) {
            String localeName = localeBox.getValue(localeBox.getSelectedIndex());
            if (cookieName != null) {
                // expire in one year
                Date expires = new Date();
                expires.setYear(expires.getYear() + 1);
                Cookies.setCookie(cookieName, localeName, expires);
            }
            if (queryParam != null) {
                UrlBuilder builder = Location.createUrlBuilder().setParameter(queryParam, localeName);
                Window.Location.replace(builder.buildString());
            } else {
                // If we are using only cookies, just reload
                Window.Location.reload();
            }
        }
    });
}

From source file:com.goodow.web.ui.client.search.DefaultHeader.java

License:Apache License

/**
 * Initialize the {@link ListBox} used for locale selection.
 *///from  w  w w . j  a v  a2 s  .c o m
private void initializeLocaleBox() {
    final String cookieName = LocaleInfo.getLocaleCookieName();
    final String queryParam = LocaleInfo.getLocaleQueryParam();
    if (cookieName == null && queryParam == null) {
        // if there is no way for us to affect the locale, don't show the selector
        localeSelectionCell.getStyle().setDisplay(Display.NONE);
        return;
    }
    String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
    if (currentLocale.equals("default")) {
        currentLocale = "zh";
    }
    String[] localeNames = LocaleInfo.getAvailableLocaleNames();
    for (String localeName : localeNames) {
        if (!localeName.equals("default")) {
            String nativeName = LocaleInfo.getLocaleNativeDisplayName(localeName);
            localeBox.addItem(nativeName, localeName);
            if (localeName.equals(currentLocale)) {
                localeBox.setSelectedIndex(localeBox.getItemCount() - 1);
            }
        }
    }
    localeBox.addChangeHandler(new ChangeHandler() {
        @Override
        @SuppressWarnings("deprecation")
        public void onChange(final ChangeEvent event) {
            String localeName = localeBox.getValue(localeBox.getSelectedIndex());
            if (cookieName != null) {
                // expire in one year
                Date expires = new Date();
                expires.setYear(expires.getYear() + 1);
                Cookies.setCookie(cookieName, localeName, expires);
            }
            if (queryParam != null) {
                UrlBuilder builder = Location.createUrlBuilder().setParameter(queryParam, localeName);
                Window.Location.replace(builder.buildString());
            } else {
                // If we are using only cookies, just reload
                Window.Location.reload();
            }
        }
    });
}

From source file:com.google.appinventor.client.TopPanel.java

License:Open Source License

private String getDisplayName(String localeName) {
    String nativeName = LocaleInfo.getLocaleNativeDisplayName(localeName);
    if (localeName == "zh_CN") {
        nativeName = MESSAGES.SwitchToSimplifiedChinese();
    } else if (localeName == "zh_TW") {
        nativeName = MESSAGES.SwitchToTraditionalChinese();
    } else if (localeName == "es_ES") {
        nativeName = MESSAGES.SwitchToSpanish();
    } else if (localeName == "fr_FR") {
        nativeName = MESSAGES.SwitchToFrench();
    } else if (localeName == "it_IT") {
        nativeName = MESSAGES.SwitchToItalian();
    } else if (localeName == "ru") {
        nativeName = MESSAGES.SwitchToRussian();
    } else if (localeName == "ko_KR") {
        nativeName = MESSAGES.SwitchToKorean();
    } else if (localeName == "sv") {
        nativeName = MESSAGES.SwitchToSwedish();
    } else if (localeName == "pt_BR") {
        nativeName = MESSAGES.switchToPortugueseBR();
    }//from  ww w  . j ava 2  s.  c  o m
    return nativeName;
}

From source file:mx.org.pescadormvp.core.client.session.SessionImpl.java

private PescadorMVPLocale setupLocale(String localeName) {
    return new PescadorMVPLocale(localeName, LocaleInfo.getLocaleNativeDisplayName(localeName));
}

From source file:mx.org.pescadormvp.core.client.session.SessionImpl.java

@Override
public List<PescadorMVPLocale> availableLocales() {
    List<PescadorMVPLocale> locales = new ArrayList<PescadorMVPLocale>();

    for (String localeName : LocaleInfo.getAvailableLocaleNames()) {

        // for some reason, "default" appears as a separate locale
        if (localeName.equalsIgnoreCase(DEFAULT_LOCALE_STRING))
            continue;

        PescadorMVPLocale locale = new PescadorMVPLocale(localeName,
                LocaleInfo.getLocaleNativeDisplayName(localeName));

        locales.add(locale);//from w w w.ja v  a2  s.  c  o  m
    }

    Collections.sort(locales, PescadorMVPLocale.getStandardComparator());
    return locales;
}

From source file:net.s17fabu.vip.gwt.showcase.client.Showcase.java

License:Apache License

/**
 * Create the options that appear next to the title.
 *//*from ww w  .jav a  2 s .  c  o  m*/
private void setupOptionsPanel(ShowcaseConstants constants) {
    VerticalPanel vPanel = new VerticalPanel();
    vPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    if (LocaleInfo.getCurrentLocale().isRTL()) {
        vPanel.getElement().setAttribute("align", "left");
    } else {
        vPanel.getElement().setAttribute("align", "right");
    }
    app.setOptionsWidget(vPanel);

    // Add the option to change the locale
    final ListBox localeBox = new ListBox();
    String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
    if (currentLocale.equals("default")) {
        currentLocale = "en_US";
    }
    String[] localeNames = LocaleInfo.getAvailableLocaleNames();
    for (String localeName : localeNames) {
        if (!localeName.equals("default")) {
            String nativeName = LocaleInfo.getLocaleNativeDisplayName(localeName);
            localeBox.addItem(nativeName, localeName);
            if (localeName.equals(currentLocale)) {
                localeBox.setSelectedIndex(localeBox.getItemCount() - 1);
            }
        }
    }
    localeBox.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent event) {
            String localeName = localeBox.getValue(localeBox.getSelectedIndex());
            Window.open(getHostPageLocation() + "?locale=" + localeName, "_self", "");
        }
    });
    HorizontalPanel localeWrapper = new HorizontalPanel();
    localeWrapper.add(images.locale().createImage());
    localeWrapper.add(new Label(constants.chooseLocale()));
    localeWrapper.add(localeBox);
    vPanel.add(localeWrapper);

    // Add the option to change the style
    final HorizontalPanel styleWrapper = new HorizontalPanel();
    vPanel.add(styleWrapper);
    for (int i = 0; i < ShowcaseConstants.STYLE_THEMES.length; i++) {
        final ThemeButton button = new ThemeButton(ShowcaseConstants.STYLE_THEMES[i]);
        styleWrapper.add(button);
        button.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                // Update the current theme
                CUR_THEME = button.getTheme();

                // Reload the current tab, loading the new theme if necessary
                TabBar bar = ((TabBar) app.getContentTitle());
                bar.selectTab(bar.getSelectedTab());

                // Load the new style sheets
                updateStyleSheets();
            }
        });
    }
}

From source file:nl.mpi.tg.eg.experiment.client.presenter.LocalePresenter.java

License:Open Source License

private void setUpLocaleOptions() {
    for (final String localeName : LocaleInfo.getAvailableLocaleNames()) {
        final String displayName = LocaleInfo.getLocaleNativeDisplayName(localeName);
        if (displayName != null && !displayName.isEmpty()) {
            ((MenuView) simpleView).addMenuItem(new PresenterEventListner() {

                @Override// w ww  . ja  v a2s  .c  o  m
                public void eventFired(ButtonBase button, SingleShotEventListner singleShotEventListner) {
                    final String queryString = Window.Location.getQueryString();
                    final String localeGet = "locale=";
                    final String updatedPathValue;
                    if (queryString.contains(localeGet)) {
                        // if a locale vale already exists then update it
                        updatedPathValue = queryString.replaceFirst(localeGet + "[^&]*",
                                localeGet + localeName);
                    } else {
                        // if there are no values already there then use ? otherwise append with &
                        String separator = (queryString.isEmpty()) ? "?" : "&";
                        updatedPathValue = queryString + separator + localeGet + localeName;
                    }
                    Window.Location.replace(Window.Location.getPath() + updatedPathValue);
                }

                @Override
                public int getHotKey() {
                    return -1;
                }

                @Override
                public String getStyleName() {
                    return null;
                }

                @Override
                public String getLabel() {
                    return displayName;
                }
            }, true);
        }
    }
}

From source file:nl.ru.languageininteraction.language.client.presenter.LocalePresenter.java

License:Open Source License

private void setUpLocaleOptions() {
    for (final String localeName : LocaleInfo.getAvailableLocaleNames()) {
        final String displayName = LocaleInfo.getLocaleNativeDisplayName(localeName);
        if (displayName != null && !displayName.isEmpty()) {
            ((MenuView) simpleView).addMenuItem(new PresenterEventListner() {

                @Override/*from  w w w. j ava2 s.c  om*/
                public void eventFired(Button button) {
                    final String queryString = Window.Location.getQueryString();
                    final String localeGet = "locale=";
                    final String updatedPathValue;
                    if (queryString.contains(localeGet)) {
                        // if a locale vale already exists then update it
                        updatedPathValue = queryString.replaceFirst(localeGet + "[^&]*",
                                localeGet + localeName);
                    } else {
                        // if there are no values already there then use ? otherwise append with &
                        String separator = (queryString.isEmpty()) ? "?" : "&";
                        updatedPathValue = queryString + separator + localeGet + localeName;
                    }
                    Window.Location.replace(Window.Location.getPath() + updatedPathValue);
                }

                @Override
                public String getLabel() {
                    return displayName;
                }
            }, true);
        }
    }
}

From source file:nl.strohalm.cyclos.mobile.client.configuration.ConfigurationPage.java

License:Open Source License

@Override
public Widget initialize() {

    SquarePanel container = new SquarePanel();

    LabelField url = new LabelField(messages.cyclosUrl());
    url.addStyleName("configuration-label-field");

    cyclosUrl = new TextField(messages.typeCyclosUrlHere());
    cyclosUrl.setValue(Configuration.get().getServerAppUrl());

    LabelField example = new LabelField(messages.forExample());

    LabelField language = new LabelField(messages.language());
    language.addStyleName("configuration-label-field");

    languages = new SimpleSelectionField<String>(Configuration.get().getLocales()) {
        @Override/*from w  w w .  j a  v  a2 s.c  o  m*/
        protected String getDisplayName(String item) {
            return StringHelper.capitalize(LocaleInfo.getLocaleNativeDisplayName(item));
        }

        @Override
        protected String getValue(String item) {
            return item;
        }
    };

    FlowPanel versionContainer = new FlowPanel();
    versionContainer.setStyleName("version-container");

    String appVersion = Configuration.get().getAppVersion();
    LabelField version = new LabelField(messages.version() + " " + appVersion);
    version.addStyleName("version-label-field");

    versionContainer.add(version);

    // Select the user language if set
    String userLanguage = Configuration.get().getUserLanguage();
    if (StringHelper.isNotEmpty(userLanguage)) {
        languages.selectItem(userLanguage);
    } else {
        languages.selectItem(Configuration.get().getDefaultLanguage());
    }

    if (Configuration.get().isURLConfigEnabled()) {
        language.addStyleName("top-spacing");
        container.add(url);
        container.add(cyclosUrl);
        container.add(example);
    }
    container.add(language);
    container.add(languages);

    if (StringHelper.isNotEmpty(appVersion)) {
        container.add(versionContainer);
    }

    return container;
}