Skip to content

Commit 7ef27cc

Browse files
authored
Merge pull request #11 from session-foundation/feature/multiple-ios-constants-paths
Added support for multiple ios constants files
2 parents 9fa3ad1 + cc6c52f commit 7ef27cc

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

.github/workflows/check_for_crowdin_updates.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,16 @@ jobs:
8686
python "${{ github.workspace }}/scripts/crowdin/generate_ios_strings.py" \
8787
"${{ github.workspace }}/raw_translations" \
8888
"${{ github.workspace }}/ios/Session/Meta/Translations" \
89-
"${{ github.workspace }}/ios/SessionUtilitiesKit/General/Constants.swift"
89+
"${{ github.workspace }}/ios/SessionUIKit/Style Guide/Constants.swift" \
90+
"${{ github.workspace }}/ios/SessionNotificationServiceExtension/NSEConstants.swift"
9091
- name: Upload iOS artefacts
9192
uses: actions/upload-artifact@v4
9293
with:
9394
name: session-ios
9495
path: |
9596
${{ github.workspace }}/ios/Session/Meta/Translations/Localizable.xcstrings
96-
${{ github.workspace }}/ios/SessionUtilitiesKit/General/Constants.swift
97+
${{ github.workspace }}/ios/SessionUIKit/Style Guide/Constants.swift
98+
${{ github.workspace }}/ios/SessionNotificationServiceExtension/NSEConstants.swift
9799
overwrite: true
98100
if-no-files-found: warn
99101
retention-days: 7

crowdin/generate_ios_strings.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@
2525
parser = argparse.ArgumentParser(description='Convert a XLIFF translation files to Apple String Catalog.')
2626
parser.add_argument('raw_translations_directory', help='Directory which contains the raw translation files')
2727
parser.add_argument('translations_output_directory', help='Directory to save the converted translation files')
28-
parser.add_argument('non_translatable_strings_output_path', help='Path to save the non-translatable strings to')
28+
parser.add_argument(
29+
'non_translatable_strings_output_paths',
30+
nargs='+', # Expect one or more arguments
31+
help='Paths to save the non-translatable strings to'
32+
)
2933
args = parser.parse_args()
3034

3135
INPUT_DIRECTORY = args.raw_translations_directory
3236
TRANSLATIONS_OUTPUT_DIRECTORY = args.translations_output_directory
33-
NON_TRANSLATABLE_STRINGS_OUTPUT_PATH = args.non_translatable_strings_output_path
37+
NON_TRANSLATABLE_STRINGS_OUTPUT_PATHS = args.non_translatable_strings_output_paths
3438

3539
def filter_and_map_language_ids(target_languages):
3640
result = []
@@ -222,32 +226,35 @@ def convert_xliff_to_string_catalog(input_dir, output_dir, source_language, targ
222226
# the `xcstrings` so if we don't then there is an absurd number of diffs...
223227
json.dump(sorted_string_catalog, f, ensure_ascii=False, indent=2, separators=(',', ' : '))
224228

225-
def convert_non_translatable_strings_to_swift(input_file, output_path):
229+
def convert_non_translatable_strings_to_swift(input_file, output_paths):
226230
glossary_dict = load_glossary_dict(input_file)
227231

228232
# Output the file in the desired format
229-
Path(output_path).parent.mkdir(parents=True, exist_ok=True)
230-
231-
with open(output_path, 'w', encoding='utf-8') as file:
232-
file.write(f'// Copyright © {datetime.now().year} Rangeproof Pty Ltd. All rights reserved.\n')
233-
file.write('// This file is automatically generated and maintained, do not manually edit it.\n')
234-
file.write('//\n')
235-
file.write('// stringlint:disable\n')
236-
file.write('\n')
237-
file.write('public enum Constants {\n')
238-
for key in glossary_dict:
239-
text = glossary_dict[key]
240-
file.write(f' public static let {key}: String = "{text}"\n')
241-
242-
file.write('}\n')
233+
for path in output_paths:
234+
Path(path).parent.mkdir(parents=True, exist_ok=True)
235+
filename = os.path.basename(path)
236+
enum_name, ext = os.path.splitext(filename)
237+
238+
with open(path, 'w', encoding='utf-8') as file:
239+
file.write(f'// Copyright © {datetime.now().year} Rangeproof Pty Ltd. All rights reserved.\n')
240+
file.write('// This file is automatically generated and maintained, do not manually edit it.\n')
241+
file.write('//\n')
242+
file.write('// stringlint:disable\n')
243+
file.write('\n')
244+
file.write(f'public enum {enum_name} {{\n')
245+
for key in glossary_dict:
246+
text = glossary_dict[key]
247+
file.write(f' public static let {key}: String = "{text}"\n')
248+
249+
file.write('}\n')
243250

244251
def convert_all_files(input_directory):
245252
setup_values = setup_generation(input_directory)
246253
source_language, rtl_languages, non_translatable_strings_file, target_languages = setup_values.values()
247254
glossary_dict = load_glossary_dict(non_translatable_strings_file)
248255
print(f"\033[2K{Fore.WHITE}⏳ Generating static strings file...{Style.RESET_ALL}", end='\r')
249256

250-
convert_non_translatable_strings_to_swift(non_translatable_strings_file, NON_TRANSLATABLE_STRINGS_OUTPUT_PATH)
257+
convert_non_translatable_strings_to_swift(non_translatable_strings_file, NON_TRANSLATABLE_STRINGS_OUTPUT_PATHS)
251258
print(f"\033[2K{Fore.GREEN}✅ Static string generation complete{Style.RESET_ALL}")
252259

253260
# Convert the XLIFF data to the desired format

0 commit comments

Comments
 (0)