Skip to content

Commit 7b34b58

Browse files
authored
Merge pull request #32 from oxen-io/fix/ios-sorting-and-formatting
Fixed the sorting and formatting for iOS to match what Xcode generates
2 parents 53a47e0 + b836081 commit 7b34b58

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

crowdin/generate_ios_strings.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ def convert_xliff_to_string_catalog(input_dir, output_dir, source_language, targ
8888
"version": "1.0"
8989
}
9090

91-
for language in [source_language] + target_languages:
91+
# We need to sort the full language list (if the source language comes first rather than in alphabetical order
92+
# then the output will differ from what Xcode generates)
93+
all_languages = [source_language] + target_languages
94+
sorted_languages = sorted(all_languages, key=lambda x: x['id'])
95+
96+
for language in sorted_languages:
9297
lang_locale = language['locale']
9398
input_file = os.path.join(input_dir, f"{lang_locale}.xliff")
9499

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

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

170177
def convert_non_translatable_strings_to_swift(input_file, output_path):
171178
if not os.path.exists(input_file):

0 commit comments

Comments
 (0)