From bc6a4c0f3f77c5b8473b44c8495e2e54fa1f28f3 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 15 Mar 2024 19:47:23 +0100 Subject: [PATCH 01/12] add 'make dump-translations' --- Makefile | 4 ++++ build/translations.js | 32 ++++++++++++++++++++++++++++++++ package-lock.json | 1 + package.json | 1 + 4 files changed, 38 insertions(+) create mode 100755 build/translations.js diff --git a/Makefile b/Makefile index 88bcf0e17cc4c..28bba1e468460 100644 --- a/Makefile +++ b/Makefile @@ -949,6 +949,10 @@ update-translations: mv ./translations/*.ini ./options/locale/ rmdir ./translations +.PHONY: dump-translations +dump-translations: node_modules + node build/translations.js dump + .PHONY: generate-license generate-license: $(GO) run build/generate-licenses.go diff --git a/build/translations.js b/build/translations.js new file mode 100755 index 0000000000000..223bda354d030 --- /dev/null +++ b/build/translations.js @@ -0,0 +1,32 @@ +#!/usr/bin/env node +import {readFileSync} from 'node:fs'; +import {parse} from 'ini'; +import {argv} from 'node:process'; + +const [cmd] = argv.slice(2); +const cmds = ['dump']; + +if (!cmds.includes(cmd)) { + console.info(` + Usage: ${argv[1]} dump + + Commands: + dump: Dump all current translation keys to stdout + `); +} + +function dumpObj(obj, path = '') { + for (const [key, value] of Object.entries(obj)) { + if (typeof value === 'string') { + console.info(`${path}.${key}`); + } else if (typeof value === 'object' && value !== 0) { + dumpObj(value, key); + } + } +} + +if (cmd === 'dump') { + const text = readFileSync(new URL('../options/locale/locale_en-US.ini', import.meta.url), 'utf8'); + const parsed = parse(text); + dumpObj(parsed); +} diff --git a/package-lock.json b/package-lock.json index 1ec1a6210571b..40974080a4798 100644 --- a/package-lock.json +++ b/package-lock.json @@ -85,6 +85,7 @@ "eslint-plugin-vue": "9.23.0", "eslint-plugin-vue-scoped-css": "2.7.2", "eslint-plugin-wc": "2.0.4", + "ini": "4.1.2", "jsdom": "24.0.0", "markdownlint-cli": "0.39.0", "postcss-html": "1.6.0", diff --git a/package.json b/package.json index 1be87e8b390d7..f9abe10cd7276 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "eslint-plugin-vue": "9.23.0", "eslint-plugin-vue-scoped-css": "2.7.2", "eslint-plugin-wc": "2.0.4", + "ini": "4.1.2", "jsdom": "24.0.0", "markdownlint-cli": "0.39.0", "postcss-html": "1.6.0", From e3d37587373c99a72034001bed6c16d6006a8fad Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 15 Mar 2024 19:49:45 +0100 Subject: [PATCH 02/12] silent --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 28bba1e468460..9270ee496df15 100644 --- a/Makefile +++ b/Makefile @@ -951,7 +951,7 @@ update-translations: .PHONY: dump-translations dump-translations: node_modules - node build/translations.js dump + @node build/translations.js dump .PHONY: generate-license generate-license: From d0412260f7ffda2b200d56549444a4aa40a97266 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 15 Mar 2024 19:54:13 +0100 Subject: [PATCH 03/12] tweaks --- build/translations.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build/translations.js b/build/translations.js index 223bda354d030..e928c139b509b 100755 --- a/build/translations.js +++ b/build/translations.js @@ -2,13 +2,15 @@ import {readFileSync} from 'node:fs'; import {parse} from 'ini'; import {argv} from 'node:process'; +import {basename} from 'node:path'; + const [cmd] = argv.slice(2); const cmds = ['dump']; if (!cmds.includes(cmd)) { console.info(` - Usage: ${argv[1]} dump + Usage: ${basename(argv[1])} dump Commands: dump: Dump all current translation keys to stdout @@ -27,6 +29,5 @@ function dumpObj(obj, path = '') { if (cmd === 'dump') { const text = readFileSync(new URL('../options/locale/locale_en-US.ini', import.meta.url), 'utf8'); - const parsed = parse(text); - dumpObj(parsed); + dumpObj(parse(text)); } From 49978a29633ac0697056d2a52b76e10ba605ce19 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 15 Mar 2024 19:54:36 +0100 Subject: [PATCH 04/12] lint --- build/translations.js | 1 - 1 file changed, 1 deletion(-) diff --git a/build/translations.js b/build/translations.js index e928c139b509b..71026b7419ad8 100755 --- a/build/translations.js +++ b/build/translations.js @@ -4,7 +4,6 @@ import {parse} from 'ini'; import {argv} from 'node:process'; import {basename} from 'node:path'; - const [cmd] = argv.slice(2); const cmds = ['dump']; From 5e2213d8050ef7c5e806f56518a61dd1322d1e9c Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 15 Mar 2024 19:55:28 +0100 Subject: [PATCH 05/12] tweak --- build/translations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/translations.js b/build/translations.js index 71026b7419ad8..ba2139d016231 100755 --- a/build/translations.js +++ b/build/translations.js @@ -9,7 +9,7 @@ const cmds = ['dump']; if (!cmds.includes(cmd)) { console.info(` - Usage: ${basename(argv[1])} dump + Usage: ${basename(argv[1])} command Commands: dump: Dump all current translation keys to stdout From c8a3094da95addf8bcd92a63fd31e1954191cc3a Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 15 Mar 2024 19:56:57 +0100 Subject: [PATCH 06/12] align --- build/translations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/translations.js b/build/translations.js index ba2139d016231..1403d1bad69d0 100755 --- a/build/translations.js +++ b/build/translations.js @@ -12,7 +12,7 @@ if (!cmds.includes(cmd)) { Usage: ${basename(argv[1])} command Commands: - dump: Dump all current translation keys to stdout + dump Dump all current translation keys to stdout `); } From 650ecdf695509bfb4b6be907ce9aaf9a9b1b7db7 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 15 Mar 2024 20:02:26 +0100 Subject: [PATCH 07/12] fix null check --- build/translations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/translations.js b/build/translations.js index 1403d1bad69d0..8bf131c3d143d 100755 --- a/build/translations.js +++ b/build/translations.js @@ -20,7 +20,7 @@ function dumpObj(obj, path = '') { for (const [key, value] of Object.entries(obj)) { if (typeof value === 'string') { console.info(`${path}.${key}`); - } else if (typeof value === 'object' && value !== 0) { + } else if (typeof value === 'object' && value !== null) { dumpObj(value, key); } } From d108b87abaf73b8c89fa25466e7bc78548ba1caf Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 15 Mar 2024 20:03:15 +0100 Subject: [PATCH 08/12] simplify --- build/translations.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/translations.js b/build/translations.js index 8bf131c3d143d..cce2b479c2d9d 100755 --- a/build/translations.js +++ b/build/translations.js @@ -18,10 +18,10 @@ if (!cmds.includes(cmd)) { function dumpObj(obj, path = '') { for (const [key, value] of Object.entries(obj)) { - if (typeof value === 'string') { - console.info(`${path}.${key}`); - } else if (typeof value === 'object' && value !== null) { + if (typeof value === 'object' && value !== null) { dumpObj(value, key); + } else { + console.info(`${path}.${key}`); } } } From 89c732dea0016b5080feaa1a08faea4bf85b49a4 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 15 Mar 2024 20:04:53 +0100 Subject: [PATCH 09/12] support arbritrary depth --- build/translations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/translations.js b/build/translations.js index cce2b479c2d9d..bdb9156f5f2cb 100755 --- a/build/translations.js +++ b/build/translations.js @@ -19,7 +19,7 @@ if (!cmds.includes(cmd)) { function dumpObj(obj, path = '') { for (const [key, value] of Object.entries(obj)) { if (typeof value === 'object' && value !== null) { - dumpObj(value, key); + dumpObj(value, path ? `${path}.${key}` : key); } else { console.info(`${path}.${key}`); } From f4391088117f332cfde3646c4bc1ae45667f62f5 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 15 Mar 2024 20:06:15 +0100 Subject: [PATCH 10/12] fix path calc --- build/translations.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build/translations.js b/build/translations.js index bdb9156f5f2cb..964fb569feded 100755 --- a/build/translations.js +++ b/build/translations.js @@ -16,12 +16,13 @@ if (!cmds.includes(cmd)) { `); } -function dumpObj(obj, path = '') { +function dumpObj(obj, currentPath = '') { for (const [key, value] of Object.entries(obj)) { + const path = currentPath ? `${currentPath}.${key}` : key; if (typeof value === 'object' && value !== null) { - dumpObj(value, path ? `${path}.${key}` : key); + dumpObj(value, path); } else { - console.info(`${path}.${key}`); + console.info(path); } } } From d8c2c821f911dfa723b4b1af46a03151cbb364a7 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 16 Mar 2024 13:08:32 +0100 Subject: [PATCH 11/12] move to tools directory --- Makefile | 2 +- {build => tools}/translations.js | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {build => tools}/translations.js (100%) diff --git a/Makefile b/Makefile index 9270ee496df15..f4efb12082d53 100644 --- a/Makefile +++ b/Makefile @@ -951,7 +951,7 @@ update-translations: .PHONY: dump-translations dump-translations: node_modules - @node build/translations.js dump + @node tools/translations.js dump .PHONY: generate-license generate-license: diff --git a/build/translations.js b/tools/translations.js similarity index 100% rename from build/translations.js rename to tools/translations.js From c352daf3b4266e657c2593febc82f3141845202c Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 16 Mar 2024 13:08:56 +0100 Subject: [PATCH 12/12] update lint --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f4efb12082d53..32442f66bb7eb 100644 --- a/Makefile +++ b/Makefile @@ -375,11 +375,11 @@ lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig .PHONY: lint-js lint-js: node_modules - npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js tests/e2e + npx eslint --color --max-warnings=0 --ext js,vue web_src/js build tools *.config.js tests/e2e .PHONY: lint-js-fix lint-js-fix: node_modules - npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js tests/e2e --fix + npx eslint --color --max-warnings=0 --ext js,vue web_src/js build tools *.config.js tests/e2e --fix .PHONY: lint-css lint-css: node_modules