From: Roland Haeder Date: Mon, 4 Apr 2016 20:12:08 +0000 (+0200) Subject: Localization support almost finished: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=dcc80bdbe3b17dde5c44fe34bdf421e046794cad;p=addressbook-war.git Localization support almost finished: - Locale setting from browser comes first - User selected locale from web interfaces overrides it (in session bean) TODO/FIXME: - Add locale support to juser-core - Still the selected locale is not re-selected in box --- diff --git a/nbproject/faces-config.NavData b/nbproject/faces-config.NavData index 9699a575..63d1cc11 100644 --- a/nbproject/faces-config.NavData +++ b/nbproject/faces-config.NavData @@ -31,19 +31,19 @@ - + + - - + diff --git a/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionBean.java b/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionBean.java index 9316575d..324a7335 100644 --- a/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionBean.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.beans.localization; +import java.text.MessageFormat; import java.util.Locale; import javax.annotation.PostConstruct; import javax.faces.bean.SessionScoped; @@ -38,7 +39,7 @@ public class AddressbookLocalizationSessionBean extends BaseDatabaseBean impleme /** * Serial number */ - private static final long serialVersionUID = 1_867_671_657_629_601_528L; + private static final long serialVersionUID = 158_768_216_759_107L; /** * Current Locale @@ -47,35 +48,72 @@ public class AddressbookLocalizationSessionBean extends BaseDatabaseBean impleme @Override public String getLanguage () { - return this.getLocale().getLanguage(); + this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::getLanguage(): locale.language={0} - EXIT!", this.getLocale().getLanguage())); //NOI18N + return this.getLocale().getLanguage().toLowerCase(); } @Override public void setLanguage (final String language) { - this.setLocale(new Locale(language)); - FacesContext.getCurrentInstance().getViewRoot().setLocale(this.getLocale()); + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::setLanguage: language={0} - CALLED!", language)); //NOI18N + + // Language splits + String[] splits = language.split("_"); + if (null == splits[1]) { + splits[1] = ""; + } + + // Get new locale with upper-case country code + Locale loc = new Locale(splits[0], splits[1]); + + // Log debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("JobsLocalizationSessionBean::setLanguage: loc={0}", loc)); //NOI18N + + // Set it here and in the JSF context + this.setLocale(loc); + FacesContext.getCurrentInstance().getViewRoot().setLocale(loc); + + // Log trace message + this.getLoggerBeanLocal().logTrace("JobsLocalizationSessionBean::setLanguage: EXIT!"); //NOI18N } @Override public Locale getLocale () { + this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::getLocale(): locale={0} - EXIT!", this.locale)); //NOI18N return this.locale; } @Override public void setLocale (final Locale locale) { + this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::setLocale(): locale={0} - CALLED!", locale)); //NOI18N this.locale = locale; } + @Override + public Locale[] getSelectableLocalizations () { + Locale[] locales = {Locale.GERMANY, Locale.US}; + return locales; + } + /** * Initializer for this bean */ @PostConstruct public void init () { + // Log trace message + this.getLoggerBeanLocal().logTrace("JobsLocalizationSessionBean::init: CALLED!"); //NOI18N + // Create locale instance from context Locale loc = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale(); + // Log debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("JobsLocalizationSessionBean::init: loc={0}", loc)); //NOI18N + // Set it here this.setLocale(loc); + + // Log trace message + this.getLoggerBeanLocal().logTrace("JobsLocalizationSessionBean::init: EXIT!"); //NOI18N } } diff --git a/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionController.java b/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionController.java index 81bda8f1..00fef991 100644 --- a/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionController.java @@ -54,4 +54,11 @@ public interface AddressbookLocalizationSessionController extends Serializable { */ void setLanguage (final String language); + /** + * Getter for selectable localizations + *

+ * @return Selectable localizations + */ + Locale[] getSelectableLocalizations (); + } diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index ccfb1ff9..eb503caa 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -316,3 +316,6 @@ CONTENT_TITLE_LOGIN_CHANGE_EMAIL_ADDRESS=Neue Email-Adresse eingeben: PAGE_TITLE_LOGIN_CHANGE_PERSONAL_DATA=Ihre persoenlichen Daten aendern #TODO: Please fix German umlaut! CONTENT_TITLE_LOGIN_CHANGE_PERSONAL_DATA=Aendern Ihrer Adresse, Telefonnummer usw.: +SELECT_LANGUAGE=Sprache: +DE_DE=Deutsch (DE) +EN_US=Englisch (US) diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 7c57bd62..71ab7f5c 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -290,3 +290,6 @@ PAGE_TITLE_LOGIN_CHANGE_EMAIL_ADDRESS=Change your email address CONTENT_TITLE_LOGIN_CHANGE_EMAIL_ADDRESS=Enter new email address: PAGE_TITLE_LOGIN_CHANGE_PERSONAL_DATA=Change your personal data CONTENT_TITLE_LOGIN_CHANGE_PERSONAL_DATA=Change your address, phone number or others: +SELECT_LANGUAGE=Language: +DE_DE=German (DE) +EN_US=English (US) diff --git a/web/WEB-INF/faces-config.xml b/web/WEB-INF/faces-config.xml index c7261f80..60dd8560 100644 --- a/web/WEB-INF/faces-config.xml +++ b/web/WEB-INF/faces-config.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"> - de + de_DE en_US diff --git a/web/WEB-INF/templates/base.tpl b/web/WEB-INF/templates/base.tpl index 3b6ccd29..f03edab7 100644 --- a/web/WEB-INF/templates/base.tpl +++ b/web/WEB-INF/templates/base.tpl @@ -6,48 +6,49 @@ xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://xmlns.jcp.org/jsf/core"> - - + + + - - + - - + + - Addressbook - <ui:insert name="title">Default title</ui:insert> - + Addressbook - <ui:insert name="title">Default title</ui:insert> + - -

-