From aec93b25a4b305443b5040b3dde8eda6c180bf61 Mon Sep 17 00:00:00 2001 From: Dejan Zdravkovic Date: Thu, 22 Feb 2024 20:53:03 +0100 Subject: [PATCH] spaces option --- README.md | 1 + src/translate/cli.ts | 7 +++++++ src/translate/translate.ts | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b646c69..ba196df 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ $ i18n-auto-translation -k SUBSCRIPTION_KEY -d PROJECT_DIR -t DESIRED_LANGUAGE | --to [required] | -t | To which language you want to translate. | / | | --override | -o | Override all created i18n JSON files. | false | | --certificatePath | -c | Path to a custom certificate. | / | +| --spaces | -s | Number of spaces to use when generating output JSON files. | 2 | ## Demo diff --git a/src/translate/cli.ts b/src/translate/cli.ts index 847492b..fe444b4 100644 --- a/src/translate/cli.ts +++ b/src/translate/cli.ts @@ -11,6 +11,7 @@ interface Arguments { to: string; override: boolean; certificatePath?: string; + spaces: number; } export const argv: Arguments = yargs(process.argv.slice(2)) @@ -78,5 +79,11 @@ export const argv: Arguments = yargs(process.argv.slice(2)) alias: 'c', description: 'Path to a custom certificate.', }, + spaces: { + type: 'number', + alias: 's', + description: 'Number of spaces to use when generating output JSON files.', + default: 2, + }, }) .parseSync(); diff --git a/src/translate/translate.ts b/src/translate/translate.ts index 6c3c7e0..96e9466 100644 --- a/src/translate/translate.ts +++ b/src/translate/translate.ts @@ -217,7 +217,7 @@ export abstract class Translate { private writeToFile = (content: JSONObj, saveTo: string, message: string): void => { try { - fs.writeFileSync(saveTo, JSON.stringify(content, null, 2)); + fs.writeFileSync(saveTo, JSON.stringify(content, null, argv.spaces)); console.log(message); } catch (e) { console.log((e as Error).message);