Reply To: Yet another I18N approach

Splash Forums PrettyFaces Users Yet another I18N approach Reply To: Yet another I18N approach

#26178

zozan
Participant

Thanks for your answers @lincoln 🙂
Here is my configuration file:

public class TeshtRewriteConfigurationProvider extends HttpConfigurationProvider{                                 
    
    @Inject
    LocaleBean localeBean;   
    
    private Cookie getCookie(HttpServletRequest request, String name){
        if(request.getCookies() != null){
            for(Cookie cookie:request.getCookies()){
                if(cookie.getName().equalsIgnoreCase(name)){
                    return cookie;
                }
            }            
        }
        return null;
    }    

   @Override
   public Configuration getConfiguration(final ServletContext context)
   {              
     return ConfigurationBuilder.begin()                          
             
             
            .addRule()             
            .when(Path.matches("/"))
             .perform(new HttpOperation(){
                @Override
                public void performHttp(HttpServletRewrite event, EvaluationContext context){
                    HttpServletRequest request =   (HttpServletRequest) event.getRequest();                      
                    if (request !=null){
                        Cookie langCookie = getCookie(request, "language");                        
                        if(langCookie != null){                                   
                                Redirect.temporary(event.getContextPath() + "/"+ langCookie.getValue() + "/Home").perform(event, context);                             
                            }else{                                   
                                Redirect.temporary(event.getContextPath() + "/Select_Language").perform(event, context);
                            }                    
                        }else{                                 
                            Redirect.temporary(event.getContextPath() + "/Select_Language").perform(event, context);
                    }
                }
             })
             
             .addRule(Join.path("/{lang}/{path}").to("/{path}.xhtml"))
             .where("path").configuredBy(LocaleTransposition.bundle("com.tesht.bundles.text", "lang"))
//             .where("lang").bindsTo(PhaseBinding.to(El.property(localeBean.getLanguage())))
             

//             .addRule()
//             .when(Path.matches("/{lang}/{path}").withRequestBinding())
//             .perform(Forward.to("/{path}.xhtml"))      
//             .where("path").configuredBy(LocaleTransposition.bundle("com.tesht.bundles.text", "lang"))                            
             
             .addRule(Join.path("/Select_Language")
             .to("/Select_Language.xhtml")
             .withInboundCorrection())
                          
             .addRule(Join.path("/Login")
             .to("/Login.xhtml")
             .withInboundCorrection())                                        
     
             .addRule(Join.path("/admin/home")
             .to("/admin/index.xhtml")
             .withInboundCorrection());          
   }    
   @Override
   public int priority()
   {
     return 10;
   }
    
}