import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; import { mergeTranslationProposals, createTranslationFiles } from '~~/helpers/translations/functions.ts'; import locales from '~~/locale/locales.ts'; yargs(hideBin(process.argv)) .scriptName('translations') .help() .showHidden() .version() .demandCommand() .command( 'merge', 'Merge in pending translation changes', (build) => { return build .options({ locale: { alias: ['l'], describe: 'Locale to be merged into', demandOption: true, type: 'string', choices: locales.map((locale) => locale.code), nargs: 1, }, file: { alias: ['f'], describe: 'The file location of the pending translations', demandOption: true, type: 'string', normalise: true, nargs: 1, }, }) .usage('$0 merge --locale --file '); }, async (args) => { await mergeTranslationProposals(args.locale, args.file); }, ) .command( 'create', 'Create a new language system', (build) => { return build .options({ locale: { alias: ['l'], describe: 'Locale to be merged into', demandOption: true, type: 'string', nargs: 1, }, }) .usage('$0 create --locale '); }, async (args) => { await createTranslationFiles(args.locale); }, ) .example([ ['$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 [options]') .showHelpOnFail(false, 'Specify --help for available options') .wrap(null) .parse();