我试图在我的网站,德语和英语中加入翻译。可悲的是,我似乎是愚蠢做正确的事情,无法发现问题。有人能告诉我为什么我的语言不会加载吗?它总是坚持使用默认的language.properties文件,不会更改为language_de / language_en
这是我的 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>
<p:link id="buttonHeader_languageLink">
<p:graphicImage id="buttonHeader_languageIcon"
value="#{languageBean.currentLanguage.graphicPath}"
onclick="#{languageBean.changeLanguage()}"></p:graphicImage>
</p:link>
和我的 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());
}
}