From 85560e90c05faddffe342c95c239140e684e0602 Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Sun, 20 Aug 2023 21:50:11 -0400 Subject: [PATCH] Auto fix common language code issues (i.e. jp not ja) --- src/helpers/translate.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/helpers/translate.ts b/src/helpers/translate.ts index f6437df..8098df8 100644 --- a/src/helpers/translate.ts +++ b/src/helpers/translate.ts @@ -26,6 +26,21 @@ export const translateTweet = async ( let translationApiResponse; let translationResults: TranslationPartial; + /* Fix up some language codes that may be mistakenly used */ + switch(language) { + case 'jp': + language = 'ja'; + break; + case 'kr': + language = 'ko'; + break; + case 'ua': + language = 'uk'; + break; + default: + break; + } + headers['x-twitter-client-language'] = language; /* As of August 2023, you can no longer fetch translations with guest token */