mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-27 21:16:48 +00:00
Auto generate a list of supported locales whenever translations are updated
This commit is contained in:
parent
5e4abcf68c
commit
71c16e0556
3
lib/l10n/.gitignore
vendored
3
lib/l10n/.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
# Do not track the collected translation files
|
||||
collected/
|
||||
collected/
|
||||
supported_locales.dart
|
||||
|
@ -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<Locale> 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.")
|
||||
|
@ -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<void> 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,
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user