mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
User options to change UI language as well as content filter language.
Some small rationalizing of common code for above. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4754 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -16,13 +16,20 @@
|
||||
*/
|
||||
package org.alfresco.web.bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.model.SelectItem;
|
||||
|
||||
import org.alfresco.config.Config;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.bean.repository.PreferencesService;
|
||||
import org.alfresco.web.config.LanguagesConfigElement;
|
||||
|
||||
/**
|
||||
* Simple bean backing the user preferences settings.
|
||||
@@ -37,6 +44,131 @@ public class UserPreferencesBean
|
||||
private static final String MSG_COMPANYHOME = "company_home";
|
||||
private static final String MSG_GUESTHOME = "guest_home";
|
||||
|
||||
private static final String PREF_CONTENTFILTERLANGUAGE = "content-filter-language";
|
||||
private static final String MSG_CONTENTALLLANGUAGES = "content_all_languages";
|
||||
|
||||
/** language locale selection */
|
||||
private String language = null;
|
||||
|
||||
/** content language locale selection */
|
||||
private String contentFilterLanguage = null;
|
||||
|
||||
private SelectItem[] getLanguageItems(boolean includeAllLanguages)
|
||||
{
|
||||
Config config = Application.getConfigService(FacesContext.getCurrentInstance()).getConfig("Languages");
|
||||
LanguagesConfigElement langConfig = (LanguagesConfigElement)config.getConfigElement(
|
||||
LanguagesConfigElement.CONFIG_ELEMENT_ID);
|
||||
|
||||
List<String> languages = langConfig.getLanguages();
|
||||
List<SelectItem> items = new ArrayList<SelectItem>(20);
|
||||
if (includeAllLanguages)
|
||||
{
|
||||
ResourceBundle msg = Application.getBundle(FacesContext.getCurrentInstance());
|
||||
String allLanguagesStr = msg.getString(MSG_CONTENTALLLANGUAGES);
|
||||
items.add(new SelectItem(MSG_CONTENTALLLANGUAGES, allLanguagesStr));
|
||||
}
|
||||
for (String locale : languages)
|
||||
{
|
||||
// get label associated to the locale
|
||||
String label = langConfig.getLabelForLanguage(locale);
|
||||
items.add(new SelectItem(locale, label));
|
||||
}
|
||||
|
||||
SelectItem[] result = new SelectItem[items.size()];
|
||||
return items.toArray(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the available languages
|
||||
*/
|
||||
public SelectItem[] getLanguages()
|
||||
{
|
||||
// Get the item selection list
|
||||
SelectItem[] items = getLanguageItems(false);
|
||||
// Change the current language
|
||||
if (this.language == null)
|
||||
{
|
||||
// first try to get the language that the current user is using
|
||||
Locale lastLocale = Application.getLanguage(FacesContext.getCurrentInstance());
|
||||
if (lastLocale != null)
|
||||
{
|
||||
this.language = lastLocale.toString();
|
||||
}
|
||||
// else we default to the first item in the list
|
||||
else if (items.length > 0)
|
||||
{
|
||||
this.language = (String) items[0].getValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The language list is empty");
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the language selection.
|
||||
*/
|
||||
public String getLanguage()
|
||||
{
|
||||
return this.language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param language The language selection to set.
|
||||
*/
|
||||
public void setLanguage(String language)
|
||||
{
|
||||
this.language = language;
|
||||
Application.setLanguage(FacesContext.getCurrentInstance(), this.language);
|
||||
}
|
||||
|
||||
public String getContentFilterLanguage()
|
||||
{
|
||||
if (this.contentFilterLanguage == null)
|
||||
{
|
||||
Locale locale = (Locale) PreferencesService.getPreferences().getValue(PREF_CONTENTFILTERLANGUAGE);
|
||||
// Null means All Languages
|
||||
if (locale == null)
|
||||
{
|
||||
this.contentFilterLanguage = MSG_CONTENTALLLANGUAGES;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.contentFilterLanguage = locale.toString();
|
||||
}
|
||||
}
|
||||
return contentFilterLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param languageStr A valid locale string or {@link #MSG_CONTENTALLLANGUAGES}
|
||||
*/
|
||||
public void setContentFilterLanguage(String languageStr)
|
||||
{
|
||||
this.contentFilterLanguage = languageStr;
|
||||
Locale language = null;
|
||||
if (languageStr.equals(MSG_CONTENTALLLANGUAGES))
|
||||
{
|
||||
// The generic "All Languages" was selected - persist this as a null
|
||||
}
|
||||
else
|
||||
{
|
||||
// It should be a proper locale string
|
||||
language = I18NUtil.parseLocale(languageStr);
|
||||
}
|
||||
PreferencesService.getPreferences().setValue(PREF_CONTENTFILTERLANGUAGE, language);
|
||||
}
|
||||
|
||||
public SelectItem[] getContentFilterLanguages()
|
||||
{
|
||||
// Get the item selection list
|
||||
SelectItem[] items = getLanguageItems(true);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
public String getStartLocation()
|
||||
{
|
||||
|
Reference in New Issue
Block a user