Skip to content

Commit

Permalink
scripts: use simply translate instead of lingva
Browse files Browse the repository at this point in the history
Lingva keeps failing
  • Loading branch information
adil192 committed Jul 31, 2024
1 parent a68cc44 commit 0e40321
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
14 changes: 7 additions & 7 deletions scripts/translate_changelogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import 'src/fix_spelling.dart';

const nearestLocaleCodes = <String, String>{
'he': 'iw',
'zh-Hans-CN': 'zh',
'zh-Hant-TW': 'zh_HANT',
'zh-Hans-CN': 'zh-cn',
'zh-Hant-TW': 'zh-tw',
};

Future<String> getEnglishChangelog() async {
Expand Down Expand Up @@ -101,18 +101,18 @@ void main() async {
print('${' ' * stepPrefix.length} - Selected $nearestLocaleCode');
}

List<String> 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
Expand Down
14 changes: 8 additions & 6 deletions scripts/translate_missing_translations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Future<YamlMap> _getMissingTranslations() async {
String _nearestLocaleCode(String localeCode) {
const nearestLocaleCodes = <String, String>{
'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)) {
Expand Down Expand Up @@ -139,18 +139,20 @@ Future<String?> translateString(
' Translating into $languageCode: '
'${english.length > 20 ? '${english.substring(0, 20)}...' : english}',
);
List<String> 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');
errorOccurredInTranslatingTree = true;
return null;
}

var translatedText = translations.first;
final errorTexts = [
'Invalid request',
'None is not supported',
Expand Down

0 comments on commit 0e40321

Please sign in to comment.