Example usage for java.util Locale equals

List of usage examples for java.util Locale equals

Introduction

In this page you can find the example usage for java.util Locale equals.

Prototype

@Override
public boolean equals(Object obj) 

Source Link

Document

Returns true if this Locale is equal to another object.

Usage

From source file:SimpleInputMethod.java

public boolean setLocale(Locale locale) {
    return (locale.equals(this.locale));
}

From source file:info.magnolia.cms.i18n.DefaultI18nContentSupport.java

/**
 * Adds the language prefix to the uri./*  w ww. ja  v  a 2  s  .  com*/
 */
@Override
protected String toI18NURI(String uri, Locale locale) {
    // don't extend the uri for the default fallback language
    if (locale.equals(getDefaultLocale())) {
        return uri;
    }

    // nothing to do for relative links
    if (uri.startsWith("/")) {
        return "/" + locale.toString() + uri;
    }
    return uri;
}

From source file:org.echocat.locela.api.java.messages.MessageSupport.java

@Override
public boolean equals(Object o) {
    final boolean result;
    if (this == o) {
        result = true;/*from  w ww  .  j av a  2s  .  c  om*/
    } else if (o == null || !(o instanceof Message)) {
        result = false;
    } else {
        final Message that = (Message) o;
        if (getId().equals(that.getId())) {
            final Locale locale = getLocale();
            if (locale != null ? locale.equals(that.getLocale()) : that.getLocale() == null) {
                result = get().equals(that.get());
            } else {
                result = false;
            }
        } else {
            result = false;
        }
    }
    return result;
}

From source file:caillou.company.clonemanager.gui.customComponent.settings.SettingsController.java

@Override
public void initialize(URL location, ResourceBundle resources) {
    languageComboBoxId.setCellFactory(new Callback<ListView<Language>, ListCell<Language>>() {
        @Override//from ww  w  . j a  v  a  2s .  c  om
        public ListCell<Language> call(ListView<Language> language) {
            return new LanguageListCell();
        }
    });

    languageComboBoxId.setButtonCell(new LanguageListCell());

    Language frenchLanguage = new Language(Locale.FRENCH);
    Language englishLanguage = new Language(Locale.ENGLISH);
    ObservableList<Language> languages = FXCollections.observableArrayList();
    languages.add(englishLanguage);
    languages.add(frenchLanguage);
    languageComboBoxId.setItems(languages);

    Locale currentLocale = SpringFxmlLoader.getLocale();
    if (currentLocale.equals(Locale.FRENCH)) {
        languageComboBoxId.setValue(frenchLanguage);
    } else {
        languageComboBoxId.setValue(englishLanguage);
    }

    languageComboBoxId.valueProperty().addListener(new ChangeListener<Language>() {

        @Override
        public void changed(ObservableValue<? extends Language> observable, Language oldValue,
                Language newValue) {
            SpringFxmlLoader.changeLocale(newValue.getLocale());
        }
    });
}

From source file:de.iew.web.view.js.RequireJSMessageBundleView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> stringObjectMap, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    response.setContentType("text/javascript; charset=utf-8");

    PrintWriter writer = response.getWriter();

    // Ja, Javascript Hlle :-)
    writer.write("define({");
    if (isRootBundle(stringObjectMap)) {
        writer.write("'root':{");
    }/*from w  w  w . j a  v a 2s  .  c  o m*/

    Map<String, String> bundle = getBundle(stringObjectMap);
    int itemsLeft = bundle.size();
    for (Map.Entry<String, String> item : bundle.entrySet()) {
        writer.write("'");
        writer.write(item.getKey());
        writer.write("':'");
        writer.write(item.getValue());
        writer.write("'");
        itemsLeft--;

        if (itemsLeft > 0) {
            writer.write(",");
        }
    }

    if (isRootBundle(stringObjectMap)) {
        writer.write("}");

        List<Locale> availableLocales = getAvailableLocales(stringObjectMap);
        for (Locale locale : availableLocales) {
            if (!locale.equals(this.defaultLocale)) {
                writer.write(",");
                writer.write("'");
                writer.write(locale.getLanguage().toLowerCase() + "-" + locale.getCountry().toLowerCase());
                writer.write("':");
                writer.write("true");
            }
        }
    }
    writer.write("});");
}

