Skip to content

Commit

Permalink
Fixed the sorting and formatting for iOS to match what Xcode generates
Browse files Browse the repository at this point in the history
  • Loading branch information
mpretty-cyro committed Oct 3, 2024
1 parent 53a47e0 commit b836081
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crowdin/generate_ios_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ def convert_xliff_to_string_catalog(input_dir, output_dir, source_language, targ
"version": "1.0"
}

for language in [source_language] + target_languages:
# We need to sort the full language list (if the source language comes first rather than in alphabetical order
# then the output will differ from what Xcode generates)
all_languages = [source_language] + target_languages
sorted_languages = sorted(all_languages, key=lambda x: x['id'])

for language in sorted_languages:
lang_locale = language['locale']
input_file = os.path.join(input_dir, f"{lang_locale}.xliff")

Expand Down Expand Up @@ -165,7 +170,9 @@ def convert_xliff_to_string_catalog(input_dir, output_dir, source_language, targ
os.makedirs(output_dir, exist_ok=True)

with open(output_file, 'w', encoding='utf-8') as f:
json.dump(string_catalog, f, ensure_ascii=False, indent=2)
# We need to add spaces around the `:` in the output beacuse Xcode inserts one when opening
# the `xcstrings` so if we don't then there is an absurd number of diffs...
json.dump(string_catalog, f, ensure_ascii=False, indent=2, separators=(',', ' : '))

def convert_non_translatable_strings_to_swift(input_file, output_path):
if not os.path.exists(input_file):
Expand Down

0 comments on commit b836081

Please sign in to comment.