mirror of https://github.com/TriliumNext/Notes
fix(test): i18n tests
parent
5029bfe3fe
commit
f6dc912d2a
@ -0,0 +1,21 @@
|
|||||||
|
import { LOCALES } from "@triliumnext/commons";
|
||||||
|
import { readFileSync } from "fs";
|
||||||
|
import { join, dirname } from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
describe("i18n", () => {
|
||||||
|
it("translations are valid JSON", () => {
|
||||||
|
for (const locale of LOCALES) {
|
||||||
|
if (locale.contentOnly) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const translationPath = join(scriptDir, "..", "translations", locale.id, "translation.json");
|
||||||
|
const translationFile = readFileSync(translationPath, { encoding: "utf-8" });
|
||||||
|
expect(() => JSON.parse(translationFile), `JSON error while parsing locale '${locale.id}' at "${translationPath}"`)
|
||||||
|
.not.toThrow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,30 +1,18 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { LOCALES } from "@triliumnext/commons";
|
||||||
import * as i18n from "./i18n.js";
|
import { readFileSync } from "fs";
|
||||||
import path from "path";
|
import { join } from "path";
|
||||||
import fs from "fs";
|
|
||||||
|
|
||||||
function checkTranslations(translationDir: string, translationFileName: string) {
|
|
||||||
const locales = i18n.getLocales();
|
|
||||||
|
|
||||||
for (const locale of locales) {
|
|
||||||
if (locale.contentOnly) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const translationPath = path.join(translationDir, locale.id, translationFileName);
|
|
||||||
const translationFile = fs.readFileSync(translationPath, { encoding: "utf-8" });
|
|
||||||
expect(() => {
|
|
||||||
JSON.parse(translationFile);
|
|
||||||
}, `JSON error while parsing locale '${locale.id}' at "${translationPath}"`).not.toThrow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("i18n", () => {
|
describe("i18n", () => {
|
||||||
it("frontend translations are valid JSON", () => {
|
it("translations are valid JSON", () => {
|
||||||
checkTranslations("src/public/translations", "translation.json");
|
for (const locale of LOCALES) {
|
||||||
});
|
if (locale.contentOnly) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
it("backend translations are valid JSON", () => {
|
const translationPath = join(__dirname, "..", "assets", "translations", locale.id, "server.json");
|
||||||
checkTranslations("translations", "server.json");
|
const translationFile = readFileSync(translationPath, { encoding: "utf-8" });
|
||||||
|
expect(() => JSON.parse(translationFile), `JSON error while parsing locale '${locale.id}' at "${translationPath}"`)
|
||||||
|
.not.toThrow();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue