diff --git a/lib/l10n/.gitignore b/lib/l10n/.gitignore index 1a05426d..d0e30b82 100644 --- a/lib/l10n/.gitignore +++ b/lib/l10n/.gitignore @@ -1,2 +1,3 @@ # Do not track the collected translation files -collected/ \ No newline at end of file +collected/ +supported_locales.dart diff --git a/lib/l10n/collect_translations.py b/lib/l10n/collect_translations.py index 9b5c0628..e6ce6f17 100644 --- a/lib/l10n/collect_translations.py +++ b/lib/l10n/collect_translations.py @@ -15,8 +15,6 @@ import glob from posixpath import dirname import shutil import re -import json -import sys def process_locale_file(filename, locale_name): """ @@ -84,11 +82,38 @@ def copy_locale_file(path): process_locale_file(fallback_file, locale) +def generate_locale_list(locales): + """ + Generate a .dart file which contains all the supported locales, + for importing into the project + """ + + with open("supported_locales.dart", "w") as output: + + output.write("// This file is auto-generated by the 'collect_translations.py' script - do not edit it directly!\n\n") + + output.write('import "package:flutter/material.dart";\n\n') + + output.write("const List supported_locales = [\n"); + + for locale in locales: + splt = locale.split("_") + + if len(splt) == 2: + lc, cc = splt + else: + lc = locale + cc = '' + + output.write(f' const Locale("{lc}", "{cc}"), // Translations avilable in app_{locale}.arb\n') + + output.write("];\n") + output.write("") + if __name__ == '__main__': here = os.path.abspath(os.path.dirname(__file__)) - # Ensure the 'collected' output directory exists output_dir = os.path.join(here, 'collected') os.makedirs(output_dir, exist_ok=True) @@ -99,7 +124,7 @@ if __name__ == '__main__': for arb in arbs: os.remove(arb) - locales = [] + locales = ['en'] for locale in os.listdir(here): @@ -111,6 +136,7 @@ if __name__ == '__main__': if os.path.exists(f) and os.path.isdir(locale): copy_locale_file(f) + locales.append(locale) # Ensure the translation source file ('app_en.arb') is copied also # Note that this does not require any further processing @@ -118,3 +144,7 @@ if __name__ == '__main__': dst = os.path.join(here, 'collected', 'app_en.arb') shutil.copyfile(src, dst) + + generate_locale_list(locales) + + print(f"Updated translations for {len(locales)} locales.") diff --git a/lib/main.dart b/lib/main.dart index e52a8ff5..f8062e39 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,6 +12,9 @@ import "package:inventree/inventree/sentry.dart"; import "package:inventree/dsn.dart"; import "package:inventree/widget/home.dart"; +// Supported translations are automatically updated +import "package:inventree/l10n/supported_locales.dart"; + Future main() async { @@ -69,36 +72,9 @@ class InvenTreeApp extends StatelessWidget { I18N.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, ], - supportedLocales: [ - const Locale("cs", ""), // Czech - const Locale("de", ""), // German - const Locale("el", ""), // Greek - const Locale("en", ""), // English - const Locale("es-ES", ""), // Spanish - const Locale("es-MX", ""), // Spanish (mexican) - const Locale("fa", ""), // Farsi (Persian) - const Locale("fr", ""), // French - const Locale("he", ""), // Hebrew - const Locale("hu", ""), // Hungarian - const Locale("id", ""), // Indonesian - const Locale("it", ""), // Italian - const Locale("ja", ""), // Japanese - const Locale("ko", ""), // Korean - const Locale("nl", ""), // Dutch - const Locale("no", ""), // Norwegian - const Locale("pl", ""), // Polish - const Locale("pt", ""), // Portuguese - const Locale("pt-BR", ""), - const Locale("ru", ""), // Russian - const Locale("sv", ""), // Swedish - const Locale("th", ""), // Thai - const Locale("tr", ""), // Turkish - const Locale("vi", ""), // Vietnamese - const Locale("zh-CN", ""), // Chinese - ], - + locale: const Locale("hu"), + supportedLocales: supported_locales, ); } } \ No newline at end of file