Results 1 to 3 of 3
  1. #1
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    187
    Rep Power
    2

    Default Set German as default language (Internationalization)

    Hello,

    I have problem with the Internationalization, i need to have 2 language (German and English) where German is the default language.

    Somehow it display English always as default language, i tried every thing, but it still English the default.

    How to make the German is the default??

    Java Code:
    package com.mycompany.internationalization;
    
    import java.io.Serializable;
    import java.util.Locale;
    import java.util.logging.Logger;
    
    import javax.annotation.PostConstruct;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    import javax.faces.context.FacesContext;
    
    /**
     * Used for managing i18n in application for each user
     *
     */
    
    @ManagedBean
    @SessionScoped
    public class LanguageSwitcher implements Serializable {
    
        private Locale locale;
    
        private static final Logger LOG = Logger.getLogger(LanguageSwitcher.class.getName());
        
        private static final long serialVersionUID = 2756934361134603857L;
    
        public void init() {
            locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
        }
    
        public Locale getLocale() {
            return locale;
        }
    
        public void setLanguage(String language) {
            locale = new Locale(language);
            FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
        }
    
    }
    I have two simple xhtml pages

    1- hi.xhtml
    XML Code:
    <?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:h="http://java.sun.com/jsf/html"
          xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core">
        <f:view locale="#{langSwitcher.locale}">
        <h:head>
            <title>Hi</title>
    
        </h:head>
        <h:body>
            <h:form id="hi">
                <div id="sidebar">
                    <h:commandLink action="#{languageSwitcher.setLanguage('de')}" value="Deutsch" /> |
                    <h:commandLink action="#{languageSwitcher.setLanguage('en')}" value="English" />
                </div>
                #{sprache.hi}
    
                <br></br>
                <br></br>
                <h:commandLink value="ToWelcome" action="welcome?faces-redirect=true" style="margin-right:20px;"/>
            </h:form>
        </h:body>
        </f:view>
    </html>

    2- welcome.xhtml
    XML Code:
    <?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:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core">
        <f:view locale="#{langSwitcher.locale}">
        <h:head>
            <title>welcome</title>
    
        </h:head>
        <h:body>
            <h:form id="hi">
                <div id="sidebar">
                        <h:commandLink action="#{languageSwitcher.setLanguage('de')}" value="Deutsch" /> |
                        <h:commandLink action="#{languageSwitcher.setLanguage('en')}" value="English" />
                </div>
                #{sprache.welcome}
    
                <br></br>
                <br></br>
                <h:commandLink value="ToHi" action="hi?faces-redirect=true" style="margin-right:20px;"/>
            </h:form>
        </h:body>
        </f:view>
    </html>
    I have 3 Properties file
    1- lang.Properties
    PHP Code:
    hi = Hi auf Deutsch
    welcome = Willkommen
    2- 1- lang_de.Properties
    PHP Code:
    hi = Hi auf Deutsch
    welcome = Willkommen
    3- 1- lang_en.Properties
    PHP Code:
    hi = Hi in English
    welcome = welcome
    faces-config.xml
    XML Code:
    <?xml version="1.0"?>
    <faces-config xmlns="http://java.sun.com/xml/ns/javaee" 
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
                  version="2.0">
        
        <application>
            <locale-config>
                <default-locale>de</default-locale>
            </locale-config>
            <resource-bundle>
                <base-name>I18n.lang</base-name>
                <var>sprache</var>
            </resource-bundle>
        </application>
    
    </faces-config>

    That all what i have

    ps: i don't any command line to the web.xml

    Any body know how to configure it to display German as Default?
    Last edited by vector_ever; 06-24-2014 at 09:37 PM.

  2. #2
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    187
    Rep Power
    2

    Default Re: Set German as default language (Internationalization)

    I found the solution

    I make every thing possible but nothing change

    At last i change English language code en to en_us
    it is work now

    lang_en.Properties will be lang_en_us.Properties

    Java Code:
    <h:commandLink action="#{langSwitcher.setLanguage('en')}" value="English" />
    will be 
    <h:commandLink action="#{langSwitcher.setLanguage('en_us')}" value="English" />

  3. #3
    Join Date
    Apr 2014
    Posts
    50
    Rep Power
    0

    Default Re: Set German as default language (Internationalization)

    You can look at this how default language is set JSF2 Internationalization example | Web Tutorials

Similar Threads

  1. Replies: 0
    Last Post: 07-02-2011, 01:58 PM
  2. default writing language selection in JTextfeaild
    By bravvve in forum AWT / Swing
    Replies: 0
    Last Post: 03-10-2011, 09:21 AM
  3. Support for German alphabets
    By javaplus in forum New To Java
    Replies: 1
    Last Post: 01-18-2008, 04:45 AM
  4. Internationalization: Select language from combo box
    By alejandrgarcia in forum AWT / Swing
    Replies: 0
    Last Post: 08-11-2007, 11:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •