]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Localization support almost finished:
authorRoland Haeder <roland@mxchange.org>
Mon, 4 Apr 2016 20:12:15 +0000 (22:12 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 4 Apr 2016 20:12:15 +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/localization/bundle_de_DE.properties
src/java/org/mxchange/localization/bundle_en_US.properties
src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionController.java
web/WEB-INF/faces-config.xml
web/WEB-INF/templates/base.tpl
web/WEB-INF/templates/generic/locale_selection_box.tpl
web/resources/css/cssLayout.css

index dc560dfacb78c9cd9f0c8fe8a4eb53817a432749..69a5d2ec1351c7457a2e16d5d2a4a64c3b9f0aa5 100644 (file)
@@ -1,25 +1,25 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scene Scope="Project" version="2">
-       <Scope Scope="Faces Configuration Only"/>
-       <Scope Scope="Project">
-               <Node id="admin/admin_logout.xhtml" x="400" y="600" zoom="true"/>
-               <Node id="item_added.xhtml" x="1150" y="150" zoom="true"/>
-               <Node id="admin/index.xhtml" x="400" y="300" zoom="true"/>
-               <Node id="*" x="150" y="300" zoom="true"/>
-               <Node id="customer/register.xhtml" x="650" y="150" zoom="true"/>
-               <Node id="errorHandler.xhtml" x="900" y="450" zoom="true"/>
-               <Node id="terms.xhtml" x="650" y="300" zoom="true"/>
-               <Node id="customer/checkout.xhtml" x="400" y="150" zoom="true"/>
-               <Node id="bye.xhtml" x="650" y="450" zoom="true"/>
-               <Node id="privacy.xhtml" x="150" y="150" zoom="true"/>
-               <Node id="customer/checkout2.xhtml" x="150" y="750" zoom="true"/>
-               <Node id="index.xhtml" x="1400" y="150" zoom="true"/>
-               <Node id="imprint.xhtml" x="1150" y="300" zoom="true"/>
-               <Node id="admin/category.xhtml" x="150" y="600" zoom="true"/>
-               <Node id="customer/lost_passwd.xhtml" x="400" y="450" zoom="true"/>
-               <Node id="basket.xhtml" x="900" y="150" zoom="true"/>
-               <Node id="admin/product.xhtml" x="150" y="450" zoom="true"/>
-               <Node id="customer/login.xhtml" x="900" y="300" zoom="true"/>
-       </Scope>
-       <Scope Scope="All Faces Configurations"/>
+    <Scope Scope="Faces Configuration Only"/>
+    <Scope Scope="Project">
+        <Node id="customer/checkout2.xhtml" x="150" y="750" zoom="true"/>
+        <Node id="bye.xhtml" x="650" y="450" zoom="true"/>
+        <Node id="index.xhtml" x="1400" y="150" zoom="true"/>
+        <Node id="errorHandler.xhtml" x="900" y="450" zoom="true"/>
+        <Node id="privacy.xhtml" x="150" y="150" zoom="true"/>
+        <Node id="customer/checkout.xhtml" x="400" y="150" zoom="true"/>
+        <Node id="*" x="150" y="300" zoom="true"/>
+        <Node id="imprint.xhtml" x="1150" y="300" zoom="true"/>
+        <Node id="customer/login.xhtml" x="900" y="300" zoom="true"/>
+        <Node id="admin/category.xhtml" x="150" y="600" zoom="true"/>
+        <Node id="admin/index.xhtml" x="400" y="300" zoom="true"/>
+        <Node id="basket.xhtml" x="900" y="150" zoom="true"/>
+        <Node id="customer/register.xhtml" x="650" y="150" zoom="true"/>
+        <Node id="item_added.xhtml" x="1150" y="150" zoom="true"/>
+        <Node id="admin/product.xhtml" x="150" y="450" zoom="true"/>
+        <Node id="terms.xhtml" x="650" y="300" zoom="true"/>
+        <Node id="admin/admin_logout.xhtml" x="400" y="600" zoom="true"/>
+        <Node id="customer/lost_passwd.xhtml" x="400" y="450" zoom="true"/>
+    </Scope>
+    <Scope Scope="All Faces Configurations"/>
 </Scene>
index 8e05451c3a37a7f353f3188c108f3e7f525c029a..f15191e0aa9297dd5874411ad463cf99253c98a6 100644 (file)
@@ -193,3 +193,6 @@ TERMS_CONDITIONS=Allgemeine Gesch\u00e4ftsbestimmungen
 NONE_SELECTED=k.A.
 ENTERED_HOUSE_NUMBER_INVALID=Die eingegebene Hausnummer ist ung\u00fcltig.
 ENTERED_ZIP_CODE_INVALID=Die eingegebene Postleitzahl ist ung\u00fcltig.
+SELECT_LANGUAGE=Sprache:
+DE_DE=Deutsch (DE)
+EN_US=Englisch (US)
index f3f9db31756ab07cc9cf0612136c66af949cca88..be73f23237863a67394e818284b9f3b0ccc2995c 100644 (file)
@@ -193,3 +193,6 @@ TERMS_CONDITIONS=Terms & Conditions
 NONE_SELECTED=Empty
 ENTERED_HOUSE_NUMBER_INVALID=The entered house number is invalid.
 ENTERED_ZIP_CODE_INVALID=The entered ZIP code is invalid.
+SELECT_LANGUAGE=Language:
+DE_DE=German (DE)
+EN_US=English (US)
index 1e98b41e54d119e82c568eb2ab8b029eac22f1eb..bcd72c060a9565a1d6c49ccbda7a4e8486b41894 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.pizzaapplication.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 PizzaLocalizationSessionBean extends BaseDatabaseBean implements Pi
        /**
         * Serial number
         */
-       private static final long serialVersionUID = 1_867_671_657_629_601_528L;
+       private static final long serialVersionUID = 639_184_671_562_195L;
 
        /**
         * Current Locale
@@ -47,35 +48,72 @@ public class PizzaLocalizationSessionBean extends BaseDatabaseBean implements Pi
 
        @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 430923d07865db36fa624d9a4d9b1c0e56c79912..7150b33000fbe16d3891810b19006003105413f8 100644 (file)
@@ -54,4 +54,11 @@ public interface PizzaLocalizationSessionController extends Serializable {
         */
        void setLanguage (final String language);
 
+       /**
+        * Getter for selectable localizations
+        * <p>
+        * @return Selectable localizations
+        */
+       Locale[] getSelectableLocalizations ();
+
 }
