Localize user language


/ Published in: jQuery
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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);

URL: http://www.itreptil.at

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.