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

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

Introduction

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

Prototype

public static final String[] getAvailableLocaleNames() 

Source Link

Document

Returns an array of available locale names.

Usage

From source file:cc.kune.core.client.i18n.I18nUITranslationService.java

License:GNU Affero Public License

/**
 * Instantiates a new i18n ui translation service.
 *
 * @param session//from   w  ww  .j a va 2  s  .c o m
 *          the session
 * @param i18nService
 *          the i18n service
 * @param eventBus
 *          the event bus
 * @param kuneConstants
 *          the kune constants
 */
@Inject
public I18nUITranslationService(final Session session, final I18nServiceAsync i18nService,
        final EventBus eventBus, final KuneConstants kuneConstants) {
    this.session = session;
    this.i18nService = i18nService;
    this.kuneConstants = kuneConstants;
    final String locale = WindowUtils.getParameter(SiteParameters.LOCALE);
    final LocaleInfo currentLocale = LocaleInfo.getCurrentLocale();
    Log.info("Workspace starting with language: " + currentLocale.getLocaleName() + ", isRTL: "
            + LocaleInfo.getCurrentLocale().isRTL() + ", translated langs: "
            + Arrays.toString(LocaleInfo.getAvailableLocaleNames()));
    isLangInProperties = isInConstantProperties(currentLocale.getLocaleName());
    earlyTexts = new HashSet<Pair<String, String>>();

    i18nService.getInitialLanguage(locale, new AsyncCallback<I18nLanguageDTO>() {

        @Override
        public void onFailure(final Throwable caught) {
            Log.error("Workspace adaptation to your language failed: " + caught.getMessage());
        }

        @Override
        public void onSuccess(final I18nLanguageDTO result) {
            currentLang = result;
            currentLanguageCode = currentLang.getCode();
            session.setCurrentLanguage(currentLang);
            isLangInProperties = isInConstantProperties(currentLang.getCode());
            i18nService.getLexicon(currentLang.getCode(), new AsyncCallback<HashMap<String, String>>() {
                @Override
                public void onFailure(final Throwable caught) {
                    Log.error(
                            "Workspace adaptation to server proposed language failed: " + caught.getMessage());
                }

                @Override
                public void onSuccess(final HashMap<String, String> result) {
                    lexicon = result;
                    session.setCurrentLanguage(currentLang);
                    Log.info("Workspace adaptation to server proposed language: " + currentLang.getEnglishName()
                            + ", isRTL: " + currentLang.getDirection() + " use properties: "
                            + shouldIuseProperties());

                    changeToLanguageIfNecessary(getCurrentGWTlanguage(), currentLang.getCode(),
                            currentLang.getEnglishName(), false, new I18nLanguageChangeNeeded() {

                                @Override
                                public void onChangeNeeded() {
                                }

                                @Override
                                public void onChangeNotNeeded() {
                                    isCurrentLangRTL = currentLang.getDirection().equals(RTL);
                                    eventBus.fireEvent(new I18nReadyEvent());
                                    I18nStyles.setRTL(isCurrentLangRTL);
                                }
                            });
                }
            });

            session.onUserSignIn(true, new UserSignInHandler() {
                @Override
                public void onUserSignIn(final UserSignInEvent event) {
                    Scheduler.get().scheduleIncremental(new RepeatingCommand() {
                        @Override
                        public boolean execute() {
                            if (!earlyTexts.isEmpty()) {
                                final Pair<String, String> pair = earlyTexts.iterator().next();
                                save(pair.getLeft(), pair.getRight());
                                earlyTexts.remove(pair);
                            }
                            return !earlyTexts.isEmpty();
                        }
                    });
                }
            });
        }
    });
}

From source file:cc.kune.core.client.i18n.I18nUITranslationService.java

License:GNU Affero Public License

/**
 * Checks if is in constant properties.//w w  w .j a v a 2 s.co  m
 *
 * @param currentLang
 *          the current lang
 * @return true, if is in constant properties
 */
