2025-06-23 16:02:50 +02:00

70 lines
2.3 KiB
TypeScript

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