Skip to content

Commit

Permalink
Fix translator option (#39)
Browse files Browse the repository at this point in the history
* fix issue in prompt.ts
see #36

* fix translator option
see #38
  • Loading branch information
Myshkouski authored Sep 17, 2023
1 parent e5ce2ec commit 1e7c661
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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),

Check failure on line 106 in src/cli/cli.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 16.x and ubuntu-latest

Delete `·`
TRANSLATE_POSTFIX

Check failure on line 107 in src/cli/cli.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 16.x and ubuntu-latest

Insert `,`
].join('') as Sources;
} else {
error(`${messages.cli.translator_not_available}`);
process.exit(1);
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Check failure on line 47 in src/index.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 16.x and ubuntu-latest

Insert `;`
export const translatorsNames = Object.values(Sources).map(s =>
s.split('Translate')[0].toLowerCase()
s.split(TRANSLATE_POSTFIX)[0].toLowerCase()
);
// TYPES
export interface translatedObject {
Expand Down

0 comments on commit 1e7c661

Please sign in to comment.