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()]);
}
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();
}
}
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;
}
Aggregations