From 7bdffc5068bae837bf737b0131db82629b77b0a4 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 12 Sep 2024 15:27:49 +1000 Subject: [PATCH] fix: prepare strings needs to also include 'en' --- crowdin/generate_android_strings.py | 2 +- crowdin/generate_desktop_strings.py | 2 +- crowdin/generate_ios_strings.py | 26 +++----------------------- 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/crowdin/generate_android_strings.py b/crowdin/generate_android_strings.py index 838bb2e..7e0f3a0 100644 --- a/crowdin/generate_android_strings.py +++ b/crowdin/generate_android_strings.py @@ -191,7 +191,7 @@ def convert_all_files(input_directory): # Convert the XLIFF data to the desired format print(f"\033[2K{Fore.WHITE}⏳ Converting translations to target format...{Style.RESET_ALL}", end='\r') source_locale = source_language['locale'] - for language in target_languages: + for language in [source_language] + target_languages: lang_locale = language['locale'] print(f"\033[2K{Fore.WHITE}⏳ Converting translations for {lang_locale} to target format...{Style.RESET_ALL}", end='\r') input_file = os.path.join(input_directory, f"{lang_locale}.xliff") diff --git a/crowdin/generate_desktop_strings.py b/crowdin/generate_desktop_strings.py index e47af78..2f014fb 100644 --- a/crowdin/generate_desktop_strings.py +++ b/crowdin/generate_desktop_strings.py @@ -159,7 +159,7 @@ def convert_all_files(input_directory): # Convert the XLIFF data to the desired format print(f"\033[2K{Fore.WHITE}⏳ Converting translations to target format...{Style.RESET_ALL}", end='\r') - for language in target_languages: + for language in [source_language] + target_languages: lang_locale = language['locale'] lang_two_letter_code = language['twoLettersCode'] print(f"\033[2K{Fore.WHITE}⏳ Converting translations for {lang_locale} to target format...{Style.RESET_ALL}", end='\r') diff --git a/crowdin/generate_ios_strings.py b/crowdin/generate_ios_strings.py index 6c4ef06..796320a 100644 --- a/crowdin/generate_ios_strings.py +++ b/crowdin/generate_ios_strings.py @@ -75,35 +75,15 @@ def convert_placeholders_for_plurals(resname, translations): return converted_translations -def convert_xliff_to_string_catalog(input_file, output_dir, locale, locale_two_letter_code): - if not os.path.exists(input_file): - raise FileNotFoundError(f"Could not find '{input_file}' in raw translations directory") - - # Parse the XLIFF and convert to XML - translations = parse_xliff(input_file) - sorted_translations = sorted(translations.items()) - converted_translations = {} - - for resname, target in sorted_translations: - converted_translations[resname] = generate_icu_pattern(target) - - # Generate output files - output_locale = LOCALE_PATH_MAPPING.get(locale, LOCALE_PATH_MAPPING.get(locale_two_letter_code, locale_two_letter_code)) - locale_output_dir = os.path.join(output_dir, output_locale) - output_file = os.path.join(locale_output_dir, 'messages.json') - os.makedirs(locale_output_dir, exist_ok=True) - - with open(output_file, 'w', encoding='utf-8') as f: - json.dump(converted_translations, f, ensure_ascii=False, indent=2) -def convert_xliff_to_string_catalog(input_dir, output_dir, target_languages): +def convert_xliff_to_string_catalog(input_dir, output_dir, source_language, target_languages): string_catalog = { "sourceLanguage": "en", "strings": {}, "version": "1.0" } - for language in target_languages: + for language in [source_language] + target_languages: lang_locale = language['locale'] input_file = os.path.join(input_dir, f"{lang_locale}.xliff") @@ -237,7 +217,7 @@ def convert_all_files(input_directory): # Convert the XLIFF data to the desired format print(f"\033[2K{Fore.WHITE}⏳ Converting translations to target format...{Style.RESET_ALL}", end='\r') - convert_xliff_to_string_catalog(input_directory, TRANSLATIONS_OUTPUT_DIRECTORY, target_languages) + convert_xliff_to_string_catalog(input_directory, TRANSLATIONS_OUTPUT_DIRECTORY, source_language, target_languages) print(f"\033[2K{Fore.GREEN}✅ All conversions complete{Style.RESET_ALL}") if __name__ == "__main__":