]> git.mxchange.org Git - jjobs-war.git/commitdiff
Localization support almost finished:
authorRoland Haeder <roland@mxchange.org>
Mon, 4 Apr 2016 20:12:12 +0000 (22:12 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 4 Apr 2016 20:12:12 +0000 (22:12 +0200)
- 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

nbproject/faces-config.NavData
src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionBean.java
src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionController.java
src/java/org/mxchange/localization/bundle_de_DE.properties
src/java/org/mxchange/localization/bundle_en_US.properties
web/WEB-INF/faces-config.xml
web/WEB-INF/templates/base.tpl
web/WEB-INF/templates/generic/locale_selection_box.tpl
web/index.xhtml
web/resources/css/cssLayout.css

index 5ab655d9a7382348c8d4bf51d88e3a6849095bae..05b77d84171578feb179f443c57be9dc26ccc03d 100644 (file)
@@ -2,26 +2,26 @@
 <Scene Scope="Project" version="2">
     <Scope Scope="Faces Configuration Only"/>
     <Scope Scope="Project">
-        <Node id="login/login_change_password.xhtml" x="900" y="450" zoom="true"/>
         <Node id="privacy.xhtml" x="150" y="900" zoom="true"/>
+        <Node id="login/login_change_password.xhtml" x="900" y="450" zoom="true"/>
         <Node id="login/login_data_saved.xhtml" x="400" y="300" zoom="true"/>
         <Node id="user/register.xhtml" x="1150" y="150" zoom="true"/>
         <Node id="login/login_all_applications.xhtml" x="650" y="750" zoom="true"/>
+        <Node id="login/login_index.xhtml" x="900" y="600" zoom="true"/>
         <Node id="login/login_add_addressbook.xhtml" x="150" y="600" zoom="true"/>
         <Node id="user/resend_link.xhtml" x="650" y="600" zoom="true"/>
-        <Node id="login/login_index.xhtml" x="900" y="600" zoom="true"/>
         <Node id="login/login_own_addressbooks.xhtml" x="1150" y="300" zoom="true"/>
-        <Node id="terms.xhtml" x="150" y="150" zoom="true"/>
         <Node id="admin/admin_logout.xhtml" x="400" y="900" zoom="true"/>
+        <Node id="terms.xhtml" x="150" y="150" zoom="true"/>
         <Node id="user/user_list.xhtml" x="150" y="450" zoom="true"/>
         <Node id="bye.xhtml" x="650" y="150" zoom="true"/>
         <Node id="index.xhtml" x="650" y="300" zoom="true"/>
         <Node id="user/register_done.xhtml" x="400" y="450" zoom="true"/>
-        <Node id="user/user_profile.xhtml" x="900" y="150" zoom="true"/>
         <Node id="login/login_change_personal_data.xhtml" x="650" y="450" zoom="true"/>
+        <Node id="user/user_profile.xhtml" x="900" y="150" zoom="true"/>
+        <Node id="user/show_addressbook.xhtml" x="150" y="750" zoom="true"/>
         <Node id="*" x="150" y="300" zoom="true"/>
         <Node id="imprint.xhtml" x="400" y="600" zoom="true"/>
-        <Node id="user/show_addressbook.xhtml" x="150" y="750" zoom="true"/>
         <Node id="user/login_error.xhtml" x="900" y="300" zoom="true"/>
         <Node id="user/show_addressbook_entries.xhtml" x="1650" y="150" zoom="true"/>
         <Node id="admin/admin_index.xhtml" x="1400" y="150" zoom="true"/>
index 21e97bbcba323f64bb6159317ef96ce564990595..6abf13742147024c17c87282a4892cc6a310434d 100644 (file)
  */
 package org.mxchange.jjobs.beans.localization;
 
+import java.text.MessageFormat;
 import java.util.Locale;
 import javax.annotation.PostConstruct;
-import javax.faces.bean.SessionScoped;
+import javax.enterprise.context.SessionScoped;
 import javax.faces.context.FacesContext;
 import javax.inject.Named;
 import org.mxchange.jcoreee.database.BaseDatabaseBean;
@@ -47,35 +48,72 @@ public class JobsLocalizationSessionBean extends BaseDatabaseBean implements Job
 
        @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
        }
 
 }
index b2818729084ea722dc57cc3bd164cf8d77e55ef9..857dddc19dd72a10784a779e9d86f02e8b710704 100644 (file)
@@ -54,4 +54,11 @@ public interface JobsLocalizationSessionController extends Serializable {
         */
        void setLanguage (final String language);
 
+       /**
+        * Getter for selectable localizations
+        * <p>
+        * @return Selectable localizations
+        */
+       Locale[] getSelectableLocalizations ();
+
 }
index ab1a1909513b2df89adbe5762d4007263ffb1d87..82d0c37185ec160e4e46253d0bc8516841d70e6c 100644 (file)
@@ -286,3 +286,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)
index 654681f7ef88c76d54fc9046fe826fc3dbc9b3c5..3dfe86d65fdd420150c6f5cf044a33ca9197130a 100644 (file)
@@ -260,3 +260,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)
index 8c82d2f9e216dcf0c77b0b7bc6367a82d3b1a58b..0159679a742613e4ee0fb35e31172c562ac4abcf 100644 (file)
@@ -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">
        <application>
                <locale-config>
-                       <default-locale>de</default-locale>
+                       <default-locale>de_DE</default-locale>
                        <supported-locale>en_US</supported-locale>
                </locale-config>
        </application>