private boolean isInConstantProperties(final String currentLang) {
    for (final String lang : LocaleInfo.getAvailableLocaleNames()) {
        if (lang.equals(currentLang)) {
            Log.info("Workspace adaptation to language: " + currentLang + " is in KuneConstants*properties");
            return true;
        }
    }
    Log.info("Workspace adaptation to language: " + currentLang + " is not in KuneConstants*properties");
    return false;
}

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

License:Apache License

/**
 * Initialize the {@link ListBox} used for locale selection.
 *//*from  www .  ja  v a2  s.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 ww.  ja  v a  2  s  .c om
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

/**
 * Initializes and assembles all UI elements shown in the top panel.
 *///  w w  w.j  a v a 2 s  .c o  m
public TopPanel() {
    /*
     * The layout of the top panel is as follows:
     *
     *  +-- topPanel ------------------------------------+
     *  |+-- logo --++-----tools-----++--links/account--+|
     *  ||          ||               ||                 ||
     *  |+----------++---------------++-----------------+|
     *  +------------------------------------------------+
     */
    HorizontalPanel topPanel = new HorizontalPanel();
    topPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);

    // Create the Tools
    TopToolbar tools = new TopToolbar();
    ode.setTopToolbar(tools);

    // Create the Links
    HorizontalPanel links = new HorizontalPanel();
    links.setStyleName("ode-TopPanelLinks");
    links.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);

    if (Ode.getInstance().isReadOnly()) {
        Label readOnly = new Label(MESSAGES.readOnlyMode());
        readOnly.setStyleName("ode-TopPanelWarningLabel");
        links.add(readOnly);
    }

    // My Projects Link
    TextButton myProjects = new TextButton(MESSAGES.myProjectsTabName());
    myProjects.setStyleName("ode-TopPanelButton");

    myProjects.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            ode.switchToProjectsView();
        }
    });

    myProjects.setStyleName("ode-TopPanelButton");
    links.add(myProjects);

    // Code on gallerydev branch
    // Gallery Link
    gallery = new TextButton(MESSAGES.tabNameGallery());
    gallery.setStyleName("ode-TopPanelButton");
    gallery.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            ode.switchToGalleryView();
        }
    });
    links.add(gallery);

    Config config = ode.getSystemConfig();
    String guideUrl = config.getGuideUrl();
    if (!Strings.isNullOrEmpty(guideUrl)) {
        TextButton guideLink = new TextButton(MESSAGES.guideTabName());
        guideLink.addClickHandler(new WindowOpenClickHandler(guideUrl));
        guideLink.setStyleName("ode-TopPanelButton");
        links.add(guideLink);
    }

    // Feedback Link
    String feedbackUrl = config.getFeedbackUrl();
    if (!Strings.isNullOrEmpty(feedbackUrl)) {
        TextButton feedbackLink = new TextButton(MESSAGES.feedbackTabName());
        feedbackLink.addClickHandler(new WindowOpenClickHandler(feedbackUrl));
        feedbackLink.setStyleName("ode-TopPanelButton");
        links.add(feedbackLink);
    }

    /*
    // Code on master branch
      // Gallery Link
      if (Ode.getInstance().getUser().getIsAdmin()) {
        TextButton gallery = new TextButton(MESSAGES.galleryTabName());
        gallery.addClickHandler(new ClickHandler() {
          @Override
          public void onClick(ClickEvent clickEvent) {
            Window.open("http://gallery.appinventor.mit.edu", "_blank", "scrollbars=1");
          }
        });
            
        gallery.setStyleName("ode-TopPanelButton");
        links.add(gallery);
      }
      */

    moderation = new TextButton(MESSAGES.tabNameModeration());
    moderation.setStyleName("ode-TopPanelButton");
    moderation.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            ode.switchToModerationPageView();
        }
    });
    moderation.setVisible(false);
    links.add(moderation);

    // Create the Account Information
    rightPanel = new VerticalPanel();
    rightPanel.setHeight("100%");
    rightPanel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);

    HorizontalPanel account = new HorizontalPanel();
    account.setStyleName("ode-TopPanelAccount");

    // Account Drop Down Button
    List<DropDownItem> userItems = Lists.newArrayList();

    // Sign Out
    userItems.add(new DropDownItem(WIDGET_NAME_SIGN_OUT, MESSAGES.signOutLink(), new SignOutAction()));

    accountButton = new DropDownButton(WIDGET_NAME_USER, " ", userItems, true);
    accountButton.setItemEnabled(WIDGET_NAME_MESSAGES, false);
    accountButton.setStyleName("ode-TopPanelButton");

    // Language
    List<DropDownItem> languageItems = Lists.newArrayList();
    String[] localeNames = LocaleInfo.getAvailableLocaleNames();
    String nativeName;
    for (String localeName : localeNames) {
        if (!localeName.equals("default")) {
            SelectLanguage lang = new SelectLanguage();
            lang.setLocale(localeName);
            nativeName = getDisplayName(localeName);
            languageItems.add(new DropDownItem(WIDGET_NAME_LANGUAGE, nativeName, lang));
        }
    }
    String currentLang = LocaleInfo.getCurrentLocale().getLocaleName();
    String nativeDisplayName = getDisplayName(currentLang);
    languageDropDown = new DropDownButton(WIDGET_NAME_LANGUAGE, nativeDisplayName, languageItems, true);
    languageDropDown.setStyleName("ode-TopPanelButton");

    account.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);
    account.add(links);
    account.add(languageDropDown);
    account.add(accountButton);

    rightPanel.add(account);

    // Add the Logo, Tools, Links to the TopPanel
    addLogo(topPanel);
    topPanel.add(tools);
    topPanel.add(rightPanel);
    topPanel.setCellVerticalAlignment(rightPanel, HorizontalPanel.ALIGN_MIDDLE);
    rightPanel.setCellHorizontalAlignment(account, HorizontalPanel.ALIGN_RIGHT);
    topPanel.setCellHorizontalAlignment(rightPanel, HorizontalPanel.ALIGN_RIGHT);

    initWidget(topPanel);

    setStyleName("ode-TopPanel");
    setWidth("100%");
}

