refactor(helpers): better type safety for parsed arguments, rename directory

This commit is contained in:
Valentyne Stigloher 2025-09-21 14:16:02 +02:00
parent b7e6111d64
commit 25ef151a7e
5 changed files with 23 additions and 27 deletions

View File

@ -323,7 +323,7 @@ new LocaleDescription('pt', 'Português', 'https://pt.pronouns.page', true, 'ã'
Save approved translations to a local file (e.g. `proposals.suml`). Then run:
```
pnpm run-file helpers/merge/index.ts merge -l locale -f filename
pnpm run-file helpers/translations/index.ts merge --locale locale --file filename
```
### Current translations being worked on

View File

View File

@ -2,8 +2,8 @@ import fs from 'node:fs/promises';
import { deepListKeys } from '#shared/helpers.ts';
import { listMissingTranslations } from '#shared/missingTranslations.ts';
import { DictNode, parse } from '~~/helpers/merge/sumlAst.ts';
import type { Node } from '~~/helpers/merge/sumlAst.ts';
import { DictNode, parse } from '~~/helpers/translations/sumlAst.ts';
import type { Node } from '~~/helpers/translations/sumlAst.ts';
import type { Config } from '~~/locale/config.ts';
import type { Translations } from '~~/locale/translations.ts';
import { loadSuml } from '~~/server/loader.ts';

View File

@ -1,71 +1,67 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { mergeTranslationProposals, createTranslationFiles } from '~~/helpers/merge/translationsHelper.ts';
import Locales from '~~/locale/locales.ts';
import { mergeTranslationProposals, createTranslationFiles } from '~~/helpers/translations/functions.ts';
import locales from '~~/locale/locales.ts';
yargs(hideBin(process.argv))
.scriptName('merger')
.scriptName('translations')
.help()
.showHidden()
.version()
.demandCommand()
.command(
'merge',
'Merge in pending translation changes',
(build) => {
build
return build
.options({
l: {
alias: ['locale'],
locale: {
alias: ['l'],
describe: 'Locale to be merged into',
demandOption: true,
type: 'string',
choices: locales.map((locale) => locale.code),
nargs: 1,
},
f: {
alias: ['file'],
file: {
alias: ['f'],
describe: 'The file location of the pending translations',
demandOption: true,
type: 'string',
normalise: true,
nargs: 1,
},
})
.usage('$0 merge -l <locale> -f <pending_file>');
.usage('$0 merge --locale <locale> --file <pending_file>');
},
async (args) => {
if (
!Locales
.map((l) => l.code)
.includes(String(args.l).toLowerCase() as typeof Locales[number]['code'])
) {
throw new RangeError('Locale Code does not exist, please check your spelling');
}
await mergeTranslationProposals(String(args.l).toLowerCase(), args.f as string);
await mergeTranslationProposals(args.locale, args.file);
},
)
.command(
'create',
'Create a new language system',
(build) => {
build
return build
.options({
l: {
alias: ['locale'],
locale: {
alias: ['l'],
describe: 'Locale to be merged into',
demandOption: true,
type: 'string',
nargs: 1,
},
})
.usage('$0 create -l <locale>');
.usage('$0 create --locale <locale>');
},
async (args) => {
await createTranslationFiles(String(args.l).toLowerCase() as string);
await createTranslationFiles(args.locale);
},
)
.example([
['$0 merge -l en -f ./to-merge.suml', 'Merge pending translations into the English (en) locale'],
['$0 create -l he', 'Create a new Hebrew (he) locale'],
['$0 merge --locale en --file ./to-merge.suml', 'Merge pending translations into the English (en) locale'],
['$0 create --locale he', 'Create a new Hebrew (he) locale'],
])
.usage('$0 <command> [options]')
.showHelpOnFail(false, 'Specify --help for available options')