2016-12-27 127 views
0

我有西班牙语语言包的窗口(本机在我的情况下),国际化工作完美的所有页面,但不适用于其他机器,他们有英语包语言为本地。我将我的语言包更改为英文,并且实际上国际化无效,只有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> 
+0

是我对你的答案有帮助? –

回答

0

国际工程对浏览器的水平,而不是OS级别。因此,您应该在您使用的浏览器中更改语言。只是为了测试目的,你也可以尝试,如果国际化的工作方式切换语言环境等langauage:

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

无论如何改变的langauge在浏览器应该是足够

+0

感谢您的回答,但我已经尝试了您的建议;我知道问题不是操作系统语言;我改用语言环境,但为什么国际化与操作系统语言一起使用是西班牙语而不是英语。我不知道问题是否与其他语言一样。 –