From bfcd62883a0e41d1427b4800afcb32be582c87dc Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 16 Mar 2026 14:26:26 +0100 Subject: [PATCH] [web] extend 'make sort_locales' to sort extracted-translations.json (#32193) GitOrigin-RevId: 19ad8ea5a8b7fb3eadfccb11affe6794bee84050 --- services/web/scripts/translations/sort.js | 46 +++++++++++++---------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/services/web/scripts/translations/sort.js b/services/web/scripts/translations/sort.js index e49a923597..0ccfb8692d 100644 --- a/services/web/scripts/translations/sort.js +++ b/services/web/scripts/translations/sort.js @@ -8,31 +8,39 @@ const LOCALES = Path.join(__dirname, '../../locales') const CHECK = process.argv.includes('--check') async function main() { + await sortFile( + Path.join(__dirname, '../../frontend/extracted-translations.json') + ) for (const locale of await fs.promises.readdir(LOCALES)) { if (locale === 'README.md') continue const path = Path.join(LOCALES, locale) - const input = await fs.promises.readFile(path, 'utf-8') - const parsed = JSON.parse(input) - const sorted = JSON.stringify(parsed, Object.keys(parsed).sort(), 2) + '\n' - if (input === sorted) { - continue - } - if (CHECK) { - console.warn('---') - console.warn( - locale, - 'is not sorted. Try running:\n\n', - ' web$ make sort_locales', - '\n' - ) - console.warn('---') - throw new Error(locale + ' is not sorted') - } - console.log('Storing sorted version of', locale) - await fs.promises.writeFile(path, sorted) + await sortFile(path) } } +async function sortFile(path) { + const name = Path.basename(path) + const input = await fs.promises.readFile(path, 'utf-8') + const parsed = JSON.parse(input) + const sorted = JSON.stringify(parsed, Object.keys(parsed).sort(), 2) + '\n' + if (input === sorted) { + return + } + if (CHECK) { + console.warn('---') + console.warn( + name, + 'is not sorted. Try running:\n\n', + ' web$ make sort_locales', + '\n' + ) + console.warn('---') + throw new Error(name + ' is not sorted') + } + console.log('Storing sorted version of', name) + await fs.promises.writeFile(path, sorted) +} + try { await main() } catch (error) {