当其他语言在Windows上时,国际化不起作用

时间:2016-12-27 20:23:48

标签: html5 jsf weblogic

我有西班牙语语言包的窗口(在我的例子中是原生的),国际化工作在所有页面都很完美,但是在其他机器上没有工作,他们有英语包语言作为本机。我将语言包改为英语,实际上国际化不起作用,只有在bean上设置的默认语言才有效。我只使用两种语言西班牙语和英语

我使用JSF 2,html5。这是我的豆子

@ManagedBean (name= "swtLanguage")
@SessionScoped
public class LanguageSwitcher implements Serializable{

private Locale locale;
private int backgroud=1;    

@PostConstruct
public void init() {
    locale = new Locale("en");
}

public Locale getLocale() {
    return locale;
}

public String getLanguage() {
    return locale.getLanguage();
}

public void setLanguage(String language) {
    locale = new Locale(language);
    FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
}

public int getBackgroud() {
    return backgroud;
}

public void setBackgroud(int backgroud) {
    this.backgroud = backgroud;
}

}

HTML

    <html xmlns="http://www.w3.org/1999/xhtml"     xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://xmlns.jcp.org/jsf/passthrough"
xmlns:c="http://java.sun.com/jsp/jstl/core">
    <f:view locale="#{swtLanguage.locale}">
    <h:head>
    <title>#{aees_msg['loginScreen']}</title>

            <meta name="viewport" content="width=device-width, initial-scale=1">  </meta>
            <h:outputStylesheet library="styleAE" name="boots/css/login.css"/>
            <h:outputStylesheet library="styleAE" name="boots/css/bootstrap.min.css"/>
            <h:outputStylesheet library="styleAE" name="boots/css/bootstrap.css"/>
            <h:outputScript library="styleAE" name="alerts/alertify.js"/>
            <h:outputScript library="styleAE" name="alerts/alertify.min.js"/>
            <h:outputStylesheet library="styleAE" name="alerts/alertify.core.css"/>
            <h:outputStylesheet library="styleAE" name="alerts/alertify.default.css"/>

        </h:head>
        <h:body class="body">

            <div class="wrapper">
                <h:graphicImage library="styleAE" name="img/login/LoginPieces-02.png"  class="img-responsive logo-img2"/>
                <div class="container wrapper-container">
                    <div class="row">
                        <div class="col-xs-12">
                            <h:form id="inputFormXD"  class="login" >
                                <div class="form-group input-group">
                                    <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                    <h:inputText value= "#{Login.usuario}" class="form-control"  p:placeholder="#{gen_msg['user']}" required="true" requiredMessage="#{aees_msg['userRequired']}" id="user">
                                        <f:ajax execute="@this" event="change" listener="#{Login.roles(Login.usuario)}" render="role" />
                                    </h:inputText>
                                </div>
                                <div class="form-group input-group separate">
                                    <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                                    <h:inputSecret value= "#{Login.password}" class="form-control"  p:placeholder="#{gen_msg['pass']}" required="true" requiredMessage="#{aees_msg['passwordRequired']}" id="password"/>
                                </div>
                                <div class="form-group separate" style="display: none">
                                    <h:panelGroup id="role">
                                        <h:outputLabel >Rol:</h:outputLabel>
                                        <h:selectOneMenu  value="#{Login.role}"  id="roles" class="form-control" >
                                            <f:selectItems  value="#{Login.listarole}" var="option" itemLabel="#{option.roleDesc}" itemValue="#{option.sgrRolePK.roleCode}"/> 
                                        </h:selectOneMenu>
                                    </h:panelGroup>
                                </div>

                                <div class="form-group separate">
                                    <h:outputLabel id="language">#{gen_msg['language']}:</h:outputLabel>
                                    <h:selectOneMenu  value="#{swtLanguage.language}" class="form-control" >
                                        <f:selectItem itemValue="en" itemLabel="English" />  
                                        <f:selectItem itemValue="es" itemLabel="Español" />                                                                                                                 
                                        <f:ajax execute="@this" render="@form psw usn language lo" />
                                    </h:selectOneMenu>

                                </div>
                                <div class="buttom separate">
                                    <h:commandButton class="btn-login btn  btn-primary" value="#{aees_msg['login']}" action="#{Login.usersValidator}" id="lo"/>
                                </div>
                                <div class="form-group separate">
                                    <label>
                                        <a href="#" style="font-style: normal" class="bstrong" onclick="mailto();">#{gen_msg['ProblCuenta']} ></a>
                                    </label><br></br>

                                    <label>
                                        <a href="#" style="font-style: normal" class="bstrong">#{gen_msg['politPriv']} > </a>
                                    </label>
                                </div>

                            </h:form>

                            <c:if test="${Login.error == 1}">
                                <h:outputScript rendered="#{facesContext.postback and not facesContext.validationFailed}">;
                                    alertify.error("Usuario o Password Incorrectos");
                                </h:outputScript>
                            </c:if>
                            <c:if test="${Login.error == 2}">
                                <h:outputScript rendered="#{facesContext.postback and not facesContext.validationFailed}">;
                                    alertify.error("Usuario sin privilegios");
                                </h:outputScript>
                            </c:if>

                        </div>
                    </div>
                </div>
            </div>



        </h:body>
    </f:view>
</html>

面-配置

<faces-config version="2.1"
              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_1.xsd">
<application>
   <locale-config>
      <default-locale>es</default-locale>
      <supported-locale>es</supported-locale>
      <supported-locale>en</supported-locale>
   </locale-config>
   <resource-bundle>
        <base-name>com.internationalization.aeesmessages</base-name>
        <var>aees_msg</var>
    </resource-bundle>
    <resource-bundle>
        <base-name>com.internationalization.genmessages</base-name>
        <var>gen_msg</var>
    </resource-bundle>
    <resource-bundle>
        <base-name>com.internationalization.menumessages</base-name>
        <var>menu_msg</var>
    </resource-bundle>
</application>
</faces-config>

1 个答案:

答案 0 :(得分:0)

国际化适用于浏览器级别,而不适用于操作系统级别。因此,您应该在您使用的浏览器中更改语言。仅出于测试目的,如果国际化通过将语言环境切换到其他语言来实现,则可以尝试:

UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
viewRoot.setLocale(new Locale("en"));

无论如何,在浏览器中更改语言应该足够了