From source file:org.alfresco.web.app.Application.java

/**
 * Return the language Locale for the current user Session.
 * //from   w w  w  . j  av a  2 s .co  m
 * @param session
 *           HttpSession for the current user
 * @param useInterfaceLanguage
 *           If the session language hasn't been established yet, should we base it on user preferences?
 * @return Current language Locale set or the VM default if none set - never null
 */
public static Locale getLanguage(HttpSession session, boolean useInterfaceLanguage) {
    Boolean useSessionLocale = (Boolean) session.getAttribute(USE_SESSION_LOCALE);
    if (useSessionLocale == null) {
        useSessionLocale = useInterfaceLanguage;
        session.setAttribute(USE_SESSION_LOCALE, useSessionLocale);
    }
    Locale locale = (Locale) session.getAttribute(LOCALE);
    if (locale == null || (!locale.equals(I18NUtil.getLocale()) && !useInterfaceLanguage)) {
        if (useSessionLocale && useInterfaceLanguage) {
            // first check saved user preferences
            String strLocale = null;
            if (getCurrentUser(session) != null) {
                strLocale = (String) PreferencesService.getPreferences(session)
                        .getValue(UserPreferencesBean.PREF_INTERFACELANGUAGE);
                if (strLocale != null) {
                    locale = I18NUtil.parseLocale(strLocale);
                } else {
                    // failing that, use the server default locale
                    locale = Locale.getDefault();
                }
            } else {
                // else get from web-client config - the first item in the configured list of languages
                locale = getLanguage(WebApplicationContextUtils
                        .getRequiredWebApplicationContext(session.getServletContext()));

            }

            // This is an interface session - the same locale will be used for the rest of the session
            session.setAttribute(LOCALE, locale);
        } else {
            // Get the request default, already decoded from the request headers
            locale = I18NUtil.getLocale();
        }
    }
    return locale;
}

From source file:org.alfresco.web.app.Application.java

/**
 * Return the language Locale for the current user context
 * /*from  www . ja  v  a 2  s.c om*/
 * @param fc        FacesContext for the current user
 * 
 * @return Current language Locale set or the VM default if none set - never null
 */
public static Locale getLanguage(FacesContext fc) {
    boolean useInterfaceLanguage = Application.getClientConfig(fc).isLanguageSelect();
    Map sessionMap = fc.getExternalContext().getSessionMap();
    Boolean useSessionLocale = (Boolean) sessionMap.get(USE_SESSION_LOCALE);
    if (useSessionLocale == null) {
        useSessionLocale = Boolean.TRUE;
        sessionMap.put(USE_SESSION_LOCALE, useSessionLocale);
    }
    Locale locale = (Locale) sessionMap.get(LOCALE);
    if (locale == null || (!locale.equals(I18NUtil.getLocale()) && !useInterfaceLanguage)) {
        if (useSessionLocale && useInterfaceLanguage) {
            // first check saved user preferences
            String strLocale = null;
            if (getCurrentUser(fc) != null) {
                strLocale = (String) PreferencesService.getPreferences(fc)
                        .getValue(UserPreferencesBean.PREF_INTERFACELANGUAGE);
                if (strLocale != null) {
                    locale = I18NUtil.parseLocale(strLocale);
                } else {
                    // failing that, use the server default locale
                    locale = Locale.getDefault();
                }
            } else {
                // else get from web-client config - the first item in the configured list of languages
                Config config = Application.getConfigService(fc).getConfig("Languages");
                LanguagesConfigElement langConfig = (LanguagesConfigElement) config
                        .getConfigElement(LanguagesConfigElement.CONFIG_ELEMENT_ID);
                List<String> languages = langConfig.getLanguages();
                if (languages != null && languages.size() != 0) {
                    locale = I18NUtil.parseLocale(languages.get(0));
                } else {
                    // failing that, use the server default locale
                    locale = Locale.getDefault();
                }
            }
            // save in user session
            sessionMap.put(LOCALE, locale);
        } else {
            // Get the request default, already decoded from the request headers
            locale = I18NUtil.getLocale();
        }
    }
    return locale;
}