From source file:com.tasktop.c2c.server.profile.web.ui.client.view.components.account.profile.AccountProfileEditView.java

License:Open Source License

public AccountProfileEditView() {
    initWidget(ourUiBinder.createAndBindUi(this));
    String[] localeNames = LocaleInfo.getAvailableLocaleNames();
    // sort the locale names and filter out the "default" value
    List<String> filteredLocaleNames = new ArrayList<String>();
    for (String name : localeNames) {
        if (!"default".equals(name)) {
            filteredLocaleNames.add(name);
        }//  ww  w .ja  v a 2 s  . co m
    }
    if (!filteredLocaleNames.isEmpty()) {
        Collections.sort(filteredLocaleNames);
        languageField.setValue(filteredLocaleNames.get(0));
        languageField.setAcceptableValues(filteredLocaleNames);
    }
    if (filteredLocaleNames.size() < 2) {
        UIObject.setVisible(languageFieldSet, false);
    }
    imageFromGravatarLabel.setHTML(profileMessages.imageFromGravatar());
    driver.initialize(this);
}

From source file:com.tasktop.c2c.server.profile.web.ui.client.view.components.account.profile.AccountProfileReadOnlyView.java

License:Open Source License

public AccountProfileReadOnlyView() {
    initWidget(ourUiBinder.createAndBindUi(this));
    // unless additional languages are enabled in the GWT module,
    // available names will be "en" and "default"
    if (LocaleInfo.getAvailableLocaleNames().length < 3) {
        UIObject.setVisible(languageFieldSet, false);
    }//from w  w  w.  java  2s  .  c o  m
    driver.initialize(this);
}

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);/* w  ww .  ja  v a  2s .co 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.
 *///www . j  a  v  a 2s. com
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//from   w  w  w .  j  av a  2  s . co 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);
        }
    }
}