java - MessageResources weird behaviour -
I have a web application for multilingual purpose I use Java Straps 1.3 from - Message processing - & gt; & Lt; Message-processing parameter = "message processing" /> In my SetDefaultLanguage.java : Setting the browser language as "Italian" always prints the case: this - but it's strange behavior here: My index, registration or password pages can be found < / P Other information: Thank you The reason for this is that you use the Java sets the default locale for this example of a virtual machine. Typically, to change a location, setting the session attribute MessageResources I am The default language is
Italian (
MessageResources.properties ) and the second language is
English (
MessageResources_en.properties ).
struts-config.xml :
index.jsp :
& lt;% string language = request.getLocale (). GetLanguage (); & Gt%; Var lang = '& lt;% = language% & gt;'; & Lt; Script type = "text / javascript" src = "js / language.js" & gt; & Lt; / Script & gt; In
js / language.js :
$ (document) .ready (function () {var browser = null; Var val = navigator.userAgent.toLowerCase (); if (val.indexOf ("firefox")> gt; -1) browser = 'firefox'; and if (val.indexOf ("msie")> gt; -1) Browser = 'IE'; else if (val.indexOf ("chrome") gt; -1) browser = 'chrome'; $ .ajax ({url: "set default language.", Data: "isolingua =" + lang + "& Browser =" + browser + "& val =" + val, success: function (response) {}});});
// parametro del browser = (request.getParameter ("isolingua") =! Zero ) {Isolingua = request.getParameter ("Icing"); Switch (isolingua) {case "en": request.getSession (). SetAttribute ("Language", 2); Locale.setDefault (Locale.ENGLISH); Request.getSession () SetAttribute (Globals.LOCALE_KEY, Locale.ENGLISH); System.out.println ("Case N:" + LocalGet Default () + "-" + request.getSession (). GetAttribute (Globals.LoKele_KEE)); break; "This" case: request.getSession (). SetAttribute ("language", 1); Locale.setDefault (Locale.ITALIAN); Request.getSession () SetAttribute (Globals.LOCALE_KEY, Locale, Italian); System.out.println ("Case IT:" + local.get default () + "+" request. Get session (). GetAttribute (globals.locale_keyi)); break; Default: request.getSession (). SetAttribute ("language", 1); Locale.setDefault (Locale.ITALIAN); Request.getSession () SetAttribute (Globals.LOCALE_KEY, Locale, Italian); System.out.println ("case default:" + local.get default () + "-" + request.getSession (). GetAttribute (globals.logge_keae)); break; }}
request.getSession (). SetAttribute ("lingua",
Locale.setDefault () what the doctor says:
...
Since changing the default locale may affect many different areas of functionality, this method should be used only when the caller is using locale-sensitive code running within a single Java virtual machine Ready to start again Globals.LOCALE_KEY and you can use the code to save the locale
// Extract Features We will need HTTP session session = request.getSession (); // Get the location from the request, if a local locale = request.getLocale (); // If supplied, set the locale based on request parameter string language = request.getParameter ("isolingua"); If (language! = Null & amp; languages. Langhe ()> gt; {switch (language) {case "en": locale = locale.ENGLISH; Session.setAttribute ("Lingua", 2); break; Default: Locale = Locale. Italian; Session.setAttribute ("Lingua", 1); break; }} // save local session.SetAttribute (Globals.LOCALE_KEY, Locale);
Comments
Post a Comment