aboutsummaryrefslogtreecommitdiff
path: root/scripts/format-lang.js
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-24 13:09:50 +0000
committerFuwn <[email protected]>2026-01-24 13:09:50 +0000
commit396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch)
treeb9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /scripts/format-lang.js
downloadumami-main.tar.xz
umami-main.zip
Initial commitHEADmain
Created from https://vercel.com/new
Diffstat (limited to 'scripts/format-lang.js')
-rw-r--r--scripts/format-lang.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/format-lang.js b/scripts/format-lang.js
new file mode 100644
index 0000000..95c390e
--- /dev/null
+++ b/scripts/format-lang.js
@@ -0,0 +1,35 @@
+import path from 'node:path';
+import del from 'del';
+import fs from 'fs-extra';
+import { createRequire } from 'module';
+
+const require = createRequire(import.meta.url);
+const src = path.resolve(process.cwd(), 'src/lang');
+const dest = path.resolve(process.cwd(), 'build/messages');
+const files = fs.readdirSync(src);
+
+del.sync([path.join(dest)]);
+
+/*
+This script takes the files from the `lang` folder and formats them into
+the format that format-js expects.
+ */
+async function run() {
+ await fs.ensureDir(dest);
+
+ files.forEach(file => {
+ const lang = require(path.resolve(process.cwd(), `src/lang/${file}`));
+ const keys = Object.keys(lang).sort();
+
+ const formatted = keys.reduce((obj, key) => {
+ obj[key] = { defaultMessage: lang[key] };
+ return obj;
+ }, {});
+
+ const json = JSON.stringify(formatted, null, 2);
+
+ fs.writeFileSync(path.resolve(dest, file), json);
+ });
+}
+
+run();