Thanks! it's very well to know how translating JS. But at least by now
I'm not going to play with JS localization. I'm very busy with a
project.


On 29 mayo, 16:38, fidoogle <[EMAIL PROTECTED]> wrote:
> If you are interested in doing the translation on the client-side,
> here is how I have done it before.
> In your HTML, show both languages but wrap them with slightly
> different tags. I used the i tag with a different class, es for
> espanol and en for english:
>
> <html>
> <body>
> <i class="en"><a href="javascript:translate('es');">En Espa&ntilde;ol</
> a></i>
> <i class="es"><a href="javascript:translate('en');">In English</a></i>
> <br>
> <i class="en">This is in English</i><i class="es">Esto esta en
> espa&ntilde;ol</i>
> </body>
> </html>
>
> When the link is clicked the language is automatically switched. The
> code that does the translating searches for all the tags of "i" with
> classname of "en" or "es" and hides or shows them. I also use cookies
> to store the last chosen language so that the next page the user
> visits will remain in the same language when the page loads. Notice
> also that I define a function called translateParts on any page that
> needs some extra stuff translated, such as selectlists. I provide an
> example of a translateParts function that would be contained on a page
> with a selectlist.
>
> function translate(pLanguage) {
>         var language;
>         if (pLanguage)  language = pLanguage;
>         else if (getCookie("language")=="es")  language = "es";
>         else language = "en";
>
>         var iTags = document.getElementsByTagName("i");
>         var i;
>         if (language=="es") {
>                 for (i=0; i<iTags.length; i++) {
>                         if (iTags[i].className=="es") iTags[i].style.display 
> = "";
>                         if (iTags[i].className=="en") iTags[i].style.display 
> = "none";
>                 }
>         } else {
>                 for (i=0; i<iTags.length; i++) {
>                         if (iTags[i].className=="es") iTags[i].style.display 
> = "none";
>                         if (iTags[i].className=="en") iTags[i].style.display 
> = "";
>                 }
>         }
>
>         setCookie("language", language, "/");
>         try { translateParts(language); //defined in individual pages,
> otherwise do nothing.
>         } catch(e) { }
>
> }
>
> function setCookie(name, value, path, expires, domain, secure) {
>   deleteCookie(name,path);
>   var curCookie = name + "=" + escape(value) +
>       ((expires) ? "; expires=" + expires.toGMTString() : "") +
>       ((path) ? "; path=" + path : "") +
>       ((domain) ? "; domain=" + domain : "") +
>       ((secure) ? "; secure" : "");
>   document.cookie = curCookie;}
>
> function getCookie(name) {
>   var dc = document.cookie;
>   var prefix = name + "=";
>   var begin = dc.indexOf("; " + prefix);
>   if (begin == -1) {
>     begin = dc.indexOf(prefix);
>     if (begin != 0) return null;
>   } else
>     begin += 2;
>   var end = document.cookie.indexOf(";", begin);
>   if (end == -1)
>     end = dc.length;
>   return unescape(dc.substring(begin + prefix.length, end));
>
> }
>
> This function would be contained in a separate page with a select list
> having an id=payeeId
> function translateParts() {
>         var language = getCookie('language');
>         var dropList = document.getElementById('payeeId');
>         if (dropList) {
>                 if (language=='es') dropList.options[0].text = 'Elija 
> Beneficiario';
>                 else dropList.options[0].text = 'Select Payee';
>         }
>
> }
>
> If this is an approach you would like to explore further, I would be
> happy to provide more details. I also have a jQuery version which cuts
> down on the lines of code.
>
> Good luck to you!
--~--~---------~--~----~------------~-------~--~----~
Insoshi developer site: http://dogfood.insoshi.com/
Insoshi documentation: http://docs.insoshi.com/

You received this message because you are subscribed to the Google
Groups "Insoshi" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/insoshi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to