CH-J Toolsspráva serverů přes SSH
Menu
Vydané zdroje

CH-J Tools

Procházejte adresáře a soubory konkrétního vydání aplikace.

Stáhnout zdroje ZIP
CH-J / Server Manager 872 souborů
core-20261030T220507Z-61e4558d889f Přidáno: · Sestaveno:
i18n.js Přidáno: Datum není evidováno 3,3 KB · 58 řádků
Kód Stáhnout soubor
1"use strict";
3(function (root) {
4 // Translations are data files (ui/i18n/<language>.json); adding a language means adding a file.
5 // The Core injects the catalogs into the window before the page runs; Node tests read the files.
6 const catalogs = (function loadCatalogs() {
7 const injected = globalThis.__CHJ_I18N__ && globalThis.__CHJ_I18N__.catalogs && globalThis.__CHJ_I18N__.catalogs.module;
8 if (injected) return injected;
9 if (typeof require === "function" && typeof __dirname === "string") {
10 const fs = require("fs"), path = require("path"), dir = path.join(__dirname, "i18n"), result = {};
11 for (const file of fs.readdirSync(dir)) if (/^[a-z]{2,3}(-[A-Za-z0-9]+)?\.json$/.test(file)) result[file.slice(0, -5)] = JSON.parse(fs.readFileSync(path.join(dir, file), "utf8"));
12 return result;
13 }
14 return {};
15 })();
16 // Language list (native names, locales, text direction) injected by the Core.
17 const languageEntry = (code) => (globalThis.__CHJ_I18N__?.manifest?.languages || []).find((entry) => entry.code === code);
18 function createI18n(initialLanguage = "en") {
19 let language;
20 const setLanguage = (value) => {
21 // Exact code first (zh-tw), then the base language (de-at → de).
22 const full = String(value || "").toLowerCase().replace(/_/g, "-");
23 const requested = Object.hasOwn(catalogs, full) ? full : full.split("-")[0];
24 language = Object.hasOwn(catalogs, requested) ? requested : "en";
25 return language;
26 };
27 setLanguage(initialLanguage);
28 const t = (key, values = {}) => (catalogs[language][key] || catalogs.en[key] || key)
29 .replace(/\{(\w+)\}/g, (match, name) => Object.hasOwn(values, name) ? String(values[name]) : match);
30 const staticText = new WeakMap();
31 let applied = false;
32 const apply = (document) => {
33 document.documentElement.lang = language;
34 document.documentElement.dir = languageEntry(language)?.dir === "rtl" ? "rtl" : "ltr";
35 // Text a module has set itself (a version, a count, server data) is not the static translation.
36 document.querySelectorAll("[data-i18n]").forEach((element) => {
37 if (staticText.has(element) && element.textContent !== staticText.get(element)) return;
38 const text = t(element.dataset.i18n);
39 element.textContent = text;
40 staticText.set(element, text);
41 });
42 // A status message from before the switch is in the old language.
43 const status = applied ? document.getElementById("status") : null;
44 if (status) { status.textContent = ""; status.classList.remove("error"); }
45 applied = true;
46 document.querySelectorAll("[data-i18n-aria-label]").forEach((element) => { element.setAttribute("aria-label", t(element.dataset.i18nAriaLabel)); });
47 };
48 const errorMessage = (error) => {
49 const message = error?.message || String(error || t("Unknown error"));
50 const code = error?.code || message.match(/\b(HASH_[A-Z_]+|ENOENT|EACCES|EPERM)\b/)?.[1];
51 return language !== "en" && catalogs[language][code] ? t(code) : message;
52 };
53 return { t, apply, setLanguage, getLanguage: () => language, errorMessage };
54 }
55 const exported = { catalogs, createI18n };
56 if (typeof module === "object" && module.exports) module.exports = exported;
57 else root.chjHashI18n = exported;
58})(typeof window === "object" ? window : globalThis);
SHA-25629f4946dfc66110b5c7bcdbf8596d1fb2024f48f04dbd1dd547a8758988d65e8

CH-J Proprietary Software License 1.14 · Zdroje jsou zveřejněny pod CH-J Proprietary Software License 1.14. Jejich dostupnost nemění licenční podmínky ani neposkytuje další oprávnění.

SHA-256 archivu77380d4805485ffa4027fbe7858b5836f197a4aa9d52358a43e2d12d018744df
Soubory