diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fac967..062d338 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -149,6 +149,7 @@ jobs: - run: npm run test:polling - run: npm run test:replay - run: npm run test:upload + - run: npm run test:i18n - run: npm run build:static python: diff --git a/web/package.json b/web/package.json index 4c823af..f5265be 100644 --- a/web/package.json +++ b/web/package.json @@ -15,7 +15,8 @@ "generate:presets": "ts-node -P tsconfig.scripts.json src/scripts/generate-theme-presets.ts", "test:polling": "node --test scripts/polling.test.mjs", "test:replay": "node --test scripts/replay.test.mjs", - "test:upload": "node --test scripts/upload.test.mjs" + "test:upload": "node --test scripts/upload.test.mjs", + "test:i18n": "node scripts/check-i18n.mjs" }, "lint-staged": { "*.{js,ts,jsx,tsx}": [ diff --git a/web/scripts/check-i18n.mjs b/web/scripts/check-i18n.mjs new file mode 100644 index 0000000..149308b --- /dev/null +++ b/web/scripts/check-i18n.mjs @@ -0,0 +1,64 @@ +import { readFileSync, readdirSync, statSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +// Every literal t("...") / t('...') key must exist in the locale dictionary +// with the same {placeholders}. Dynamic keys (variables, template literals +// with ${}) are skipped: there is nothing to compare them against. +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); +const dict = JSON.parse(readFileSync(join(root, "src/i18n/locales/tr.json"), "utf8")); + +const files = []; +function walk(dir) { + for (const name of readdirSync(dir)) { + const p = join(dir, name); + const st = statSync(p); + if (st.isDirectory()) walk(p); + else if (/\.(ts|tsx)$/.test(name)) files.push(p); + } +} +walk(join(root, "src")); + +const calls = new Map(); // key -> first file that uses it +const literalCall = /(?:^|[^\w$.])t\(\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)')/gm; +for (const file of files) { + const src = readFileSync(file, "utf8"); + for (const m of src.matchAll(literalCall)) { + const key = + m[1] !== undefined ? JSON.parse(`"${m[1]}"`) : m[2].replace(/\\(['\\])/g, "$1"); + if (!calls.has(key)) calls.set(key, file.slice(root.length + 1)); + } +} + +function placeholders(s) { + return [...s.matchAll(/\{(\w+)\}/g)] + .map((m) => m[1]) + .sort() + .join(","); +} + +const missing = []; +const mismatch = []; +for (const [key, file] of calls) { + if (!Object.prototype.hasOwnProperty.call(dict, key)) { + missing.push(`${file}: ${JSON.stringify(key)}`); + continue; + } + if (placeholders(dict[key]) !== placeholders(key)) { + mismatch.push(`${JSON.stringify(key)}: source {${placeholders(key)}} dict {${placeholders(dict[key])}}`); + } +} + +if (missing.length || mismatch.length) { + if (missing.length) { + console.error(`Missing tr.json entries (${missing.length}):\n${missing.join("\n")}`); + } + if (mismatch.length) { + console.error(`Placeholder mismatches (${mismatch.length}):\n${mismatch.join("\n")}`); + } + process.exit(1); +} + +console.log( + `i18n: ${calls.size} literal keys checked against ${Object.keys(dict).length} tr.json entries`, +); diff --git a/web/scripts/upload.test.mjs b/web/scripts/upload.test.mjs index 733184e..8826bca 100644 --- a/web/scripts/upload.test.mjs +++ b/web/scripts/upload.test.mjs @@ -21,6 +21,9 @@ function setup(mock = false) { require(name) { if (name === "@/lib/mock/enabled") return { MOCK: mock }; if (name === "@/lib/mock/handler") return { mockHandle: () => assert.fail("unexpected mock request") }; + // English passthrough: assertions below match the source (English) messages. + if (name === "@/i18n") + return { t: (key, vars) => key.replace(/\{(\w+)\}/g, (m, k) => (vars && k in vars ? String(vars[k]) : m)) }; throw new Error("Unexpected import: " + name); }, FormData: class { diff --git a/web/src/app/(auth)/login/page.tsx b/web/src/app/(auth)/login/page.tsx index 1ec20b3..9d8d4c1 100644 --- a/web/src/app/(auth)/login/page.tsx +++ b/web/src/app/(auth)/login/page.tsx @@ -11,6 +11,7 @@ import { Checkbox } from "@/components/ui/checkbox"; import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; +import { t } from "@/i18n"; import { api } from "@/lib/api"; import { auth } from "@/lib/auth"; @@ -55,14 +56,14 @@ export default function LoginPage() { .then(({ initialized }) => { if (!initialized) router.replace("/setup"); }) - .catch(() => setError("Unable to connect to the backend service")) + .catch(() => setError(t("Unable to connect to the backend service"))) .finally(() => setChecking(false)); }, [router]); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (!agreed) { - setError("Please read and agree to the Terms of Use first"); + setError(t("Please read and agree to the Terms of Use first")); return; } setLoading(true); @@ -72,7 +73,7 @@ export default function LoginPage() { auth.setToken(token); window.location.replace("/function/tasks"); } catch { - setError("Incorrect username or password"); + setError(t("Incorrect username or password")); } finally { setLoading(false); } @@ -80,12 +81,16 @@ export default function LoginPage() { if (checking) { return ( -
Welcome back — enter your password to continue using ARTEX
++ {t("Welcome back — enter your password to continue using ARTEX")} +
- Version v1.1 · Effective 2026-10-11 · Please read all the following terms in full before signing in + {t("Version v1.1 · Effective 2026-10-11 · Please read all the following terms in full before signing in")}
- This Terms of Use and Disclaimer (the "Statement") is the agreement between you and the ARTEX - project authors and contributors regarding your use of this software. Please read it carefully and fully understand each provision before use, especially the disclaimer, liability-limitation, and prohibition clauses highlighted in bold or color blocks. + {t( + 'This Terms of Use and Disclaimer (the "Statement") is the agreement between you and the ARTEX project authors and contributors regarding your use of this software. Please read it carefully and fully understand each provision before use, especially the disclaimer, liability-limitation, and prohibition clauses highlighted in bold or color blocks.', + )} {" "} - Once you download, install, access, or use this software in any way, you are deemed to have read, understood, and agreed to be bound by all of this Statement. + {t( + "Once you download, install, access, or use this software in any way, you are deemed to have read, understood, and agreed to be bound by all of this Statement.", + )}
@@ -182,12 +193,12 @@ export default function LoginPage() { 1 - Article 1 · Definitions and Open-Source License + {t("Article 1 · Definitions and Open-Source License")}- This software (ARTEX) is an open-source program released under the GNU Affero General Public License - v3.0 (AGPL-3.0). You may freely use, copy, modify, and distribute it under that license; however, any derivative work (including online services provided to third parties over a network) must likewise be open-sourced under - the AGPL-3.0 license with the complete corresponding source code made public to its users. The full AGPL-3.0 terms are governed by the accompanying LICENSE file. + {t( + "This software (ARTEX) is an open-source program released under the GNU Affero General Public License v3.0 (AGPL-3.0). You may freely use, copy, modify, and distribute it under that license; however, any derivative work (including online services provided to third parties over a network) must likewise be open-sourced under the AGPL-3.0 license with the complete corresponding source code made public to its users. The full AGPL-3.0 terms are governed by the accompanying LICENSE file.", + )}
@@ -196,10 +207,12 @@ export default function LoginPage() { 2 - Article 2 · Permitted Scope of Use + {t("Article 2 · Permitted Scope of Use")}- This software is a security-testing platform. You may use it for: personal study, code research, and technical verification in environments you set up yourself; security testing of systems you own; security testing of third-party systems when you hold the owner's explicit authorization; and testing within the written scope of a bug bounty or vulnerability disclosure program, in compliance with that program's rules of engagement. You are responsible for obtaining and keeping proof of authorization, for staying inside the authorized scope, and for the safety and proportionality of every action the software takes on your behalf. + {t( + "This software is a security-testing platform. You may use it for: personal study, code research, and technical verification in environments you set up yourself; security testing of systems you own; security testing of third-party systems when you hold the owner's explicit authorization; and testing within the written scope of a bug bounty or vulnerability disclosure program, in compliance with that program's rules of engagement. You are responsible for obtaining and keeping proof of authorization, for staying inside the authorized scope, and for the safety and proportionality of every action the software takes on your behalf.", + )}
@@ -209,15 +222,29 @@ export default function LoginPage() { 3- The copyright and related intellectual property of this software belong to the project authors and contributors, who grant - you the corresponding rights within the scope of the AGPL-3.0 license. Beyond the rights expressly granted by that license, this Statement grants you no other rights, expressly or by implication. + {t( + "The copyright and related intellectual property of this software belong to the project authors and contributors, who grant you the corresponding rights within the scope of the AGPL-3.0 license. Beyond the rights expressly granted by that license, this Statement grants you no other rights, expressly or by implication.", + )}
@@ -239,10 +267,12 @@ export default function LoginPage() { 5 - Article 5 · Data and Privacy + {t("Article 5 · Data and Privacy")}- This software is a self-deployable open-source program; the authors run no centralized service and neither collect nor upload your usage data. All data you generate, process, or touch while using it stays under your control, and you are responsible for its legality and security; any consequence of improper data handling is yours to bear. + {t( + "This software is a self-deployable open-source program; the authors run no centralized service and neither collect nor upload your usage data. All data you generate, process, or touch while using it stays under your control, and you are responsible for its legality and security; any consequence of improper data handling is yours to bear.", + )}
@@ -251,13 +281,17 @@ export default function LoginPage() { 6 - Article 6 · Compliance and Legal Liability + {t("Article 6 · Compliance and Legal Liability")}- You must comply on your own with all laws and regulations of your country or region on cybersecurity, data security and personal-information protection, computer crime, and the like (for example, laws on unauthorized access to computer systems, on personal-data protection, and on the responsibilities of security researchers and penetration testers in your jurisdiction). + {t( + "You must comply on your own with all laws and regulations of your country or region on cybersecurity, data security and personal-information protection, computer crime, and the like (for example, laws on unauthorized access to computer systems, on personal-data protection, and on the responsibilities of security researchers and penetration testers in your jurisdiction).", + )} {" "} - All legal liability and consequences arising from your violation of the above laws and regulations or of this Statement are borne by you alone and have nothing to do with this software's authors and contributors. + {t( + "All legal liability and consequences arising from your violation of the above laws and regulations or of this Statement are borne by you alone and have nothing to do with this software's authors and contributors.", + )}
@@ -267,11 +301,12 @@ export default function LoginPage() { 7 - Article 7 · Disclaimer and Limitation of Liability + {t("Article 7 · Disclaimer and Limitation of Liability")}- This software is provided on an "AS IS" and "AS - AVAILABLE" basis, without any express or implied warranty, including but not limited to warranties of merchantability, fitness for a particular purpose, accuracy, and non-infringement. To the maximum extent permitted by applicable law, this software's authors and contributors are not liable for any direct, indirect, incidental, special, or consequential loss arising from using or being unable to use this software (regardless of whether it is used properly), including but not limited to data loss, system damage, business interruption, loss of profit, or legal disputes. + {t( + 'This software is provided on an "AS IS" and "AS AVAILABLE" basis, without any express or implied warranty, including but not limited to warranties of merchantability, fitness for a particular purpose, accuracy, and non-infringement. To the maximum extent permitted by applicable law, this software\'s authors and contributors are not liable for any direct, indirect, incidental, special, or consequential loss arising from using or being unable to use this software (regardless of whether it is used properly), including but not limited to data loss, system damage, business interruption, loss of profit, or legal disputes.', + )}
@@ -280,17 +315,19 @@ export default function LoginPage() { 8 - Article 8 · Changes to the Terms and Final Interpretation + {t("Article 8 · Changes to the Terms and Final Interpretation")}- The authors may update this Statement from time to time as laws, regulations, or project development require; the updated version ships with the project and takes effect on its publication date, and your continued use of this software means you accept the revised terms. To the extent permitted by law, the authors hold the final right of interpretation of this Statement. If any provision of this Statement is held invalid, the remaining provisions stay in effect. + {t( + "The authors may update this Statement from time to time as laws, regulations, or project development require; the updated version ships with the project and takes effect on its publication date, and your continued use of this software means you accept the revised terms. To the extent permitted by law, the authors hold the final right of interpretation of this Statement. If any provision of this Statement is held invalid, the remaining provisions stay in effect.", + )}
- {readToEnd ? "You have read all the terms" : "Scroll the terms to the bottom to confirm"} + {readToEnd ? t("You have read all the terms") : t("Scroll the terms to the bottom to confirm")}
{unavailable - ? "The backend or database is temporarily unavailable. To avoid overwriting a password already set on this instance, setup is temporarily closed — restore the service and try again." - : "First time using ARTEX? Enter the setup token from the server log, then set a login password for the account (at least 12 characters)"} + ? t( + "The backend or database is temporarily unavailable. To avoid overwriting a password already set on this instance, setup is temporarily closed — restore the service and try again.", + ) + : t( + "First time using ARTEX? Enter the setup token from the server log, then set a login password for the account (at least 12 characters)", + )}
{error}
}