1
0

langs.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const supportLangs = [
  2. {
  3. name: "English",
  4. value: "en-US",
  5. icon: "🇺🇸",
  6. },
  7. {
  8. name: "فارسی",
  9. value: "fa-IR",
  10. icon: "🇮🇷",
  11. },
  12. {
  13. name: "简体中文",
  14. value: "zh-CN",
  15. icon: "🇨🇳",
  16. },
  17. {
  18. name: "繁體中文",
  19. value: "zh-TW",
  20. icon: "🇹🇼",
  21. },
  22. {
  23. name: "日本語",
  24. value: "ja-JP",
  25. icon: "🇯🇵",
  26. },
  27. {
  28. name: "Русский",
  29. value: "ru-RU",
  30. icon: "🇷🇺",
  31. },
  32. {
  33. name: "Tiếng Việt",
  34. value: "vi-VN",
  35. icon: "🇻🇳",
  36. },
  37. {
  38. name: "Español",
  39. value: "es-ES",
  40. icon: "🇪🇸",
  41. },
  42. {
  43. name: "Indonesian",
  44. value: "id-ID",
  45. icon: "🇮🇩",
  46. },
  47. {
  48. name: "Український",
  49. value: "uk-UA",
  50. icon: "🇺🇦",
  51. },
  52. {
  53. name: "Türkçe",
  54. value: "tr-TR",
  55. icon: "🇹🇷",
  56. },
  57. {
  58. name: "Português",
  59. value: "pt-BR",
  60. icon: "🇧🇷",
  61. },
  62. ];
  63. function getLang() {
  64. let lang = getCookie("lang");
  65. if (!lang) {
  66. if (window.navigator) {
  67. lang = window.navigator.language || window.navigator.userLanguage;
  68. if (isSupportLang(lang)) {
  69. setCookie("lang", lang, 150);
  70. } else {
  71. setCookie("lang", "en-US", 150);
  72. window.location.reload();
  73. }
  74. } else {
  75. setCookie("lang", "en-US", 150);
  76. window.location.reload();
  77. }
  78. }
  79. return lang;
  80. }
  81. function setLang(lang) {
  82. if (!isSupportLang(lang)) {
  83. lang = "en-US";
  84. }
  85. setCookie("lang", lang, 150);
  86. window.location.reload();
  87. }
  88. function isSupportLang(lang) {
  89. for (l of supportLangs) {
  90. if (l.value === lang) {
  91. return true;
  92. }
  93. }
  94. return false;
  95. }