From source file:org.nuxeo.ecm.webapp.locale.LocaleStartup.java

protected void setupLocale(Locale locale) {
    FacesContext ctx = FacesContext.getCurrentInstance();
    if (locale == null && ctx != null) {
        log.debug("Locale not set, falling back to request locale");
        locale = ctx.getExternalContext().getRequestLocale();
    }//from w  w  w  . j  av a  2 s .c  om
    if (locale == null && ctx != null) {
        log.debug("Locale not set, falling back to default JSF locale");
        locale = ctx.getApplication().getDefaultLocale();
    }
    if (locale == null) {
        log.debug("Locale not set, falling back to default locale");
        locale = Locale.getDefault();
    }
    LocaleSelector localeSelector = LocaleSelector.instance();
    // check if locale is accepted for setup
    boolean set = false;
    if (ctx != null) {
        Locale jsfDefault = ctx.getApplication().getDefaultLocale();
        if (jsfDefault != null && jsfDefault.getLanguage().equals(locale)) {
            set = true;
        } else {
            Iterator<Locale> it = ctx.getApplication().getSupportedLocales();
            while (it.hasNext()) {
                Locale current = it.next();
                if (current.equals(locale)) {
                    set = true;
                    break;
                }
            }
        }
    }
    if (!set) {
        if (log.isDebugEnabled()) {
            log.debug("Locale was not set to '" + locale
                    + "' as it could not be validated as a supported language.");
        }
    } else {
        localeSelector.setLocale(locale);
        localeSelector.setCookieEnabled(true);
        localeSelector.select();
    }
}

From source file:de.nico.ha_manager.activities.Preferences.java

@SuppressWarnings("deprecation")
private void setLanguage() {
    Preference language = findPreference("pref_app_language");

    // Locale of HW-Manager
    Locale appLoc = getResources().getConfiguration().locale;

    // Locale of device
    Locale devLoc = Locale.getDefault();

    if (devLoc.equals(appLoc)) {
        language.setSummary(getString(R.string.pref_language_default));
    } else {// w ww  . j a v a2  s . com
        language.setSummary(appLoc.getDisplayLanguage(appLoc));
    }
}

From source file:org.duniter.client.Main.java

protected void initI18n() throws IOException {
    Configuration config = Configuration.instance();

    // --------------------------------------------------------------------//
    // init i18n/*from w w w. j  a  va  2s.c  om*/
    // --------------------------------------------------------------------//
    File i18nDirectory = config.getI18nDirectory();
    if (i18nDirectory.exists()) {
        // clean i18n cache
        FileUtils.cleanDirectory(i18nDirectory);
    }

    FileUtils.forceMkdir(i18nDirectory);

    if (debug) {
        System.out.println("INFO - I18N directory: " + i18nDirectory);
    }

    Locale i18nLocale = config.getI18nLocale();

    // Fix locale
    if (i18nLocale.equals(Locale.FRENCH)) {
        i18nLocale = Locale.FRANCE;
    } else if (i18nLocale.equals(Locale.ENGLISH)) {
        i18nLocale = Locale.UK;
    }

    if (debug) {
        System.out.println(
                String.format("INFO - Starts i18n with locale [%s] at [%s]", i18nLocale, i18nDirectory));
    }
    I18n.init(new UserI18nInitializer(i18nDirectory, new DefaultI18nInitializer(getI18nBundleName())),
            i18nLocale);
}