Skip to content

Commit f224aed

Browse files
committed
Fix logs, clean up caching.
1 parent fdb1f89 commit f224aed

File tree

4 files changed

+66
-22
lines changed

4 files changed

+66
-22
lines changed

web/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# Created by https://www.gitignore.io/api/node
33
# Edit at https://www.gitignore.io/?templates=node
44

5+
#region Locale
6+
7+
src/locales/*.ts
8+
59
### Node ###
610
# Logs
711
logs

web/package.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"build": "wireit",
88
"build-proxy": "wireit",
9-
"build:locales": "wireit",
9+
"build:locales": "node scripts/build-locales.mjs",
1010
"build:sfe": "npm run build -w @goauthentik/web-sfe",
1111
"bundler:watch": "node scripts/build-web.mjs --watch",
1212
"extract-locales": "lit-localize extract",
@@ -246,16 +246,6 @@
246246
"locales:repair": {
247247
"command": "prettier --write ./src/locale-codes.ts"
248248
},
249-
"build:locales": {
250-
"command": "node scripts/build-locales.mjs",
251-
"files": [
252-
"./xliff/*.xlf"
253-
],
254-
"output": [
255-
"./src/locales/*.ts",
256-
"./src/locale-codes.ts"
257-
]
258-
},
259249
"lint:components": {
260250
"command": "lit-analyzer src"
261251
},

web/scripts/build-locales.mjs

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ import path, { resolve } from "node:path";
2020

2121
import { generatePseudoLocaleModule } from "./pseudolocalize.mjs";
2222

23-
// import localizeRules from "../lit-localize.json" with { type: "json" };
2423
import { ConsoleLogger } from "#logger/node";
2524
import { PackageRoot } from "#paths/node";
2625

2726
import { readConfigFileAndWriteSchema } from "@lit/localize-tools/lib/config.js";
2827
import { RuntimeLitLocalizer } from "@lit/localize-tools/lib/modes/runtime.js";
2928

29+
//#region Setup
30+
31+
const missingMessagePattern = /([\w_-]+)\smessage\s(?:[\w_-]+)\sis\smissing/;
3032
const logger = ConsoleLogger.child({ name: "Locales" });
3133

3234
const localizeRules = readConfigFileAndWriteSchema(path.join(PackageRoot, "lit-localize.json"));
@@ -43,6 +45,17 @@ const EmittedLocalesDirectory = resolve(
4345
/** @type {string} */ (localizeRules.output.outputDir),
4446
);
4547

48+
const targetLocales = localizeRules.targetLocales.filter((localeCode) => {
49+
return localeCode !== "pseudo-LOCALE";
50+
});
51+
52+
//#endregion
53+
54+
//#region Utilities
55+
56+
/**
57+
* Cleans the emitted locales directory.
58+
*/
4659
async function cleanEmittedLocales() {
4760
logger.info("♻️ Cleaning previously emitted locales...");
4861
logger.info(`♻️ ${EmittedLocalesDirectory}`);
@@ -113,10 +126,6 @@ async function checkIfEmittedFileCurrent(localeCode) {
113126
async function checkIfLocalesAreCurrent() {
114127
logger.info("Reading locale configuration...");
115128

116-
const targetLocales = localizeRules.targetLocales.filter((localeCode) => {
117-
return localeCode !== "pseudo-LOCALE";
118-
});
119-
120129
logger.info(`Checking ${targetLocales.length} source files...`);
121130

122131
let outOfDateCount = 0;
@@ -141,16 +150,56 @@ export async function generateLocaleModules() {
141150

142151
logger.info("Generating locale modules...");
143152

144-
const localizer = new RuntimeLitLocalizer({
145-
...localizeRules,
146-
output: /** @type {RuntimeOutputConfig} */ (localizeRules.output),
147-
});
153+
/**
154+
* @type {Map<string, number>}
155+
*/
156+
const localeWarnings = new Map();
157+
158+
const initialConsoleWarn = console.warn;
159+
160+
console.warn = (arg0, ...args) => {
161+
if (typeof arg0 !== "string") {
162+
initialConsoleWarn(arg0, ...args);
163+
return;
164+
}
165+
166+
const [, matchedLocale] = arg0.match(missingMessagePattern) || [];
167+
168+
if (matchedLocale) {
169+
const count = localeWarnings.get(matchedLocale) || 0;
170+
171+
localeWarnings.set(matchedLocale, count + 1);
172+
173+
return;
174+
}
175+
176+
initialConsoleWarn(arg0, ...args);
177+
};
178+
179+
// @ts-expect-error: Type is too broad.
180+
const localizer = new RuntimeLitLocalizer(localizeRules);
148181

149182
await localizer.build();
150183

184+
const report = Array.from(localeWarnings)
185+
.filter(([, count]) => count)
186+
.sort(([, totalsA], [, totalsB]) => {
187+
return totalsB - totalsA;
188+
})
189+
.map(([locale, count]) => `${locale}: ${count.toLocaleString()}`)
190+
.join("\n");
191+
192+
logger.info(`Missing translations:\n${report}`);
193+
194+
localizer.assertTranslationsAreValid();
195+
151196
logger.info("Complete.");
152197
}
153198

199+
//#endregion
200+
201+
//#region Commands
202+
154203
async function delegateCommand() {
155204
const command = process.argv[2];
156205

@@ -160,7 +209,7 @@ async function delegateCommand() {
160209
case "--check":
161210
return checkIfLocalesAreCurrent();
162211
case "--force":
163-
return generateLocaleModules();
212+
return cleanEmittedLocales().then(generateLocaleModules);
164213
}
165214

166215
const upToDate = await checkIfLocalesAreCurrent();
@@ -184,3 +233,5 @@ await delegateCommand()
184233
logger.error(`Error during locale build: ${error}`);
185234
process.exit(1);
186235
});
236+
237+
//#endregion

web/src/locales/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)