refactor: improve locale parsing and normalization in localization ge… (#3330)

* refactor: improve locale parsing and normalization in localization generation script

* Remove chinese tranditional because it's breaking flutter

* delete retry in case of parallel save [skip ci]

* Improve translation
This commit is contained in:
Omar Hatem
2026-06-17 23:09:35 +02:00
committed by GitHub
parent 241503774f
commit 29684affc2
35 changed files with 1819 additions and 1695 deletions
+11 -4
View File
@@ -51,12 +51,19 @@ Future<void> main(List<String> args) async {
final localePath = <String, dynamic>{};
await dir.list(recursive: false).forEach((element) {
try {
final shortLocale = element.path.split('_',)[1].split('.')[0];
localePath[shortLocale] = element.path;
} catch (e) {
// Parse the locale from the file name (e.g. strings_pt_br.arb -> pt_BR),
// normalizing the case so keys match LanguageService.supportedLocales.
final fileName = element.uri.pathSegments.last;
if (!fileName.startsWith('strings_') || !fileName.endsWith('.arb')) {
printV('Wrong file: ${element.path}');
return;
}
final parts =
fileName.substring('strings_'.length, fileName.length - '.arb'.length).split('_');
final locale = parts.length > 1
? '${parts.first.toLowerCase()}_${parts.sublist(1).join('_').toUpperCase()}'
: parts.first.toLowerCase();
localePath[locale] = element.path;
});
if (!localePath.keys.contains(defaultLocale)) {
@@ -2,5 +2,5 @@ const defaultLang = "en";
const langs = [
"ar", "bg", "cs", "de", "en", "es", "fa", "fr", "gn", "ha", "hi", "hr", "hy", "id", "it",
"ja", "ko", "my", "nl", "pl", "pt", "ru", "th", "tl", "tr", "uk", "ur", "yo",
"vi", "zh-cn", "zh-tw" // zh-cn for Chinese (Simplified), zh-tw for Chinese (Traditional)
"vi", "zh-cn" // zh-cn for Chinese (Simplified)
];