From 0ef185f7450946d30d2b12211fe15e856ebe0651 Mon Sep 17 00:00:00 2001 From: vivian Date: Thu, 10 Oct 2024 16:44:09 -0400 Subject: [PATCH] add isFullTranslation argument for CLI --- src/cli/translate.ts | 14 +++++++++++--- src/sdk/index.ts | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cli/translate.ts b/src/cli/translate.ts index 988c9cd..eff3a59 100644 --- a/src/cli/translate.ts +++ b/src/cli/translate.ts @@ -10,7 +10,7 @@ const ORIGIN_LANGUAGE_DIR = process.env.ORIGIN_LANGUAGE_TRANSLATION_PATH!; const FRENGLISH_API_KEY = process.env.FRENGLISH_API_KEY; const TRANSLATION_PATH = process.env.TRANSLATION_PATH!; -export async function translate(customPath: string = TRANSLATION_PATH) { +export async function translate(customPath: string = TRANSLATION_PATH, isFullTranslation: boolean = false) { try { if (!FRENGLISH_API_KEY) { throw new Error('FRENGLISH_API_KEY environment variable is not set'); @@ -44,8 +44,9 @@ export async function translate(customPath: string = TRANSLATION_PATH) { console.log('Files to translate:', fileIDs); console.log('Uploading files and creating translation...'); + console.log('Is full translation:', isFullTranslation); - const translationResponse = await frenglish.translate(fileIDs as [], contents as []); + const translationResponse = await frenglish.translate(fileIDs as [], contents as [], isFullTranslation); if (translationResponse && translationResponse.content) { for (const languageData of translationResponse.content) { @@ -87,18 +88,25 @@ if (require.main === module) { type: 'string', description: 'Specify a custom path for translation (file or directory, overrides TRANSLATION_PATH)', default: ORIGIN_LANGUAGE_DIR + }, + isFullTranslation: { + type: 'boolean', + description: 'Perform a full translation instead of just comparing with existing translation files', + default: false } }) .example('$0 translate', 'Translate files using the default TRANSLATION_PATH') .example('$0 translate --path "./custom/path/file.json"', 'Translate a specific JSON file') .example('$0 translate --path "./custom/path"', 'Translate all files in a custom directory') + .example('$0 translate --isFullTranslation=true', 'Perform a full translation on all files in directory specified by TRANSLATION_PATH') + .example('$0 translate --path "./custom/path" --isFullTranslation=true', 'Perform a full translation on files in a custom directory') .help('h') .alias('h', 'help') .epilog('For more information, visit https://www.frenglish.ai') .parse(); if (argv._.includes('translate')) { - translate(argv.path as string); + translate(argv.path as string, argv.isFullTranslation as boolean); } else { yargs.showHelp(); } diff --git a/src/sdk/index.ts b/src/sdk/index.ts index 1ef960e..1ec5de9 100644 --- a/src/sdk/index.ts +++ b/src/sdk/index.ts @@ -30,7 +30,7 @@ class FrenglishSDK { } // Send a translation request to Frenglish! - async translate(filenames: [], content: []): Promise { + async translate(filenames: [], content: [], fullTranslation: boolean = false): Promise { const POLLING_INTERVAL = 5000 // 5 seconds const MAX_POLLING_TIME = 1800000 // 30 minutes const startTime = Date.now() @@ -42,7 +42,7 @@ class FrenglishSDK { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.apiKey}`, }, - body: JSON.stringify({ filenames, content, apiKey: this.apiKey }), + body: JSON.stringify({ filenames, content, apiKey: this.apiKey, fullTranslation }), }); if (!response.ok) {