List of usage examples for com.google.gwt.i18n.client LocaleInfo getLocaleCookieName
public static final String getLocaleCookieName()
From source file:com.dingziran.effective.client.ShowcaseShell.java
License:Apache License
/** * Initialize the {@link ListBox} used for locale selection. *//*from ww w .ja va 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. *///ww w.j a va 2 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 = "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.tasktop.c2c.server.profile.web.ui.client.view.components.account.presenter.AccountActivity.java
License:Open Source License
@Override public void saveProfile() { ProfileEntryPoint.getInstance().getProfileService().updateProfile(profile, new AsyncCallbackSupport<Credentials>() { @Override//w w w .j av a2 s. c o m public void success(Credentials result) { ProfileEntryPoint.getInstance().getAppState().setCredentials(result); profile = result.getProfile(); updateView(); ProfileGinjector.get.instance().getNotifier() .displayMessage(Message.createSuccessMessage(profileMessages.profileUpdated())); if (!originalEmail.equals(profile.getEmail())) { ProfileGinjector.get.instance().getNotifier().displayMessage( Message.createSuccessMessage(profileMessages.verificationEmailSent())); originalEmail = profile.getEmail(); } if (result.getProfile().getLanguage() != null && !result.getProfile().getLanguage() .equals(LocaleInfo.getCurrentLocale().getLocaleName())) { // We'd prefer to have the GwtLocaleCookieFilter be the only place where this cookie is set, // but in this instance we find that when we refresh the page, the security context has not // yet been updated by the AuthenticationRefreshFilter, so GwtLocaleCookieFilter uses the // previous language value in the cookie. Since we cannot refresh twice, we instead set the // cookie here. Cookies.setCookie(LocaleInfo.getLocaleCookieName(), result.getProfile().getLanguage(), new Date(System.currentTimeMillis() + (1209600 * 1000))); // reload with the new language Window.Location.reload(); } } }); }
From source file:de.knightsoftnet.validationexample.client.ui.page.settings.SettingsPresenter.java
License:Apache License
/** * change the language of the ui./*from w ww .j av a2s . c o m*/ * * @param planguage language to switch to. */ public final void changeLanguage(final String planguage) { Cookies.setCookie(LocaleInfo.getLocaleCookieName(), planguage); Window.Location.reload(); }