Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(i18n): flag content-only languages in the coverage check
Claude23d23741d4b8
diff --git a/scripts/translation/check-translation-coverage.mts b/scripts/translation/check-translation-coverage.mtsindex d448059349..d0d39e3a13 100644--- a/scripts/translation/check-translation-coverage.mts+++ b/scripts/translation/check-translation-coverage.mts@@ -1,6 +1,8 @@import { LOCALES as WEBSITE_LOCALES } from "../../apps/website/src/locales.ts";import { LOCALES as APP_LOCALES } from "../../packages/commons/src/lib/i18n.ts";-import { getLanguageStats, type WeblateProject } from "./utils.mts";+import {+ findUnofferedLanguages, getLanguageStats, type OfferedLocale, type WeblateProject+} from "./utils.mts";/*** Coverage above which a language must be offered, rather than sitting@@ -12,37 +14,38 @@ interface GatedProject {project: WeblateProject;/** Names the list a maintainer has to add the locale to, quoted in the failure. */listDescription: string;- localeIds: string[];+ locales: OfferedLocale[];}const GATED_PROJECTS: GatedProject[] = [{project: "client",listDescription: "LOCALES in packages/commons/src/lib/i18n.ts",- localeIds: APP_LOCALES.map(l => l.id)+ locales: APP_LOCALES},{project: "website",listDescription: "LOCALES in apps/website/src/locales.ts",- localeIds: WEBSITE_LOCALES.map(l => l.id)+ locales: WEBSITE_LOCALES}];async function main() {const failures: string[] = [];- for (const { project, listDescription, localeIds } of GATED_PROJECTS) {+ for (const { project, listDescription, locales } of GATED_PROJECTS) {const languageStats = await getLanguageStats(project);- for (const localeData of languageStats.results) {+ const unoffered = findUnofferedLanguages(+ languageStats.results, locales, MINIMUM_COVERAGE_PERCENT);+ for (const localeData of unoffered) {const localeId = localeData.language_code;+ const reason = locales.some(l => l.id === localeId)+ ? `is marked \`contentOnly\` in ${listDescription}`+ : `is missing from ${listDescription}`;const percentage = localeData.translated_percent;- if (percentage <= MINIMUM_COVERAGE_PERCENT || localeIds.includes(localeId)) {- continue;- }-failures.push(`❌ ${localeData.language.name} (${localeId}) is ${percentage}% translated `- + `in '${project}', but is missing from ${listDescription}.`);+ + `in '${project}', but ${reason}.`);}}diff --git a/scripts/translation/utils.mts b/scripts/translation/utils.mtsindex 7635c94f85..52aecc4b1f 100644--- a/scripts/translation/utils.mts+++ b/scripts/translation/utils.mts@@ -9,6 +9,32 @@ export type WeblateProject = "readme" | "client" | "website";/** How long a `.language-stats-*.json` cache file is reused before Weblate is queried again. */export const CACHE_MAX_AGE_MS = 24 * 60 * 60 * 1000;+/** One language of a Weblate component, as `/api/components/…/translations/` lists it. */+export interface LanguageStat {+ language_code: string;+ translated_percent: number;+ language: { name: string };+}++/** A locale as the app or the website lists it. */+export interface OfferedLocale {+ id: string;+ contentOnly?: boolean;+}++/**+ * Lists the languages translated above `minimumPercent` that `locales` does not offer.+ *+ * A `contentOnly` locale counts as not offered: it can be set as a note's language, but+ * not selected as the UI language.+ */+export function findUnofferedLanguages(+ stats: LanguageStat[], locales: OfferedLocale[], minimumPercent: number) {+ const offeredIds = locales.filter(l => !l.contentOnly).map(l => l.id);+ return stats.filter(stat => stat.translated_percent > minimumPercent+ && !offeredIds.includes(stat.language_code));+}+export async function getLanguageStats(project: WeblateProject) {const cacheFile = join(scriptDir, `.language-stats-${project}.json`);diff --git a/scripts/translation/utils.spec.ts b/scripts/translation/utils.spec.tsindex 41c91c6cdf..7710bb4f4b 100644--- a/scripts/translation/utils.spec.ts+++ b/scripts/translation/utils.spec.ts@@ -1,6 +1,6 @@import { afterEach, describe, expect, it, vi } from "vitest";-import { CACHE_MAX_AGE_MS, fetchAllPages, isCacheFresh } from "./utils.mts";+import { CACHE_MAX_AGE_MS, fetchAllPages, findUnofferedLanguages, isCacheFresh } from "./utils.mts";describe("isCacheFresh", () => {const now = new Date("2026-08-20T12:00:00Z").getTime();@@ -61,3 +61,26 @@ describe("fetchAllPages", () => {.rejects.toThrow("Weblate answered 404 Not Found for /gone.");});});++describe("findUnofferedLanguages", () => {+ function stat(code: string, percent: number) {+ return { language_code: code, translated_percent: percent, language: { name: code } };+ }++ it("flags a language above the threshold only when it is not offered", () => {+ const stats = [ stat("de", 99), stat("fa", 97), stat("ug", 19), stat("ga", 50) ];+ const unoffered = findUnofferedLanguages(stats, [ { id: "de" } ], 50);++ expect(unoffered.map(s => s.language_code)).toStrictEqual([ "fa" ]);+ });++ it("treats a content-only locale as not offered", () => {+ const stats = [ stat("fa", 97), stat("he", 80), stat("ar", 99) ];+ const locales = [+ { id: "fa", contentOnly: true }, { id: "he", contentOnly: true }, { id: "ar" }+ ];++ expect(findUnofferedLanguages(stats, locales, 50).map(s => s.language_code))+ .toStrictEqual([ "fa", "he" ]);+ });+});