Skip to content

Commit

Permalink
add isFullTranslation argument for CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
viv-cheung committed Oct 10, 2024
1 parent faae4b5 commit 0ef185f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/cli/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FrenglishSDK {
}

// Send a translation request to Frenglish!
async translate(filenames: [], content: []): Promise<RequestTranslationResponse | undefined> {
async translate(filenames: [], content: [], fullTranslation: boolean = false): Promise<RequestTranslationResponse | undefined> {
const POLLING_INTERVAL = 5000 // 5 seconds
const MAX_POLLING_TIME = 1800000 // 30 minutes
const startTime = Date.now()
Expand All @@ -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) {
Expand Down

0 comments on commit 0ef185f

Please sign in to comment.