Skip to content

Commit

Permalink
fix(deepl): stipe locale code for deepl, close #622
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 12, 2021
1 parent e972a8c commit c976cdb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/translators/engines/deepl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ async function usage(): Promise<DeepLUsage> {
}
}

function stripeLocaleCode(locale?: string): string | undefined {
if (!locale)
return locale
const index = locale.indexOf('-')
if (index === -1)
return locale
return locale.slice(0, index)
}

class DeepL extends TranslateEngine {
async translate(options: TranslateOptions) {
try {
Expand All @@ -73,8 +82,8 @@ class DeepL extends TranslateEngine {
url: '/translate',
data: {
text: options.text,
source_lang: options.from || undefined,
target_lang: options.to,
source_lang: stripeLocaleCode(options.from || undefined),
target_lang: stripeLocaleCode(options.to),
},
}).then(({ data }) => data)

Expand Down

0 comments on commit c976cdb

Please sign in to comment.