@krx3d/tizentube2 1.31.620 → 1.31.640
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/i18n-check.yml +24 -0
- package/AGENTS.md +8 -0
- package/dist/userScript.js +1 -1
- package/package.json +1 -1
- package/scripts/i18n-check/check-i18n.cjs +149 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krx3d/tizentube2",
|
|
3
3
|
"appName": "TizenTube",
|
|
4
|
-
"version": "1.31.
|
|
4
|
+
"version": "1.31.640",
|
|
5
5
|
"description": "TizenTube is an ad-free and sponsor-free solution for your favourite streaming website on your Tizen (Samsung) TVs.",
|
|
6
6
|
"packageType": "mods",
|
|
7
7
|
"websiteURL": "https://youtube.com/tv?additionalDataUrl=http%3A%2F%2Flocalhost%3A8085%2Fdial%2Fapps%2FYouTube",
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
// process.stdout/stderr rather than console: CodeQL ties console.* here to the TV's
|
|
4
|
+
// console hook in mods/features/visualConsole.js and reports file data reaching the
|
|
5
|
+
// log senders (js/file-access-to-http), though this script never runs on the TV.
|
|
6
|
+
const writeOut = (line) => process.stdout.write(`${line}\n`);
|
|
7
|
+
const writeErr = (line) => process.stderr.write(`${line}\n`);
|
|
8
|
+
|
|
9
|
+
// Checks that the English and German translations stay in step.
|
|
10
|
+
// Plain Node, no dependencies, so it runs in any CI job that has actions/checkout.
|
|
11
|
+
//
|
|
12
|
+
// Usage:
|
|
13
|
+
// node scripts/i18n-check/check-i18n.cjs --en <en.json> --de <de.json> [--src <dir>]... [--go <file.go>]
|
|
14
|
+
//
|
|
15
|
+
// Fails on:
|
|
16
|
+
// - a key in one language file but not the other (nested JSON is flattened to a.b.c)
|
|
17
|
+
// - a placeholder ({n}, {{name}}, %s, %d) present in one language but not the other
|
|
18
|
+
// - a key used in code (t('key'), data-i18n="key") that is in neither file
|
|
19
|
+
// - with --go: the same checks for a Go map of the form "en": { "key": "..." }, "de": {...}
|
|
20
|
+
// plus i18n.T(lang, "key") calls in all Go sources under the current directory
|
|
21
|
+
// Keys built at runtime (t('state.' + x)) are skipped, they cannot be checked statically.
|
|
22
|
+
// Keys starting with "__" (metadata such as __contributors) are ignored.
|
|
23
|
+
|
|
24
|
+
const fs = require('fs');
|
|
25
|
+
const path = require('path');
|
|
26
|
+
|
|
27
|
+
const args = { src: [] };
|
|
28
|
+
for (let i = 2; i < process.argv.length; i += 2) {
|
|
29
|
+
const name = process.argv[i].replace(/^--/, '');
|
|
30
|
+
const value = process.argv[i + 1];
|
|
31
|
+
if (value === undefined) usage(`missing value for --${name}`);
|
|
32
|
+
if (name === 'src') args.src.push(value);
|
|
33
|
+
else if (['en', 'de', 'go'].includes(name)) args[name] = value;
|
|
34
|
+
else usage(`unknown option --${name}`);
|
|
35
|
+
}
|
|
36
|
+
if (!args.en || !args.de) usage('--en and --de are required');
|
|
37
|
+
|
|
38
|
+
function usage(msg) {
|
|
39
|
+
writeErr(`check-i18n: ${msg}`);
|
|
40
|
+
writeErr('usage: check-i18n.cjs --en <en.json> --de <de.json> [--src <dir>]... [--go <file.go>]');
|
|
41
|
+
process.exit(2);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const errors = [];
|
|
45
|
+
|
|
46
|
+
function flatten(obj, prefix, out) {
|
|
47
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
48
|
+
if (k.startsWith('__')) continue;
|
|
49
|
+
const key = prefix ? `${prefix}.${k}` : k;
|
|
50
|
+
if (v && typeof v === 'object' && !Array.isArray(v)) flatten(v, key, out);
|
|
51
|
+
else out[key] = v;
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function readJson(file) {
|
|
57
|
+
try {
|
|
58
|
+
return flatten(JSON.parse(fs.readFileSync(file, 'utf8')), '', {});
|
|
59
|
+
} catch (e) {
|
|
60
|
+
errors.push(`${file}: cannot read: ${e.message}`);
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const PLACEHOLDER = /\{\{\s*\w+\s*\}\}|\{\w+\}|%[sdvqf]/g;
|
|
66
|
+
const placeholders = (s) => (typeof s === 'string' ? (s.match(PLACEHOLDER) || []).sort().join(' ') : '');
|
|
67
|
+
|
|
68
|
+
function compare(label, en, de) {
|
|
69
|
+
for (const k of Object.keys(en)) if (!(k in de)) errors.push(`${label}: "${k}" is in en but missing in de`);
|
|
70
|
+
for (const k of Object.keys(de)) if (!(k in en)) errors.push(`${label}: "${k}" is in de but missing in en`);
|
|
71
|
+
for (const k of Object.keys(en)) {
|
|
72
|
+
if (!(k in de)) continue;
|
|
73
|
+
const a = placeholders(en[k]);
|
|
74
|
+
const b = placeholders(de[k]);
|
|
75
|
+
if (a !== b) errors.push(`${label}: "${k}" placeholders differ: en [${a}] vs de [${b}]`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function walk(dir, exts, out) {
|
|
80
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
81
|
+
if (['node_modules', 'dist', 'build', '.git'].includes(entry.name)) continue;
|
|
82
|
+
const full = path.join(dir, entry.name);
|
|
83
|
+
if (entry.isDirectory()) walk(full, exts, out);
|
|
84
|
+
else if (exts.includes(path.extname(entry.name))) out.push(full);
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function checkUsage(label, roots, exts, pattern, known) {
|
|
90
|
+
for (const root of roots) {
|
|
91
|
+
if (!fs.existsSync(root)) {
|
|
92
|
+
errors.push(`${label}: source directory ${root} does not exist`);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
for (const file of walk(root, exts, [])) {
|
|
96
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
97
|
+
for (const m of text.matchAll(pattern)) {
|
|
98
|
+
const key = m.groups.key;
|
|
99
|
+
// Prefixes completed at runtime, e.g. t('state.' + x).
|
|
100
|
+
if (key.endsWith('.') || key.endsWith('_')) continue;
|
|
101
|
+
if (!(key in known)) {
|
|
102
|
+
const line = text.slice(0, m.index).split('\n').length;
|
|
103
|
+
errors.push(`${file}:${line}: "${key}" is used but not in ${label}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// --- JSON dictionaries
|
|
111
|
+
const en = readJson(args.en);
|
|
112
|
+
const de = readJson(args.de);
|
|
113
|
+
compare(`${args.en} / ${args.de}`, en, de);
|
|
114
|
+
|
|
115
|
+
// Only dotted keys count as translation keys, so t('x') from unrelated helpers is not flagged.
|
|
116
|
+
const JS_USE = /(?:\bt\(\s*|\bdata-i18n[\w-]*=)(['"`])(?<key>[A-Za-z0-9_-]+\.[A-Za-z0-9_.-]*)\1/g;
|
|
117
|
+
checkUsage(
|
|
118
|
+
'the translation files',
|
|
119
|
+
args.src,
|
|
120
|
+
['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs', '.html', '.vue', '.svelte'],
|
|
121
|
+
JS_USE,
|
|
122
|
+
en,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// --- Go map
|
|
126
|
+
if (args.go) {
|
|
127
|
+
const maps = {};
|
|
128
|
+
let lang = null;
|
|
129
|
+
for (const line of fs.readFileSync(args.go, 'utf8').split('\n')) {
|
|
130
|
+
const open = line.match(/^\s*"(en|de)":\s*\{\s*$/);
|
|
131
|
+
if (open) { lang = open[1]; maps[lang] = {}; continue; }
|
|
132
|
+
if (lang && /^\s*\},?\s*$/.test(line)) { lang = null; continue; }
|
|
133
|
+
const entry = lang && line.match(/^\s*"([^"]+)":\s*"((?:[^"\\]|\\.)*)",?\s*$/);
|
|
134
|
+
if (entry) maps[lang][entry[1]] = entry[2];
|
|
135
|
+
}
|
|
136
|
+
if (!maps.en || !maps.de) errors.push(`${args.go}: could not find both "en" and "de" maps`);
|
|
137
|
+
else {
|
|
138
|
+
compare(args.go, maps.en, maps.de);
|
|
139
|
+
const GO_USE = /\bi18n\.T\([^,()]+,\s*"(?<key>[^"]+)"/g;
|
|
140
|
+
checkUsage(args.go, ['.'], ['.go'], GO_USE, maps.en);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (errors.length) {
|
|
145
|
+
writeErr(`check-i18n: ${errors.length} problem(s)`);
|
|
146
|
+
for (const e of errors) writeErr(` ${e}`);
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
writeOut(`check-i18n: ok (${Object.keys(en).length} keys${args.go ? ' + Go map' : ''})`);
|