Skip to content

Commit

Permalink
feat: add support for all translation modules in package (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoobzio authored Oct 3, 2024
1 parent 6556e46 commit 5db4897
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 39 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ This package will provide you to translate your JSON/YAML files or JSON objects

### ⏳ Package Support:

| Translation Module | Support | FREE |
| :----------------------: | :-----: | :-------: |
| Google Translate || `✅ FREE` |
| Google Translate 2 | | |
| Microsoft Bing Translate | | |
| Libre Translate | | |
| Argos Translate | | |
| DeepL Translate | | |
| gpt-4o | | |
| gpt-3.5-turbo | | |
| gpt-4 | | |
| gpt-4o-mini | | |
| Translation Module | Support | FREE |
| :----------------------: | :-----: | :---------------------------------------: |
| Google Translate || `✅ FREE` |
| Google Translate 2 | | `✅ FREE` |
| Microsoft Bing Translate | | `✅ FREE` |
| Libre Translate | | `✅ FREE` |
| Argos Translate | | `✅ FREE` |
| DeepL Translate | | `require API KEY (DEEPL_API_KEY as env)` |
| gpt-4o | | `require API KEY (OPENAI_API_KEY as env)` |
| gpt-3.5-turbo | | `require API KEY (OPENAI_API_KEY as env)` |
| gpt-4 | | `require API KEY (OPENAI_API_KEY as env)` |
| gpt-4o-mini | | `require API KEY (OPENAI_API_KEY as env)` |

`Browser support will come soon...`

Expand Down
44 changes: 17 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,38 @@ import { objectTranslator } from './core/json_object';
import { TranslationConfig, TranslationModules } from './modules/modules';
import { default_concurrency_limit, default_fallback } from './utils/micro';

// TODO: fix to get from user
export async function translateWord(word: string, from: string, to: string) {
let config: TranslationConfig = {
moduleKey: 'google',
TranslationModule: TranslationModules['google'],
concurrencyLimit: default_concurrency_limit,
fallback: default_fallback,
};

const defaults: TranslationConfig = {
moduleKey: 'google',
TranslationModule: TranslationModules['google'],
concurrencyLimit: default_concurrency_limit,
fallback: default_fallback,
};

export async function translateWord(
word: string,
from: string,
to: string,
config: TranslationConfig = defaults
) {
return await plaintranslate(config, word, from, to, []);
}
// TODO: fix to get from user
export async function translateObject(
object: translatedObject,
from: string,
to: string[]
to: string[],
config: TranslationConfig = defaults
): Promise<translatedObject | translatedObject[]> {
let hard_copy = JSON.parse(JSON.stringify(object));

let config: TranslationConfig = {
moduleKey: 'google',
TranslationModule: TranslationModules['google'],
concurrencyLimit: default_concurrency_limit,
fallback: default_fallback,
};

return objectTranslator(config, hard_copy, from, to);
}

export async function translateFile(
objectPath: string,
from: string,
to: string[],
newFileName: string
newFileName: string,
config: TranslationConfig = defaults
) {
let config: TranslationConfig = {
moduleKey: 'google',
TranslationModule: TranslationModules['google'],
concurrencyLimit: default_concurrency_limit,
fallback: default_fallback,
};

return fileTranslator(config, objectPath, from, to, newFileName);
}

Expand Down

0 comments on commit 5db4897

Please sign in to comment.