diff --git a/.github/workflows/ios.yaml b/.github/workflows/ios.yaml index 202c684b..039a6e9a 100644 --- a/.github/workflows/ios.yaml +++ b/.github/workflows/ios.yaml @@ -28,6 +28,10 @@ jobs: uses: subosito/flutter-action@v1 with: flutter-version: '2.10.3' + - name: Collect Translation Files + run: | + cd lib/l10n + python3 collect_translations.py - name: Build for iOS run: | flutter pub get diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index a9d3fe78..44b1ed3b 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -31,6 +31,10 @@ jobs: uses: subosito/flutter-action@v1 with: flutter-version: '2.10.3' + - name: Collect Translation Files + run: | + cd lib/l10n + python3 collect_translations.py - run: flutter pub get - run: cp lib/dummy_dsn.dart lib/dsn.dart - run: flutter analyze diff --git a/lib/l10n/.gitignore b/lib/l10n/.gitignore new file mode 100644 index 00000000..1a05426d --- /dev/null +++ b/lib/l10n/.gitignore @@ -0,0 +1,2 @@ +# Do not track the collected translation files +collected/ \ No newline at end of file diff --git a/lib/l10n/collect_translations.py b/lib/l10n/collect_translations.py new file mode 100644 index 00000000..f1987e30 --- /dev/null +++ b/lib/l10n/collect_translations.py @@ -0,0 +1,97 @@ +""" +Collect translation files into a single directory, +where they can be accessed by the flutter i18n library. + +Translations provided from crowdin are located in subdirectories, +but we need the .arb files to appear in this top level directory +to be accessed by the app. + +So, simply copy them here! + +""" + +import os +import shutil +import re +import json + +def process_locale_file(filename): + """ + Process a locale file after copying + + - Ensure the 'locale' matches + """ + + # Extract the locale name from the filename + f = os.path.basename(filename) + locale = re.search(r"^app\_(\w+)\.arb$", f).groups()[0] + + # TODO: Use JSON processing instead of manual + # Need to work out unicode issues for this to work + + with open(filename, 'r', encoding='utf-8') as input_file: + + lines = input_file.readlines() + + with open(filename, 'w', encoding='utf-8') as output_file: + # Using JSON processing would be simpler here, + # but it does not preserve unicode data! + for line in lines: + if '@@locale' in line: + new_line = f' "@@locale": "{locale}"' + + if ',' in line: + new_line += ',' + + new_line += '\n' + + line = new_line + + output_file.write(line) + + +def copy_locale_file(path): + """ + Locate and copy the locale file from the provided directory + """ + + here = os.path.abspath(os.path.dirname(__file__)) + + for f in os.listdir(path): + + src = os.path.join(path, f) + dst = os.path.join(here, 'collected', f) + + if os.path.exists(src) and os.path.isfile(src) and f.endswith('.arb'): + + shutil.copyfile(src, dst) + print(f"Copied file '{f}'") + + process_locale_file(dst) + + +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) + + for item in os.listdir(here): + + # Ignore the output directory + if item == 'collected': + continue + + f = os.path.join(here, item) + + if os.path.exists(f) and os.path.isdir(item): + copy_locale_file(f) + + # Ensure the translation source file ('app_en.arb') is copied also + # Note that this does not require any further processing + src = os.path.join(here, 'app_en.arb') + dst = os.path.join(here, 'collected', 'app_en.arb') + + shutil.copyfile(src, dst) diff --git a/lib/l10n/app_cs.arb b/lib/l10n/cs_CZ/app_cs_CZ.arb similarity index 100% rename from lib/l10n/app_cs.arb rename to lib/l10n/cs_CZ/app_cs_CZ.arb diff --git a/lib/l10n/app_de.arb b/lib/l10n/de_DE/app_de_DE.arb similarity index 100% rename from lib/l10n/app_de.arb rename to lib/l10n/de_DE/app_de_DE.arb diff --git a/lib/l10n/app_el.arb b/lib/l10n/el_GR/app_el_GR.arb similarity index 100% rename from lib/l10n/app_el.arb rename to lib/l10n/el_GR/app_el_GR.arb diff --git a/lib/l10n/app_es.arb b/lib/l10n/es_ES/app_es_ES.arb similarity index 100% rename from lib/l10n/app_es.arb rename to lib/l10n/es_ES/app_es_ES.arb diff --git a/lib/l10n/es_MX/app_es_MX.arb b/lib/l10n/es_MX/app_es_MX.arb new file mode 100644 index 00000000..36d80aae --- /dev/null +++ b/lib/l10n/es_MX/app_es_MX.arb @@ -0,0 +1,5 @@ +{ + "@@locale": "en", + "@homeShowSubscsribedDescription": {}, + "@homeShowSupplierDescription": {} +} \ No newline at end of file diff --git a/lib/l10n/app_fa.arb b/lib/l10n/fa_IR/app_fa_IR.arb similarity index 100% rename from lib/l10n/app_fa.arb rename to lib/l10n/fa_IR/app_fa_IR.arb diff --git a/lib/l10n/app_fr.arb b/lib/l10n/fr_FR/app_fr_FR.arb similarity index 100% rename from lib/l10n/app_fr.arb rename to lib/l10n/fr_FR/app_fr_FR.arb diff --git a/lib/l10n/app_he.arb b/lib/l10n/he_IL/app_he_IL.arb similarity index 100% rename from lib/l10n/app_he.arb rename to lib/l10n/he_IL/app_he_IL.arb diff --git a/lib/l10n/app_hu.arb b/lib/l10n/hu_HU/app_hu_HU.arb similarity index 100% rename from lib/l10n/app_hu.arb rename to lib/l10n/hu_HU/app_hu_HU.arb diff --git a/lib/l10n/app_id.arb b/lib/l10n/id_ID/app_id_ID.arb similarity index 100% rename from lib/l10n/app_id.arb rename to lib/l10n/id_ID/app_id_ID.arb diff --git a/lib/l10n/app_it.arb b/lib/l10n/it_IT/app_it_IT.arb similarity index 100% rename from lib/l10n/app_it.arb rename to lib/l10n/it_IT/app_it_IT.arb diff --git a/lib/l10n/app_ja.arb b/lib/l10n/ja_JP/app_ja_JP.arb similarity index 100% rename from lib/l10n/app_ja.arb rename to lib/l10n/ja_JP/app_ja_JP.arb diff --git a/lib/l10n/app_ko.arb b/lib/l10n/ko_KR/app_ko_KR.arb similarity index 100% rename from lib/l10n/app_ko.arb rename to lib/l10n/ko_KR/app_ko_KR.arb diff --git a/lib/l10n/app_nl.arb b/lib/l10n/nl_NL/app_nl_NL.arb similarity index 100% rename from lib/l10n/app_nl.arb rename to lib/l10n/nl_NL/app_nl_NL.arb diff --git a/lib/l10n/app_no.arb b/lib/l10n/no_NO/app_no_NO.arb similarity index 100% rename from lib/l10n/app_no.arb rename to lib/l10n/no_NO/app_no_NO.arb diff --git a/lib/l10n/app_pl.arb b/lib/l10n/pl_PL/app_pl_PL.arb similarity index 100% rename from lib/l10n/app_pl.arb rename to lib/l10n/pl_PL/app_pl_PL.arb diff --git a/lib/l10n/pt_BR/app_pt_BR.arb b/lib/l10n/pt_BR/app_pt_BR.arb new file mode 100644 index 00000000..36d80aae --- /dev/null +++ b/lib/l10n/pt_BR/app_pt_BR.arb @@ -0,0 +1,5 @@ +{ + "@@locale": "en", + "@homeShowSubscsribedDescription": {}, + "@homeShowSupplierDescription": {} +} \ No newline at end of file diff --git a/lib/l10n/app_pt.arb b/lib/l10n/pt_PT/app_pt_PT.arb similarity index 100% rename from lib/l10n/app_pt.arb rename to lib/l10n/pt_PT/app_pt_PT.arb diff --git a/lib/l10n/app_ru.arb b/lib/l10n/ru_RU/app_ru_RU.arb similarity index 100% rename from lib/l10n/app_ru.arb rename to lib/l10n/ru_RU/app_ru_RU.arb diff --git a/lib/l10n/app_sv.arb b/lib/l10n/sv_SE/app_sv_SE.arb similarity index 100% rename from lib/l10n/app_sv.arb rename to lib/l10n/sv_SE/app_sv_SE.arb diff --git a/lib/l10n/app_th.arb b/lib/l10n/th_TH/app_th_TH.arb similarity index 100% rename from lib/l10n/app_th.arb rename to lib/l10n/th_TH/app_th_TH.arb diff --git a/lib/l10n/app_tr.arb b/lib/l10n/tr_TR/app_tr_TR.arb similarity index 100% rename from lib/l10n/app_tr.arb rename to lib/l10n/tr_TR/app_tr_TR.arb diff --git a/lib/l10n/app_vi.arb b/lib/l10n/vi_VN/app_vi_VN.arb similarity index 100% rename from lib/l10n/app_vi.arb rename to lib/l10n/vi_VN/app_vi_VN.arb diff --git a/lib/l10n/app_zh.arb b/lib/l10n/zh_CN/app_zh_CN.arb similarity index 100% rename from lib/l10n/app_zh.arb rename to lib/l10n/zh_CN/app_zh_CN.arb