Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShishkevich D. <135337715+shishkevichd@users.noreply.github.com>2025-03-08 05:54:41 +0300
committerGitHub <noreply@github.com>2025-03-08 05:54:41 +0300
commit6658f648e696712d5bca3083d613203fbb5ff2df (patch)
tree228017738e6dccc406c3592f114e3a7d8ffbc871 /web/assets/js/util
parentd6f9f3f6d3747b049de52be2e68cb9a850343307 (diff)
refactor: move language manager to utils (#2735)
Diffstat (limited to 'web/assets/js/util')
-rw-r--r--web/assets/js/util/index.js104
1 files changed, 104 insertions, 0 deletions
diff --git a/web/assets/js/util/index.js b/web/assets/js/util/index.js
index 8a6a4703..57a6b95d 100644
--- a/web/assets/js/util/index.js
+++ b/web/assets/js/util/index.js
@@ -669,4 +669,108 @@ class URLBuilder {
return `${protocol}//${host}${port}${base}${path}`;
}
+}
+
+class LanguageManager {
+ static supportedLanguages = [
+ {
+ name: "English",
+ value: "en-US",
+ icon: "🇺🇸",
+ },
+ {
+ name: "فارسی",
+ value: "fa-IR",
+ icon: "🇮🇷",
+ },
+ {
+ name: "简体中文",
+ value: "zh-CN",
+ icon: "🇨🇳",
+ },
+ {
+ name: "繁體中文",
+ value: "zh-TW",
+ icon: "🇹🇼",
+ },
+ {
+ name: "日本語",
+ value: "ja-JP",
+ icon: "🇯🇵",
+ },
+ {
+ name: "Русский",
+ value: "ru-RU",
+ icon: "🇷🇺",
+ },
+ {
+ name: "Tiếng Việt",
+ value: "vi-VN",
+ icon: "🇻🇳",
+ },
+ {
+ name: "Español",
+ value: "es-ES",
+ icon: "🇪🇸",
+ },
+ {
+ name: "Indonesian",
+ value: "id-ID",
+ icon: "🇮🇩",
+ },
+ {
+ name: "Український",
+ value: "uk-UA",
+ icon: "🇺🇦",
+ },
+ {
+ name: "Türkçe",
+ value: "tr-TR",
+ icon: "🇹🇷",
+ },
+ {
+ name: "Português",
+ value: "pt-BR",
+ icon: "🇧🇷",
+ }
+ ]
+
+ static getLanguage() {
+ let lang = CookieManager.getCookie("lang");
+
+ if (!lang) {
+ if (window.navigator) {
+ lang = window.navigator.language || window.navigator.userLanguage;
+
+ if (LanguageManager.isSupportLanguage(lang)) {
+ CookieManager.setCookie("lang", lang, 150);
+ } else {
+ CookieManager.setCookie("lang", "en-US", 150);
+ window.location.reload();
+ }
+ } else {
+ CookieManager.setCookie("lang", "en-US", 150);
+ window.location.reload();
+ }
+ }
+
+ return lang;
+ }
+
+ static setLanguage(language) {
+ if (!LanguageManager.isSupportLanguage(language)) {
+ language = "en-US";
+ }
+
+ CookieManager.setCookie("lang", language, 150);
+ window.location.reload();
+ }
+
+ static isSupportLanguage(language) {
+ const languageFilter = LanguageManager.supportedLanguages.filter((lang) => {
+ return lang.value === language
+ })
+
+ return languageFilter.length > 0;
+ }
} \ No newline at end of file