From 0e4032166e8d62d12d8b6f4539d7f75c0cd60919 Mon Sep 17 00:00:00 2001 From: Adil Hanney Date: Wed, 31 Jul 2024 23:51:48 +0100 Subject: [PATCH] scripts: use simply translate instead of lingva Lingva keeps failing --- scripts/translate_changelogs.dart | 14 +++++++------- scripts/translate_missing_translations.dart | 14 ++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/scripts/translate_changelogs.dart b/scripts/translate_changelogs.dart index 88629abc2..5963b4e99 100755 --- a/scripts/translate_changelogs.dart +++ b/scripts/translate_changelogs.dart @@ -15,8 +15,8 @@ import 'src/fix_spelling.dart'; const nearestLocaleCodes = { 'he': 'iw', - 'zh-Hans-CN': 'zh', - 'zh-Hant-TW': 'zh_HANT', + 'zh-Hans-CN': 'zh-cn', + 'zh-Hant-TW': 'zh-tw', }; Future getEnglishChangelog() async { @@ -101,18 +101,18 @@ void main() async { print('${' ' * stepPrefix.length} - Selected $nearestLocaleCode'); } - List translations; + String translatedChangelog; try { - translations = await translator - .translateLingva(englishChangelog, 'en', nearestLocaleCode) - .timeout(const Duration(seconds: 5)); + translatedChangelog = await translator + .translateSimply(englishChangelog, from: 'en', to: nearestLocaleCode) + .then((translation) => translation.translations.text) + .timeout(const Duration(seconds: 10)); } catch (e) { print('${' ' * stepPrefix.length} ! Translation failed, skipping...'); someTranslationsFailed = true; continue; } - var translatedChangelog = translations.first; translatedChangelog = fixSpelling(translatedChangelog); if (!translatedChangelog.endsWith('\n')) { // translations sometimes don't end with a newline diff --git a/scripts/translate_missing_translations.dart b/scripts/translate_missing_translations.dart index a174b9f49..68d7fc331 100755 --- a/scripts/translate_missing_translations.dart +++ b/scripts/translate_missing_translations.dart @@ -25,8 +25,8 @@ Future _getMissingTranslations() async { String _nearestLocaleCode(String localeCode) { const nearestLocaleCodes = { 'he': 'iw', - 'zh-Hans-CN': 'zh', - 'zh-Hant-TW': 'zh_HANT', + 'zh-Hans-CN': 'zh-cn', + 'zh-Hant-TW': 'zh-tw', }; if (LanguageList.contains(localeCode)) { @@ -139,10 +139,13 @@ Future translateString( ' Translating into $languageCode: ' '${english.length > 20 ? '${english.substring(0, 20)}...' : english}', ); - List translations; + + String translatedText; try { - translations = await translator - .translateLingva(english, 'en', _nearestLocaleCode(languageCode)) + translatedText = await translator + .translateSimply(english, + from: 'en', to: _nearestLocaleCode(languageCode)) + .then((translation) => translation.translations.text) .timeout(const Duration(seconds: 10)); } catch (e) { print(' Translation failed: $e'); @@ -150,7 +153,6 @@ Future translateString( return null; } - var translatedText = translations.first; final errorTexts = [ 'Invalid request', 'None is not supported',