1

I was trying to include translations in my website, german and english. Sadly i seem to be to stupid to do it right and can't spot the problem. Can someone tell my why my language wont load? It always sticks with the default language.properties file and wont change to language_de / language_en

Here is my faces-config

<?xml version="1.0" encoding="UTF-8"?>
<faces-config 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"
version="2.2">

<application>
    <locale-config>
        <default-locale>de</default-locale>
        <supported-locale>en</supported-locale>
    </locale-config>
    <resource-bundle>
        <base-name>language</base-name>
        <var>language</var>
    </resource-bundle>
</application>

</faces-config>

Here is my project structure
enter image description here
Here is the component i use to change the language

<p:link id="buttonHeader_languageLink">
            <p:graphicImage id="buttonHeader_languageIcon"
                value="#{languageBean.currentLanguage.graphicPath}"
                onclick="#{languageBean.changeLanguage()}"></p:graphicImage>
</p:link>

and my ManagedBean

@ManagedBean
@SessionScoped
public class LanguageBean implements Serializable {

  private static final long serialVersionUID = 1L;

  private final static SessionLanguage GERMAN = new SessionLanguage(new Locale("de"), "/resource/image/german.png");
  private final static SessionLanguage ENGLISH = new SessionLanguage(new Locale("en"), "/resource/image/english.png");
  private SessionLanguage currentLanguage = GERMAN;

  public SessionLanguage getCurrentLanguage() {
    return currentLanguage;
  }

  public void changeLanguage() {
      if(currentLanguage.equals(GERMAN)){
        currentLanguage = ENGLISH;
      }else{
        currentLanguage = GERMAN;
      }
      FacesContext.getCurrentInstance().getViewRoot().setLocale(currentLanguage.getLocale());
  }

}

And this is the response header after clicking the link which seems to be missing the language :/
enter image description here

Basti
  • 1,117
  • 12
  • 32
  • i don't know primefaces, but isn't onclick a javascript-handler? you have to call sth. like : i guess – Steve Jan 22 '18 at 14:35
  • @Steve Thanks for the hint. I will look into that, but it still doesn't explain why it loads the language.properties by default instead of the language_de.properties. Since i got the default-locale in the faces-config set to de thats what it should do no? – Basti Jan 22 '18 at 14:43
  • @Steve so the commandLink solved the problem. But i have a bunch of buttons which redirect to other .xhtml pages and those turn back into english then, forcing me to set the language again. Why is that? Do i have to send the language with every single redirect? – Basti Jan 22 '18 at 15:05
  • the second link of balusc exactly answers your question. – Steve Jan 22 '18 at 15:20

0 Answers0