PageSourceSearch

https://thecodingcolosseum.com/Scripts/Locale.js?v=2.8.0.4

js thecodingcolosseum.com collected 2026-10-03 21:19:28 UTC 4,704 bytes, 109 lines download raw bytes

1const Locale = (function () {
2    let localeData = {};
3    let loadedLocale = "en";
4    let translatorMode = false;
5    let missingTranslations = {};
6    let obj = {
7        MonthsOfYear: ["Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"],
8        DaysOfWeek: ["Mon", "Tue", "Wed", "Thurs", "Fri", "Sat", "Sun"],
9        LongDaysOfWeek: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
10        AvailableLocales: ["en"],
11        LoadLocale: async function (iso) {
12            let data = await (await fetch(`/Locale/${iso}.json`)).json();
13            loadedLocale = data.LocaleName;
14            localeData = data.Strings;
15            this.MonthsOfYear = data.MonthsOfYear || this.MonthsOfYear;
16            this.DaysOfWeek = data.DaysOfWeek || this.DaysOfWeek;
17            this.LongDaysOfWeek = data.LongDaysOfWeek || this.LongDaysOfWeek;
18        },
19        GetLocaleMessage: function (original) {
20            if (translatorMode && !(original in missingTranslations)) {
21                missingTranslations[original] = "";
22                localeData[original] = original;
23                console.log(`Missing translation for '${original}'`);
24            }
25            return localeData[original] || original;
26        },
27        SetTranslatorMode: function (value) {
28            translatorMode = value;
29            this.ApplyLocale();
30            console.log(`Translator mode ${value ? "enabled" : "disabled"}.`)
31        },
32        ApplyLocale: function (context) {
33            $((context || "body") + " *")
34                .contents()
35                .filter((_, e) => e.nodeType === Node.TEXT_NODE && e.textContent.match(/[a-zA-Z]\w/) && !e.textContent.contains("<!-- ko"))
36                .each(function (_, e) {
37                    e.textContent = e.textContent.replace(/^(\s*)([a-zA-Z ].+?)(\s*)$/, (match, p1, p2, p3) => `${p1}${obj.GetLocaleMessage(p2)}${p3}`);
38                });
39        },
40        ListLocale: function (context) {
41            let messages = {};
42            $((context || "body") + " *")
43                .contents()
44                .filter((_, e) => e.nodeType === Node.TEXT_NODE && e.textContent.match(/[a-zA-Z]\w/) && !e.textContent.contains("<!-- ko"))
45                .each(function (_, e) {
46                    e.textContent = e.textContent.replace(/^(\s*)([a-zA-Z ].+?)(\s*)$/, function (match, p1, p2, p3) {
47                        messages[p2] = p2;
48                        return `${p1}${p2}${p3}`
49                    });
50                });
51            console.log(JSON.stringify(messages, null, 4));
52        },
53        DownloadJSONFile: function () {
54            const output = {
55                MonthsOfYear: this.MonthsOfYear,
56                DaysOfWeek: this.DaysOfWeek,
57                LongDaysOfWeeek: this.LongDaysOfWeek,
58                LocaleName: loadedLocale,
59                Strings: localeData,
60            };
61            const jsonData = JSON.stringify(output);
62            const blob = new Blob([jsonData], {
63                type: 'application/json'
64            });
65            saveAs(blob, loadedLocale + ".json");
66        },
67        DownloadPOTFile: function () {
68            let lines = [];
69            for (const key of Object.keys(missingTranslations)) {
70                lines.push(`msgid "${key}"`, `msgstr ""`);
71            }
72            const output = lines.join("\n");
73            const blob = new Blob([output], {
74                type: 'text/plain'
75            });
76            saveAs(blob, "amp.pot");
77        },
78        SwitchLocale: async function (iso) {
79            if (iso == loadedLocale) { return; }
80            /* If the already loaded locale is not English then we need to reload
81             * the page and apply the locale after reload. */
82            else if (loadedLocale != "en") {
83                localStorage.AMPLocale = iso == "en" ? "" : iso;
84                location.reload();
85                return;
86            }
87            localStorage.AMPLocale = iso;
88            await obj.LoadLocale(iso);
89            obj.ApplyLocale();
90        }, 
91        AutoLoadLocale: async function (override) {
92            if (override == "en") {
93                localStorage.AMPLocale = "";
94                return;
95            }
96
97            if (override != null) {
98                await this.SwitchLocale(override);
99            }
100            else if ("AMPLocale" in localStorage && localStorage.AMPLocale != "") {
101                await this.SwitchLocale(localStorage.AMPLocale);
102            }
103        },
104    };
105
106    obj.l = obj.GetLocaleMessage;
107
108    return obj;
vendor: 5 bytes, line 109
109})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.