index 9bcf44e7d6865988da6964dc9bda48172890b78f..b2187caf5e2dca0f114b6ef10e8b9a84245e897d 100644 (file)
@@ -6,48 +6,49 @@
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://xmlns.jcp.org/jsf/core">
 
-       <h:head>
-               <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+       <f:view locale="#{localization.locale}" contentType="text/html">
+               <h:head>
+                       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 
-               <f:loadBundle var="msg" basename="org.mxchange.localization.bundle" />
-               <f:view locale="#{localization.locale}" />
+                       <f:loadBundle var="msg" basename="org.mxchange.localization.bundle" />
 
-               <h:outputStylesheet name="/css/default.css" />
-               <h:outputStylesheet name="/css/cssLayout.css" />
+                       <h:outputStylesheet name="/css/default.css" />
+                       <h:outputStylesheet name="/css/cssLayout.css" />
 
-               <title>JJobs - <ui:insert name="title">Default title</ui:insert></title>
-       </h:head>
+                       <title>JJobs - <ui:insert name="title">Default title</ui:insert></title>
+               </h:head>
 
-       <h:body>
-               <div id="top">
-                       <div id="header">
-                               <div id="title">
-                                       <h1>JJobs - <ui:insert name="title">Default title</ui:insert></h1>
+               <h:body id="body">
+                       <div id="top">
+                               <div id="header">
+                                       <div id="title">
+                                               <h1>JJobs - <ui:insert name="title">Default title</ui:insert></h1>
+                                       </div>
                                </div>
                        </div>
-               </div>
 
-               <div id="menu_content">
-                       <div id="left">
-                               <ui:insert name="menu">Default menu</ui:insert>
-                               <ui:include src="/WEB-INF/templates/generic/locale_selection_box.tpl" />
-                       </div>
-
-                       <div id="content_outer" class="left_content">
-                               <div id="content_header">
-                                       <ui:insert name="content_header">Default content header</ui:insert>
+                       <div id="menu_content">
+                               <div id="left">
+                                       <ui:insert name="menu">Default menu</ui:insert>
+                                       <ui:include src="/WEB-INF/templates/generic/locale_selection_box.tpl" />
                                </div>
 
-                               <div id="content">
-                                       <ui:insert name="content">Default content</ui:insert>
+                               <div id="content_outer" class="left_content">
+                                       <div id="content_header">
+                                               <ui:insert name="content_header">Default content header</ui:insert>
+                                       </div>
+
+                                       <div id="content">
+                                               <ui:insert name="content">Default content</ui:insert>
+                                       </div>
                                </div>
-                       </div>
 
-                       <div class="clear"></div>
-               </div>
+                               <div class="clear"></div>
+                       </div>
 
-               <div id="footer">
-                       <ui:insert name="footer">Default footer</ui:insert>
-               </div>
-       </h:body>
+                       <div id="footer">
+                               <ui:insert name="footer">Default footer</ui:insert>
+                       </div>
+               </h:body>
+       </f:view>
 </html>
index 16860b2d3cb83c7c4356275329a59ac9bb9c1fac..baea374b89333f6eb756a73061b73a814dd55496 100644 (file)
@@ -6,9 +6,9 @@
        xmlns:ui="http://java.sun.com/jsf/facelets">
 
        <h:form id="locale_selection">
-               <h:selectOneMenu value="#{localization.language}" onchange="submit()">
-                       <f:selectItem itemValue="de" itemLabel="Deutsch" />
-                       <f:selectItem itemValue="en" itemLabel="English" />
+               <h:selectOneMenu id="language_selection" value="#{localization.language}" onchange="submit()">
+                       <f:selectItem itemLabel="#{msg.SELECT_LANGUAGE}" noSelectionOption="true" />
+                       <f:selectItems value="#{localization.selectableLocalizations}" var="l" itemValue="#{l}" itemLabel="#{msg[l.toString().toUpperCase()]}" />
                </h:selectOneMenu>
        </h:form>
 </ui:composition>
index 1af56cbbbd0a5fd43527c1b7562031a30a0a1188..16cdb7ce2583e066444d24288cfb6024e58e5700 100644 (file)
@@ -1,10 +1,11 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"
-         xmlns:ui="http://java.sun.com/jsf/facelets"
-         xmlns:h="http://xmlns.jcp.org/jsf/html"
-         xmlns:f="http://xmlns.jcp.org/jsf/core"
-         >
+<html
+       xmlns="http://www.w3.org/1999/xhtml"
+       xmlns:ui="http://java.sun.com/jsf/facelets"
+       xmlns:h="http://xmlns.jcp.org/jsf/html"
+       xmlns:f="http://xmlns.jcp.org/jsf/core"
+       >
 
        <ui:composition template="/WEB-INF/templates/guest/guest_base.tpl">
                <ui:define name="guest_title">#{msg.PAGE_TITLE_INDEX_WELCOME}</ui:define>
index 18ff572bafa8ca69733c0b595e6070c2cb4e2c2b..22a6f9f4650eb8f58947ac46f1a36bfd26762233 100644 (file)
@@ -23,7 +23,7 @@ div, table {
        float: left;
        background-color: #ece3a5;
        padding: 5px;
-       width: 150px;
+       width: 170px;
 }
 
 #right {
@@ -41,7 +41,7 @@ div, table {
 
 .left_content {
        padding: 5px;
-       margin-left: 170px;
+       margin-left: 190px;
 }
 
 #top a:link, #top a:visited {