diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index 7cef65ee78..6bd7fe99b6 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -1168,6 +1168,9 @@ new_password=New Password edit_user_details=Edit User Details edit_user_details_description=Use this view to change your user details and email address start_location=Start Location +interface_language=Interface Language +content_language_filter=Content Language Filter +content_all_languages=All Languages # Delete Space Dialog messages select_delete_operation=What do you want to delete? diff --git a/config/alfresco/web-client-config.xml b/config/alfresco/web-client-config.xml index 6588b55c89..4991b3997f 100644 --- a/config/alfresco/web-client-config.xml +++ b/config/alfresco/web-client-config.xml @@ -76,6 +76,8 @@ English + French + Japanese diff --git a/source/java/org/alfresco/web/app/Application.java b/source/java/org/alfresco/web/app/Application.java index d9915a09cf..bfee708490 100644 --- a/source/java/org/alfresco/web/app/Application.java +++ b/source/java/org/alfresco/web/app/Application.java @@ -21,7 +21,6 @@ import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.ResourceBundle; -import java.util.StringTokenizer; import javax.faces.context.FacesContext; import javax.portlet.PortletContext; @@ -33,6 +32,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.alfresco.config.ConfigService; +import org.alfresco.i18n.I18NUtil; import org.alfresco.repo.importer.ImporterBootstrap; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.web.app.servlet.AuthenticationHelper; @@ -495,7 +495,7 @@ public class Application @SuppressWarnings("unchecked") public static void setLanguage(FacesContext context, String code) { - Locale locale = parseLocale(code); + Locale locale = I18NUtil.parseLocale(code); // set locale for JSF framework usage context.getViewRoot().setLocale(locale); @@ -515,38 +515,12 @@ public class Application */ public static void setLanguage(HttpSession session, String code) { - Locale locale = parseLocale(code); + Locale locale = I18NUtil.parseLocale(code); session.setAttribute(LOCALE, locale); session.removeAttribute(MESSAGE_BUNDLE); } - /** - * @param code Locale code (java format with underscores) to parse - * @return Locale object or default if unable to parse - */ - private static Locale parseLocale(String code) - { - Locale locale = Locale.getDefault(); - - StringTokenizer t = new StringTokenizer(code, "_"); - int tokens = t.countTokens(); - if (tokens == 1) - { - locale = new Locale(code); - } - else if (tokens == 2) - { - locale = new Locale(t.nextToken(), t.nextToken()); - } - else if (tokens == 3) - { - locale = new Locale(t.nextToken(), t.nextToken(), t.nextToken()); - } - - return locale; - } - /** * Return the language Locale for the current user context * diff --git a/source/java/org/alfresco/web/bean/LoginBean.java b/source/java/org/alfresco/web/bean/LoginBean.java index 0efa685854..2dcd137040 100644 --- a/source/java/org/alfresco/web/bean/LoginBean.java +++ b/source/java/org/alfresco/web/bean/LoginBean.java @@ -18,18 +18,14 @@ package org.alfresco.web.bean; import java.io.IOException; import java.text.MessageFormat; -import java.util.List; -import java.util.Locale; import java.util.Map; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; -import javax.faces.model.SelectItem; import javax.faces.validator.ValidatorException; import javax.servlet.http.HttpServletRequest; -import org.alfresco.config.Config; import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationException; import org.alfresco.service.cmr.repository.InvalidNodeRefException; @@ -42,7 +38,6 @@ import org.alfresco.web.app.servlet.AuthenticationHelper; import org.alfresco.web.app.servlet.FacesHelper; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.bean.repository.User; -import org.alfresco.web.config.LanguagesConfigElement; import org.alfresco.web.ui.common.Utils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -166,62 +161,6 @@ public class LoginBean return this.password; } - /** - * @return the available languages - */ - public SelectItem[] getLanguages() - { - Config config = Application.getConfigService(FacesContext.getCurrentInstance()).getConfig("Languages"); - LanguagesConfigElement langConfig = (LanguagesConfigElement)config.getConfigElement( - LanguagesConfigElement.CONFIG_ELEMENT_ID); - - List languages = langConfig.getLanguages(); - SelectItem[] items = new SelectItem[languages.size()]; - int count = 0; - for (String locale : languages) - { - // get label associated to the locale - String label = langConfig.getLabelForLanguage(locale); - - // set default selection - if (count == 0 && 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 - { - this.language = locale; - } - } - - items[count++] = new SelectItem(locale, label); - } - - 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); - } - // ------------------------------------------------------------------------------ // Validator methods @@ -419,9 +358,10 @@ public class LoginBean session.put(AuthenticationHelper.SESSION_INVALIDATED, true); // set language to last used - if (this.language != null && this.language.length() != 0) + String language = preferences.getLanguage(); + if (language != null && language.length() != 0) { - Application.setLanguage(context, this.language); + Application.setLanguage(context, language); } return externalAuth ? "logout" : "relogin"; @@ -451,9 +391,6 @@ public class LoginBean /** password */ private String password = null; - /** language locale selection */ - private String language = null; - /** PersonService bean reference */ protected PersonService personService; diff --git a/source/java/org/alfresco/web/bean/UserPreferencesBean.java b/source/java/org/alfresco/web/bean/UserPreferencesBean.java index 692e3dd7e3..a37af4347a 100644 --- a/source/java/org/alfresco/web/bean/UserPreferencesBean.java +++ b/source/java/org/alfresco/web/bean/UserPreferencesBean.java @@ -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 languages = langConfig.getLanguages(); + List items = new ArrayList(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() { diff --git a/source/web/jsp/login.jsp b/source/web/jsp/login.jsp index c7f4e1209a..460cb57462 100644 --- a/source/web/jsp/login.jsp +++ b/source/web/jsp/login.jsp @@ -112,8 +112,8 @@ <%-- language selection drop-down --%> - - + + diff --git a/source/web/jsp/users/user-console.jsp b/source/web/jsp/users/user-console.jsp index 6457bc0636..58cafb743b 100644 --- a/source/web/jsp/users/user-console.jsp +++ b/source/web/jsp/users/user-console.jsp @@ -153,6 +153,28 @@ + + + :  + + + <%-- Interface Language drop-down selector --%> + + + + + + + + :  + + + <%-- Content Language Filter drop-down selector --%> + + + + +