新手:帮助使用 mod_rewrite 进行本地化网站
新手:帮助使用 JSF 切换语言环境
嗨,我希望有人可以提供帮助,我在语言环境之间切换时遇到问题,特别是在我的网站的 en_GB 到 en_US 和 en_US 到 en_GB 之间,但是所有其他两个字符语言环境都切换得很好。
faces_config.xml 片段
<default-locale>en_gb</default-locale>
<supported-locale>en_us</supported-locale>
<supported-locale>en_gb</supported-locale>
<supported-locale>cy</supported-locale>
<supported-locale>es</supported-locale>
<supported-locale>fr</supported-locale>
网页片段
<f:view locale="#{localeBean.locale}">
<h:body>
<h:form>
<h:selectOneMenu value="#{localeBean.language}" onchange="submit()">
<f:selectItem itemValue="en_GB" itemLabel="English (British)" />
<f:selectItem itemValue="en_US" itemLabel="English (American)" />
<f:selectItem itemValue="cy" itemLabel="Cymraeg (British)" />
<f:selectItem itemValue="es" itemLabel="Español (España)" />
<f:selectItem itemValue="fr" itemLabel="Français (France)" />
</h:selectOneMenu>
</h:form>
</h:body
</f:view>
Java bean
public class LocaleBean {
private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
public Locale getLocale() {
return locale;
}
public String getLanguage() {
return locale.getLanguage();
}
public void setLanguage(String language) {
if ( language.equals("en_GB") ) {
locale = new Locale("en","GB");
}
else if ( language.equals("en_US") ) {
locale = new Locale("en","US");
}
else {
locale = new Locale(language);
}
FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
}
}
我的问题是,当我将语言环境更改为 en_US 或 en_GB 时,selectItem 默认为 en_GB itemLablel,因此除非我先选择 fr、es 或 cy,否则我无法选择 en_US 或 en_GB 语言环境。
任何帮助表示赞赏
Newbie: help switching locale with JSF
Hi, I hope someone can help, I am having problems switching between locales in particular en_GB to en_US and en_US to en_GB for my website, however all other two character locales are switching fine.
faces_config.xml snippet
<default-locale>en_gb</default-locale>
<supported-locale>en_us</supported-locale>
<supported-locale>en_gb</supported-locale>
<supported-locale>cy</supported-locale>
<supported-locale>es</supported-locale>
<supported-locale>fr</supported-locale>
web page snippet
<f:view locale="#{localeBean.locale}">
<h:body>
<h:form>
<h:selectOneMenu value="#{localeBean.language}" onchange="submit()">
<f:selectItem itemValue="en_GB" itemLabel="English (British)" />
<f:selectItem itemValue="en_US" itemLabel="English (American)" />
<f:selectItem itemValue="cy" itemLabel="Cymraeg (British)" />
<f:selectItem itemValue="es" itemLabel="Español (España)" />
<f:selectItem itemValue="fr" itemLabel="Français (France)" />
</h:selectOneMenu>
</h:form>
</h:body
</f:view>
Java bean
public class LocaleBean {
private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
public Locale getLocale() {
return locale;
}
public String getLanguage() {
return locale.getLanguage();
}
public void setLanguage(String language) {
if ( language.equals("en_GB") ) {
locale = new Locale("en","GB");
}
else if ( language.equals("en_US") ) {
locale = new Locale("en","US");
}
else {
locale = new Locale(language);
}
FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
}
}
My problem is when I change the locale to en_US or en_GB the selectItem defaults to en_GB itemLablel, so unless I select either fr, es or cy first I am unable to select either en_US or en_GB locales.
Any help appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况的原因应该很明显:
这将始终仅返回语言代码。但您的英文标识符分别是“en_GB”和“en_US”,因此它始终选择第一个项。
我相信现在解决办法是显而易见的,不是吗?我建议的修改是:
也就是说,除非您在其他地方仅使用语言代码......
The reason why it happens should be obvious:
This will always return language-code only. But your English identifiers are "en_GB" and "en_US" respectively, so it always selects first item.
I believe now, the fix is obvious, isn't it? The modification I recommend is:
That is, unless you are using just the language code somewhere else...