index c1187b0f50ab816d331b3a3786f4a9f8c6a3faa4..d181a5635897227883079f7830b40c589adc4eaf 100644 (file)
@@ -3,6 +3,12 @@
                          xmlns="http://xmlns.jcp.org/xml/ns/javaee"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          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_DE</default-locale>
+                       <supported-locale>en_US</supported-locale>
+               </locale-config>
+       </application>
        <validator>
                <validator-id>PrivacyTermsCheckboxValidator</validator-id>
                <validator-class>org.mxchange.jcoreee.validator.bool.privacy_terms.PrivacyTermsCheckboxValidator</validator-class>
index 712904cf2ad40358ed2aee031d0ce8f1ab35f168..96b05e2155f378099ef8a788e0e32f9b8e1e7ba1 100644 (file)
@@ -6,55 +6,56 @@
        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>Pizza-Service - <ui:insert name="title">Default title</ui:insert></title>
-       </h:head>
+                       <title>Pizza-Service - <ui:insert name="title">Default title</ui:insert></title>
+               </h:head>
 
-       <h:body>
-               <div id="top">
-                       <div id="header">
-                               <div id="title">
-                                       <h1>Pizza-Service - <ui:insert name="title">Default title</ui:insert></h1>
+               <h:body>
+                       <div id="top">
+                               <div id="header">
+                                       <div id="title">
+                                               <h1>Pizza-Service - <ui:insert name="title">Default title</ui:insert></h1>
+                                       </div>
                                </div>
                        </div>
-               </div>
-
-               <!--
-               Mini basket on left side
-               //-->
-               <div id="mini_basket">
-                       <ui:insert name="basket" />
-               </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" />
+
+                       <!--
+                       Mini basket on left side
+                       //-->
+                       <div id="mini_basket">
+                               <ui:insert name="basket" />
                        </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 321cf6466c916c6e612600b6250354014ac107a3..22a6f9f4650eb8f58947ac46f1a36bfd26762233 100644 (file)
@@ -23,7 +23,7 @@ div, table {
        float: left;
        background-color: #ece3a5;
        padding: 5px;
-       width: 150px;
+       width: 170px;
 }
 
 #right {
@@ -40,15 +40,8 @@ div, table {
 }
 
 .left_content {
-       background-color: #dddddd;
        padding: 5px;
-       margin-left: 170px;
-}
-
-.right_content {
-       background-color: #dddddd;
-       padding: 5px;
-       margin: 0px 170px 0px 170px;
+       margin-left: 190px;
 }
 
 #top a:link, #top a:visited {
@@ -72,8 +65,8 @@ table, .table {
        width: 500px;
 }
 
-.basket_item_table {
-       width: 600px;
+.table_big {
+       width: 100%;
 }
 
 .table_row {
@@ -136,20 +129,26 @@ ul.footer_nav li.footer_copyright {
        padding-left: 5px;
 }
 
-.table_header {
+.table_header, .table_label, .message_header {
        text-align: center;
        font-weight: bold;
 }
 
 #content_header {
+       background-color: #dddddd;
        font-weight: bold;
        font-size: 18px;
+       margin-bottom: 20px;
 }
 
 .table_header_column {
        width: 100px;
 }
 
+.table_header_column25 {
+       width: 25%;
+}
+
 .table_data_column {
        width: 100px;
 }
@@ -157,3 +156,32 @@ ul.footer_nav li.footer_copyright {
 .item_price, .item_total_price {
        text-align: right;
 }
+
+.errors {
+       color: red;
+}
+
+.fatals {
+       color: red;
+       font-weight: bold;
+}
+
+.infos {
+       color: cornflowerblue;
+}
+
+.warnings {
+       color: gold;
+}
+
+.message_box {
+       width: 400px;
+}
+
+.message_header {
+       background-color: #dddddd;
+}
+
+.okay {
+       color: #00aa00;
+}