mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 17:36:44 +00:00
ae6293f6da
Resolves #2739 ## Description: Introduce language metadata handling and refactor existing language checks to validate the existence of language JSON and corresponding SVG files. Add tests to ensure the integrity of the new metadata structure and its references. The lang field is intentionally kept in each language file. This is because the files are frequently regenerated by Crowdin, and the field also serves as a hint for management and maintenance. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: aotumuri --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
|
|
describe("Lang Metadata Check", () => {
|
|
const langDir = path.join(__dirname, "../resources/lang");
|
|
const flagDir = path.join(__dirname, "../resources/flags");
|
|
const metadataFile = path.join(langDir, "metadata.json");
|
|
|
|
test("metadata languages point to existing lang json and flag files", () => {
|
|
if (!fs.existsSync(metadataFile)) {
|
|
console.log(
|
|
"No resources/lang/metadata.json file found. Skipping check.",
|
|
);
|
|
return;
|
|
}
|
|
|
|
const metadata = JSON.parse(fs.readFileSync(metadataFile, "utf-8"));
|
|
if (!Array.isArray(metadata) || metadata.length === 0) {
|
|
console.log(
|
|
"No language entries found in metadata.json. Skipping check.",
|
|
);
|
|
return;
|
|
}
|
|
|
|
const errors: string[] = [];
|
|
|
|
for (const entry of metadata) {
|
|
const code = entry?.code;
|
|
const svg = entry?.svg;
|
|
if (typeof code !== "string" || code.length === 0) {
|
|
errors.push(
|
|
`metadata entry missing valid code: ${JSON.stringify(entry)}`,
|
|
);
|
|
continue;
|
|
}
|
|
if (typeof svg !== "string" || svg.length === 0) {
|
|
errors.push(
|
|
`[${code}]: metadata svg is missing or not a non-empty string`,
|
|
);
|
|
continue;
|
|
}
|
|
|
|
const langFilePath = path.join(langDir, `${code}.json`);
|
|
if (!fs.existsSync(langFilePath)) {
|
|
errors.push(`[${code}]: lang json file does not exist: ${code}.json`);
|
|
}
|
|
|
|
const svgFile = svg.endsWith(".svg") ? svg : `${svg}.svg`;
|
|
const flagPath = path.join(flagDir, svgFile);
|
|
if (!fs.existsSync(flagPath)) {
|
|
errors.push(`[${code}]: SVG file does not exist: ${svgFile}`);
|
|
}
|
|
}
|
|
|
|
if (errors.length > 0) {
|
|
console.error(
|
|
"Metadata lang or SVG file check failed:\n" + errors.join("\n"),
|
|
);
|
|
expect(errors).toEqual([]);
|
|
}
|
|
});
|
|
});
|