Posted By

itreptil on 12/30/10


Tagged

localization


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

darkhawk
Fogh
geldora
virendrakryadav


Localize user language


 / Published in: jQuery
 

URL: http://www.itreptil.at

this snippet allows you to receive the browser default language (IE & other).

  • change content based on the lang
  • German
  • Russian
  • English
  • Japanese
  • and default

have fun http://itreptil.at

  1. (function($){
  2. //
  3. // DIV must be style="display:none;"
  4. //
  5. $.fn.chk_userlanguage = function() {
  6. /* check if <style=display:none;> not set to that element */
  7. if (!this.is(":hidden")) { this.hide(); };
  8.  
  9. /* get browser default lang */
  10. if (navigator.userLanguage) {
  11. baseLang = navigator.userLanguage.substring(0,2).toLowerCase();
  12. } else {
  13. baseLang = navigator.language.substring(0,2).toLowerCase();
  14. }
  15.  
  16. /* language match */
  17. switch(baseLang)
  18. {
  19. case "de":
  20. /* german */
  21. this.slideDown("slow");
  22. break;
  23. case "en":
  24. /* english */
  25. break;
  26. case "ja":
  27. /* japanese */
  28. break;
  29. case "ru":
  30. /* russian */
  31. break;
  32. default:
  33. /* default no match */
  34. }
  35. };
  36. })(jQuery);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Marfa on November 1, 2012

Hi. How can I run a java script using your snippet? I need to run script for non-russian users.

You need to login to post a comment.