mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-24 05:05:20 -04:00
refactor(helpers): better type safety for parsed arguments, rename directory
This commit is contained in:
parent
b7e6111d64
commit
25ef151a7e
@ -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:
|
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
|
### Current translations being worked on
|
||||||
|
@ -2,8 +2,8 @@ import fs from 'node:fs/promises';
|
|||||||
|
|
||||||
import { deepListKeys } from '#shared/helpers.ts';
|
import { deepListKeys } from '#shared/helpers.ts';
|
||||||
import { listMissingTranslations } from '#shared/missingTranslations.ts';
|
import { listMissingTranslations } from '#shared/missingTranslations.ts';
|
||||||
import { DictNode, parse } from '~~/helpers/merge/sumlAst.ts';
|
import { DictNode, parse } from '~~/helpers/translations/sumlAst.ts';
|
||||||
import type { Node } from '~~/helpers/merge/sumlAst.ts';
|
import type { Node } from '~~/helpers/translations/sumlAst.ts';
|
||||||
import type { Config } from '~~/locale/config.ts';
|
import type { Config } from '~~/locale/config.ts';
|
||||||
import type { Translations } from '~~/locale/translations.ts';
|
import type { Translations } from '~~/locale/translations.ts';
|
||||||
import { loadSuml } from '~~/server/loader.ts';
|
import { loadSuml } from '~~/server/loader.ts';
|
@ -1,71 +1,67 @@
|
|||||||
import yargs from 'yargs';
|
import yargs from 'yargs';
|
||||||
import { hideBin } from 'yargs/helpers';
|
import { hideBin } from 'yargs/helpers';
|
||||||
|
|
||||||
import { mergeTranslationProposals, createTranslationFiles } from '~~/helpers/merge/translationsHelper.ts';
|
import { mergeTranslationProposals, createTranslationFiles } from '~~/helpers/translations/functions.ts';
|
||||||
import Locales from '~~/locale/locales.ts';
|
import locales from '~~/locale/locales.ts';
|
||||||
|
|
||||||
yargs(hideBin(process.argv))
|
yargs(hideBin(process.argv))
|
||||||
.scriptName('merger')
|
.scriptName('translations')
|
||||||
.help()
|
.help()
|
||||||
.showHidden()
|
.showHidden()
|
||||||
.version()
|
.version()
|
||||||
|
.demandCommand()
|
||||||
.command(
|
.command(
|
||||||
'merge',
|
'merge',
|
||||||
'Merge in pending translation changes',
|
'Merge in pending translation changes',
|
||||||
(build) => {
|
(build) => {
|
||||||
build
|
return build
|
||||||
.options({
|
.options({
|
||||||
l: {
|
locale: {
|
||||||
alias: ['locale'],
|
alias: ['l'],
|
||||||
describe: 'Locale to be merged into',
|
describe: 'Locale to be merged into',
|
||||||
demandOption: true,
|
demandOption: true,
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
choices: locales.map((locale) => locale.code),
|
||||||
nargs: 1,
|
nargs: 1,
|
||||||
},
|
},
|
||||||
f: {
|
file: {
|
||||||
alias: ['file'],
|
alias: ['f'],
|
||||||
describe: 'The file location of the pending translations',
|
describe: 'The file location of the pending translations',
|
||||||
demandOption: true,
|
demandOption: true,
|
||||||
|
type: 'string',
|
||||||
normalise: true,
|
normalise: true,
|
||||||
nargs: 1,
|
nargs: 1,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.usage('$0 merge -l <locale> -f <pending_file>');
|
.usage('$0 merge --locale <locale> --file <pending_file>');
|
||||||
},
|
},
|
||||||
async (args) => {
|
async (args) => {
|
||||||
if (
|
await mergeTranslationProposals(args.locale, args.file);
|
||||||
!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);
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.command(
|
.command(
|
||||||
'create',
|
'create',
|
||||||
'Create a new language system',
|
'Create a new language system',
|
||||||
(build) => {
|
(build) => {
|
||||||
build
|
return build
|
||||||
.options({
|
.options({
|
||||||
l: {
|
locale: {
|
||||||
alias: ['locale'],
|
alias: ['l'],
|
||||||
describe: 'Locale to be merged into',
|
describe: 'Locale to be merged into',
|
||||||
demandOption: true,
|
demandOption: true,
|
||||||
type: 'string',
|
type: 'string',
|
||||||
nargs: 1,
|
nargs: 1,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.usage('$0 create -l <locale>');
|
.usage('$0 create --locale <locale>');
|
||||||
},
|
},
|
||||||
async (args) => {
|
async (args) => {
|
||||||
await createTranslationFiles(String(args.l).toLowerCase() as string);
|
await createTranslationFiles(args.locale);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.example([
|
.example([
|
||||||
['$0 merge -l en -f ./to-merge.suml', 'Merge pending translations into the English (en) locale'],
|
['$0 merge --locale en --file ./to-merge.suml', 'Merge pending translations into the English (en) locale'],
|
||||||
['$0 create -l he', 'Create a new Hebrew (he) locale'],
|
['$0 create --locale he', 'Create a new Hebrew (he) locale'],
|
||||||
])
|
])
|
||||||
.usage('$0 <command> [options]')
|
.usage('$0 <command> [options]')
|
||||||
.showHelpOnFail(false, 'Specify --help for available options')
|
.showHelpOnFail(false, 'Specify --help for available options')
|
Loading…
x
Reference in New Issue
Block a user