CH-J Toolsمدیریت سرور از طریق SSH
منو
منبع منتشرشده

CH-J Tools

پوشه‌ها و فایل‌های یک نسخهٔ مشخص از برنامه را مرور کنید.

دانلود ZIP منبع
CH-J / Server Manager 1704 فایل
0.1.2-beta افزوده‌شده: · ساخته‌شده:
i18n.js افزوده‌شده: تاریخ ثبت نشده است ۳٫۴ KB · 58 خط
کد دانلود فایل
1"use strict";
3// CS/DE/EN texts of chj.log-viewer. Keys are the original Czech texts; values are inserted as plain text, never as HTML.
4(function (root) {
5 // Translations are data files (ui/i18n/<language>.json); adding a language means adding a file.
6 // The Core injects the catalogs into the window before the page runs; Node tests read the files.
7 const catalogs = (function loadCatalogs() {
8 const injected = globalThis.__CHJ_I18N__ && globalThis.__CHJ_I18N__.catalogs && globalThis.__CHJ_I18N__.catalogs.module;
9 if (injected) return injected;
10 if (typeof require === "function" && typeof __dirname === "string") {
11 const fs = require("fs"), path = require("path"), dir = path.join(__dirname, "i18n"), result = {};
12 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"));
13 return result;
14 }
15 return {};
16 })();
17 // Language list (native names, locales, text direction) injected by the Core.
18 const languageEntry = (code) => (globalThis.__CHJ_I18N__?.manifest?.languages || []).find((entry) => entry.code === code);
19 function createI18n(initialLanguage = "cs") {
20 let language;
21 const setLanguage = (value) => {
22 // Exact code first (zh-tw), then the base language (de-at ← de).
23 const full = String(value || "").toLowerCase().replace(/_/g, "-");
24 const requested = Object.hasOwn(catalogs, full) ? full : full.split("-")[0];
25 language = requested === "cs" || Object.hasOwn(catalogs, requested) ? requested : "en";
26 return language;
27 };
28 setLanguage(initialLanguage);
29 const t = (key, values = {}) => String(language === "cs" ? key : catalogs[language][key] || catalogs.en[key] || key)
30 .replace(/\{(\w+)\}/g, (match, name) => Object.hasOwn(values, name) ? String(values[name]) : match);
31 const staticText = new WeakMap();
32 let applied = false;
33 const apply = (document) => {
34 document.documentElement.lang = language;
35 document.documentElement.dir = languageEntry(language)?.dir === "rtl" ? "rtl" : "ltr";
36 // Text a module has set itself (a version, a count, server data) is not the static translation.
37 document.querySelectorAll("[data-i18n]").forEach((element) => {
38 if (staticText.has(element) && element.textContent !== staticText.get(element)) return;
39 const text = t(element.dataset.i18n);
40 element.textContent = text;
41 staticText.set(element, text);
42 });
43 // A status message from before the switch is in the old language.
44 const status = applied ? document.getElementById("status") : null;
45 if (status) { status.textContent = ""; status.classList.remove("error"); }
46 applied = true;
47 for (const attribute of ["placeholder", "title", "aria-label"]) {
48 document.querySelectorAll(`[data-i18n-${attribute}]`).forEach((element) => { element.setAttribute(attribute, t(element.getAttribute(`data-i18n-${attribute}`))); });
49 }
50 document.title = t("Log Viewer");
51 };
52 const locale = () => languageEntry(language)?.locale || ({ cs: "cs-CZ", de: "de-DE" }[language] || "en-GB");
53 return { t, apply, setLanguage, getLanguage: () => language, locale };
54 }
55 const exported = { catalogs, createI18n };
56 if (typeof module === "object" && module.exports) module.exports = exported;
57 else root.chjPluginI18n = exported;
58})(typeof window === "object" ? window : globalThis);
SHA-256908047508a4d4745e67f999f6533d778e38e76a9cc67986a095f798b6546cb04

CH-J Proprietary Software License 1.14 · کد منبع تحت CH-J Proprietary Software License 1.14 ارائه می‌شود. در دسترس بودن آن شرایط مجوز را تغییر نمی‌دهد و حق اضافه‌ای اعطا نمی‌کند.

SHA-256 بایگانیac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f
فایل‌ها