Skip to content

Commit

Permalink
feat: add language type #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ifyour committed Nov 16, 2023
1 parent d44d065 commit d3bdaee
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
31 changes: 31 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
export const API_URL = 'https://www2.deepl.com/jsonrpc';
export const REQUEST_ALTERNATIVES = 3;
export const SUPPORTED_LANGUAGES = [
'el',
'bg',
'lv',
'ko',
'lt',
'id',
'uk',
'sl',
'sk',
'tr',
'ro',
'cs',
'et',
'fi',
'da',
'hu',
'sv',
'nb',
'ru',
'pl',
'pt',
'nl',
'it',
'es',
'fr',
'de',
'ja',
'en',
'zh',
] as const;
4 changes: 2 additions & 2 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function buildRequestParams(sourceLang = 'auto', targetLang = 'en') {
timestamp: 0,
splitting: 'newlines',
lang: {
source_lang_user_selected: sourceLang,
target_lang: targetLang,
source_lang_user_selected: sourceLang?.toUpperCase(),
target_lang: targetLang?.toUpperCase(),
},
},
};
Expand Down
14 changes: 10 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { SUPPORTED_LANGUAGES } from './const';

type Lang = typeof SUPPORTED_LANGUAGES[number];
export type SourceLang = Lang | 'auto';
export type TargetLang = Lang;

export type RawResponseParams = {
jsonrpc: string;
id: number;
Expand All @@ -16,16 +22,16 @@ export type RawResponseParams = {

export type RequestParams = {
text: string;
source_lang: string;
target_lang: string;
source_lang: SourceLang;
target_lang: TargetLang;
};

export type ResponseParams = {
code: number;
message: string;
data: string | null;
source_lang?: string;
target_lang?: string;
source_lang?: SourceLang;
target_lang?: TargetLang;
alternatives?: string[];
};

Expand Down

0 comments on commit d3bdaee

Please sign in to comment.