From 1e7c6614e468022ccc5b63e42e19b0824799a8f0 Mon Sep 17 00:00:00 2001 From: Alexei Date: Sun, 17 Sep 2023 14:08:56 +0300 Subject: [PATCH] Fix translator option (#39) * fix issue in prompt.ts see https://github.com/mololab/json-translator/issues/36 * fix translator option see https://github.com/mololab/json-translator/issues/38 --- src/cli/cli.ts | 8 ++++++-- src/index.ts | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 23af7bc..8667f58 100644 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -1,4 +1,4 @@ -import { listIOS, Sources, translatorsNames } from '..'; +import { listIOS, Sources, TRANSLATE_POSTFIX, translatorsNames } from '..'; import { fileTranslator, getFileFromPath } from '../core/json_file'; import { error, @@ -101,7 +101,11 @@ async function translate() { let translator = translatorsNames.find((el: string) => el.includes(translatorInput as string) ); - global.source = capitalize(translator as string) as Sources; + // Restore source name after splitting it for "translatorsNames" variable + global.source = [ + capitalize(translator as string), + TRANSLATE_POSTFIX + ].join('') as Sources; } else { error(`${messages.cli.translator_not_available}`); process.exit(1); diff --git a/src/index.ts b/src/index.ts index a7b3459..bc126ba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,8 +43,10 @@ export enum Sources { // default global.source = Sources.GoogleTranslate; +// Use postfix just for compatability, when Sources enum values used somewhere else. +export const TRANSLATE_POSTFIX = 'Translate' export const translatorsNames = Object.values(Sources).map(s => - s.split('Translate')[0].toLowerCase() + s.split(TRANSLATE_POSTFIX)[0].toLowerCase() ); // TYPES export interface translatedObject {