Search in sources :

Example 1 with LanguagesConfigElement

use of org.alfresco.web.config.LanguagesConfigElement in project acs-community-packaging by Alfresco.

the class UserPreferencesBean method getLanguageItems.

/**
 * Helper to return the available language items
 *
 * @return Array of SelectItem objects
 */
private static SelectItem[] getLanguageItems() {
    FacesContext fc = FacesContext.getCurrentInstance();
    Config config = Application.getConfigService(fc).getConfig("Languages");
    LanguagesConfigElement langConfig = (LanguagesConfigElement) config.getConfigElement(LanguagesConfigElement.CONFIG_ELEMENT_ID);
    List<String> languages = langConfig.getLanguages();
    List<SelectItem> items = new ArrayList<SelectItem>(10);
    for (String locale : languages) {
        // get label associated to the locale
        String label = langConfig.getLabelForLanguage(locale);
        items.add(new SelectItem(locale, label));
    }
    return items.toArray(new SelectItem[items.size()]);
}
Also used : FacesContext(javax.faces.context.FacesContext) LanguagesConfigElement(org.alfresco.web.config.LanguagesConfigElement) Config(org.springframework.extensions.config.Config) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList)

Example 2 with LanguagesConfigElement

use of org.alfresco.web.config.LanguagesConfigElement in project acs-community-packaging by Alfresco.

the class Application method getLanguage.

/**
 * Return the configured language Locale for the application context
 *
 * @param ctx
 *           the application context
 * @return Current language Locale set or the VM default if none set - never null
 */
public static Locale getLanguage(ApplicationContext ctx) {
    // get from web-client config - the first item in the configured list of languages
    Config config = ((ConfigService) ctx.getBean(Application.BEAN_CONFIG_SERVICE)).getConfig("Languages");
    LanguagesConfigElement langConfig = (LanguagesConfigElement) config.getConfigElement(LanguagesConfigElement.CONFIG_ELEMENT_ID);
    List<String> languages = langConfig.getLanguages();
    if (languages != null && languages.size() != 0) {
        return I18NUtil.parseLocale(languages.get(0));
    } else {
        // failing that, use the server default locale
        return Locale.getDefault();
    }
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) LanguagesConfigElement(org.alfresco.web.config.LanguagesConfigElement) Config(org.springframework.extensions.config.Config)

Example 3 with LanguagesConfigElement

use of org.alfresco.web.config.LanguagesConfigElement in project acs-community-packaging by Alfresco.

the class Application method getLanguage.

/**
 * Return the language Locale for the current user context
 *
 * @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;
}
Also used : Locale(java.util.Locale) LanguagesConfigElement(org.alfresco.web.config.LanguagesConfigElement) Config(org.springframework.extensions.config.Config) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap)

Aggregations

LanguagesConfigElement (org.alfresco.web.config.LanguagesConfigElement)3 Config (org.springframework.extensions.config.Config)3 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 Map (java.util.Map)1 FacesContext (javax.faces.context.FacesContext)1 SelectItem (javax.faces.model.SelectItem)1 MimetypeMap (org.alfresco.repo.content.MimetypeMap)1 ConfigService (org.springframework.extensions.config.ConfigService)1