diff --git a/README.md b/README.md index 4339d4c..f37c095 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,9 @@ $ npx i18n-auto-translation -k SUBSCRIPTION_KEY -d PROJECT_DIR -t DESIRED_LANGUA | --certificatePath | -c | Path to a custom certificate. | / | | --spaces | -s | Number of spaces to use when generating output JSON files. | 2 | | --maxLinesPerRequest | -l | Maximum number of lines per request. For every `x` number of lines, separated request is sent to the api. | 50 | -| --context | -x | Context for the translation. Used only by the DeepL API. | default | -| --formality | -m | Formality for the translation. Used only by the DeepL API. | / | +| --context | -x | Context for the translation. Used only by the DeepL API. | / | +| --formality | -m | Formality for the translation. Used only by the DeepL API. | default | +| --trim | -i | Trim string after translation. | true | ## Demo diff --git a/src/translate/cli.ts b/src/translate/cli.ts index 90a9a17..89b22b9 100644 --- a/src/translate/cli.ts +++ b/src/translate/cli.ts @@ -14,7 +14,8 @@ interface Arguments { spaces: number; maxLinesPerRequest: number; context?: string; - formality?: string; + formality: string; + trim: boolean; } export const argv: Arguments = yargs(process.argv.slice(2)) @@ -107,5 +108,11 @@ export const argv: Arguments = yargs(process.argv.slice(2)) choices: ['default', 'more', 'less', 'prefer_more', 'prefer_less'], default: 'default', }, + trim: { + type: 'boolean', + alias: 'i', + description: 'Trim string after translation.', + default: true, + }, }) .parseSync(); diff --git a/src/translate/providers/azure-rapid-api.ts b/src/translate/providers/azure-rapid-api.ts index e626f64..f366bc6 100644 --- a/src/translate/providers/azure-rapid-api.ts +++ b/src/translate/providers/azure-rapid-api.ts @@ -7,7 +7,7 @@ import { Translate } from '../translate'; import { addCustomCert } from '../util'; export class AzureRapidAPI extends Translate { - private static readonly endpoint: string = 'microsoft-translator-text.p.rapidapi.com'; + private static readonly endpoint: string = 'microsoft-translator-text-api3.p.rapidapi.com'; private static readonly axiosConfig: AxiosRequestConfig = { headers: { 'X-ClientTraceId': crypto.randomUUID(), @@ -16,7 +16,6 @@ export class AzureRapidAPI extends Translate { 'Content-type': 'application/json', }, params: { - 'api-version': '3.0', from: argv.from, to: argv.to, }, diff --git a/src/translate/translate.ts b/src/translate/translate.ts index f335fa2..e57ee4f 100644 --- a/src/translate/translate.ts +++ b/src/translate/translate.ts @@ -125,7 +125,7 @@ export abstract class Translate { private skipWords(value: string): string { return value.replace(Translate.skipWordRegex, (match: string) => { - this.skippedWords.push(match.trim()); + this.skippedWords.push(match); return `{{${this.skippedWords.length - 1}}}`; }); } @@ -190,7 +190,7 @@ export abstract class Translate { private saveTranslation = (translations: string, objectBeforeTranslation: JSONObj): void => { let objectAfterTranslation: JSONObj = this.createTranslatedObject( - translations.split(Translate.sentenceDelimiter.trim()), + translations.split(Translate.sentenceDelimiter), objectBeforeTranslation, ); if (fs.existsSync(this.saveTo) && !argv.override) { @@ -217,7 +217,7 @@ export abstract class Translate { if (typeof json[key] === 'object') { addTranslations(json[key] as JSONObj); } else { - json[key] = translations[index++]?.trim(); + json[key] = argv.trim ? translations[index++]?.trim() : translations[index++]; } }); })(translatedObject);