Skip to content

Commit

Permalink
Merge pull request #21 from oxen-io/generate-strings-for-src-language
Browse files Browse the repository at this point in the history
fix: prepare strings needs to also include 'en'
  • Loading branch information
mpretty-cyro authored Sep 12, 2024
2 parents 35a02a4 + 7bdffc5 commit 313f12d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
2 changes: 1 addition & 1 deletion crowdin/generate_android_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion crowdin/generate_desktop_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
26 changes: 3 additions & 23 deletions crowdin/generate_ios_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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__":
Expand Down

0 comments on commit 313f12d

Please sign in to comment.