Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/check_for_crowdin_updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 25 additions & 18 deletions crowdin/generate_ios_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -222,32 +226,35 @@ 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)
source_language, rtl_languages, non_translatable_strings_file, target_languages = setup_values.values()
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
Expand Down