diff --git a/.github/workflows/check_for_crowdin_updates.yml b/.github/workflows/check_for_crowdin_updates.yml index daaa286..8442f89 100644 --- a/.github/workflows/check_for_crowdin_updates.yml +++ b/.github/workflows/check_for_crowdin_updates.yml @@ -86,14 +86,16 @@ jobs: python "${{ github.workspace }}/scripts/crowdin/generate_ios_strings.py" \ "${{ github.workspace }}/raw_translations" \ "${{ github.workspace }}/ios/Session/Meta/Translations" \ - "${{ github.workspace }}/ios/SessionUtilitiesKit/General/Constants.swift" + "${{ github.workspace }}/ios/SessionUIKit/Style Guide/Constants.swift" \ + "${{ github.workspace }}/ios/SessionNotificationServiceExtension/NSEConstants.swift" - name: Upload iOS artefacts uses: actions/upload-artifact@v4 with: name: session-ios path: | ${{ github.workspace }}/ios/Session/Meta/Translations/Localizable.xcstrings - ${{ github.workspace }}/ios/SessionUtilitiesKit/General/Constants.swift + ${{ github.workspace }}/ios/SessionUIKit/Style Guide/Constants.swift + ${{ github.workspace }}/ios/SessionNotificationServiceExtension/NSEConstants.swift overwrite: true if-no-files-found: warn retention-days: 7 diff --git a/crowdin/generate_ios_strings.py b/crowdin/generate_ios_strings.py index eb077f1..c8d6000 100644 --- a/crowdin/generate_ios_strings.py +++ b/crowdin/generate_ios_strings.py @@ -25,12 +25,16 @@ parser = argparse.ArgumentParser(description='Convert a XLIFF translation files to Apple String Catalog.') parser.add_argument('raw_translations_directory', help='Directory which contains the raw translation files') parser.add_argument('translations_output_directory', help='Directory to save the converted translation files') -parser.add_argument('non_translatable_strings_output_path', help='Path to save the non-translatable strings to') +parser.add_argument( + 'non_translatable_strings_output_paths', + nargs='+', # Expect one or more arguments + help='Paths to save the non-translatable strings to' +) args = parser.parse_args() INPUT_DIRECTORY = args.raw_translations_directory TRANSLATIONS_OUTPUT_DIRECTORY = args.translations_output_directory -NON_TRANSLATABLE_STRINGS_OUTPUT_PATH = args.non_translatable_strings_output_path +NON_TRANSLATABLE_STRINGS_OUTPUT_PATHS = args.non_translatable_strings_output_paths def filter_and_map_language_ids(target_languages): result = [] @@ -222,24 +226,27 @@ def convert_xliff_to_string_catalog(input_dir, output_dir, source_language, targ # the `xcstrings` so if we don't then there is an absurd number of diffs... json.dump(sorted_string_catalog, f, ensure_ascii=False, indent=2, separators=(',', ' : ')) -def convert_non_translatable_strings_to_swift(input_file, output_path): +def convert_non_translatable_strings_to_swift(input_file, output_paths): glossary_dict = load_glossary_dict(input_file) # Output the file in the desired format - Path(output_path).parent.mkdir(parents=True, exist_ok=True) - - with open(output_path, 'w', encoding='utf-8') as file: - file.write(f'// Copyright © {datetime.now().year} Rangeproof Pty Ltd. All rights reserved.\n') - file.write('// This file is automatically generated and maintained, do not manually edit it.\n') - file.write('//\n') - file.write('// stringlint:disable\n') - file.write('\n') - file.write('public enum Constants {\n') - for key in glossary_dict: - text = glossary_dict[key] - file.write(f' public static let {key}: String = "{text}"\n') - - file.write('}\n') + for path in output_paths: + Path(path).parent.mkdir(parents=True, exist_ok=True) + filename = os.path.basename(path) + enum_name, ext = os.path.splitext(filename) + + with open(path, 'w', encoding='utf-8') as file: + file.write(f'// Copyright © {datetime.now().year} Rangeproof Pty Ltd. All rights reserved.\n') + file.write('// This file is automatically generated and maintained, do not manually edit it.\n') + file.write('//\n') + file.write('// stringlint:disable\n') + file.write('\n') + file.write(f'public enum {enum_name} {{\n') + for key in glossary_dict: + text = glossary_dict[key] + file.write(f' public static let {key}: String = "{text}"\n') + + file.write('}\n') def convert_all_files(input_directory): setup_values = setup_generation(input_directory) @@ -247,7 +254,7 @@ def convert_all_files(input_directory): glossary_dict = load_glossary_dict(non_translatable_strings_file) print(f"\033[2K{Fore.WHITE}⏳ Generating static strings file...{Style.RESET_ALL}", end='\r') - convert_non_translatable_strings_to_swift(non_translatable_strings_file, NON_TRANSLATABLE_STRINGS_OUTPUT_PATH) + convert_non_translatable_strings_to_swift(non_translatable_strings_file, NON_TRANSLATABLE_STRINGS_OUTPUT_PATHS) print(f"\033[2K{Fore.GREEN}✅ Static string generation complete{Style.RESET_ALL}") # Convert the XLIFF data to the desired format