language.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. var sz = ["en", "zh", "ot"]
  2. var szname = ["English", "Chinese", "Other"]
  3. $(function() {
  4. var default_value = "en";
  5. var value = window.localStorage.getItem("i18n_default_value");
  6. if (value) {
  7. default_value = value;
  8. }
  9. loadProperties(default_value);
  10. })
  11. function loadProperties(val) {
  12. $("#languagelist").empty()
  13. window.localStorage.setItem("i18n_default_value", val);
  14. for (var i in sz) {
  15. if (sz[i] == val) {
  16. $("#language_show").text(szname[i])
  17. } else {
  18. //languagelist
  19. var item = $('<li txt="' + sz[i] + '"><a href="#" txt="' + sz[i] + '" >' + szname[i] +
  20. '</a></li>')
  21. item.on("click", function() {
  22. loadProperties($(this).attr('txt'));
  23. })
  24. $("#languagelist").append(item);
  25. }
  26. }
  27. jQuery.i18n.properties({ //加载资浏览器语言对应的资源文件
  28. name: 'strings', //资源文件名称
  29. path: '/lanhu-bootstrap/i18n/', //资源文件路径
  30. mode: 'map', //用Map的方式使用资源文件中的值
  31. language: val, // - 不支持 ,支持_
  32. callback: function() { //加载成功后设置显示内容
  33. $('.i18n-text').each(function() {
  34. var prop = $(this).attr('i18n')
  35. var value = $.i18n.prop(prop)
  36. $(this).text(value);
  37. });
  38. $('.i18n-input').each(function() {
  39. var prop = $(this).attr('i18n')
  40. var value = $.i18n.prop(prop)
  41. $(this).val(value);
  42. });
  43. $('.i18n-placeholder').each(function() {
  44. var prop = $(this).attr('i18n')
  45. var value = $.i18n.prop(prop)
  46. $(this).attr('placeholder',value);
  47. });
  48. }
  49. });
  50. }
  51. function relanguage(){
  52. var value = window.localStorage.getItem("i18n_default_value");
  53. loadProperties(value);
  54. }