# Deutsch Als Standardsprache (Internationalisierung)



## vector_ever (24. Jun 2014)

Hallo,

Ich habe eine JSF Seiten, die Deutsch und Englisch Sprachen haben.
Deutsch muss Standardsprache sein.
aber irgendwie Englisch ist immer die Standardsprache.


```
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);
    }
 
}
```

Ich habe 2 einfache xhtml Seiten

1- hi.xhtml

```
<?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 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>
```

Dafür habe ich 3 Properties Datei
1- lang.Properties 

```
hi = Hi auf Deutsch
welcome = Willkommen
```

2- lang_de.Properties 

```
hi = Hi auf Deutsch
welcome = Willkommen
```

3- lang_en.Properties 

```
hi = Hi in English
welcome = welcome
```

faces-config.xml

```
<?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>
```

Also, wie kann ich es schaffen, und Deutsch als Standardsprache einstellen?


----------

