|
25 | 25 | parser = argparse.ArgumentParser(description='Convert a XLIFF translation files to Apple String Catalog.')
|
26 | 26 | parser.add_argument('raw_translations_directory', help='Directory which contains the raw translation files')
|
27 | 27 | 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 | +) |
29 | 33 | args = parser.parse_args()
|
30 | 34 |
|
31 | 35 | INPUT_DIRECTORY = args.raw_translations_directory
|
32 | 36 | 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 |
34 | 38 |
|
35 | 39 | def filter_and_map_language_ids(target_languages):
|
36 | 40 | result = []
|
@@ -222,32 +226,35 @@ def convert_xliff_to_string_catalog(input_dir, output_dir, source_language, targ
|
222 | 226 | # the `xcstrings` so if we don't then there is an absurd number of diffs...
|
223 | 227 | json.dump(sorted_string_catalog, f, ensure_ascii=False, indent=2, separators=(',', ' : '))
|
224 | 228 |
|
225 |
| -def convert_non_translatable_strings_to_swift(input_file, output_path): |
| 229 | +def convert_non_translatable_strings_to_swift(input_file, output_paths): |
226 | 230 | glossary_dict = load_glossary_dict(input_file)
|
227 | 231 |
|
228 | 232 | # 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') |
243 | 250 |
|
244 | 251 | def convert_all_files(input_directory):
|
245 | 252 | setup_values = setup_generation(input_directory)
|
246 | 253 | source_language, rtl_languages, non_translatable_strings_file, target_languages = setup_values.values()
|
247 | 254 | glossary_dict = load_glossary_dict(non_translatable_strings_file)
|
248 | 255 | print(f"\033[2K{Fore.WHITE}⏳ Generating static strings file...{Style.RESET_ALL}", end='\r')
|
249 | 256 |
|
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) |
251 | 258 | print(f"\033[2K{Fore.GREEN}✅ Static string generation complete{Style.RESET_ALL}")
|
252 | 259 |
|
253 | 260 | # Convert the XLIFF data to the desired format
|
|
0 commit comments