app-localizer 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ """Translate Apple String Catalogs and Fastlane App Store metadata."""
2
+
3
+ __all__ = [
4
+ "StringsCatalogTranslator",
5
+ "TranslationConfig",
6
+ ]
7
+
8
+
9
+ def __getattr__(name):
10
+ if name in __all__:
11
+ from app_localizer.xcstrings import StringsCatalogTranslator, TranslationConfig
12
+
13
+ exports = {
14
+ "StringsCatalogTranslator": StringsCatalogTranslator,
15
+ "TranslationConfig": TranslationConfig,
16
+ }
17
+ return exports[name]
18
+
19
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -0,0 +1,603 @@
1
+ """Utilities for reading and mutating Apple String Catalog files."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from collections import Counter
7
+ from copy import deepcopy
8
+ from dataclasses import dataclass
9
+ from hashlib import sha256
10
+ from pathlib import Path
11
+ import re
12
+ from typing import Any, Dict, Iterator, Mapping, Optional, Tuple
13
+
14
+ from app_localizer.cldr import CATEGORY_ORDER, ordered_categories, required_cardinal_categories
15
+ from app_localizer.fileio import atomic_write_json
16
+
17
+ JsonObject = Dict[str, Any]
18
+
19
+ PLURAL_VARIATION_KEY = "plural"
20
+ CARDINAL_CATEGORIES = frozenset(CATEGORY_ORDER)
21
+
22
+ PRINTF_PLACEHOLDER_PATTERN = re.compile(
23
+ r"%(?:\d+\$)?[-+#0 ]*(?:\*|\d+)?(?:\.(?:\*|\d+))?"
24
+ r"(?:hh|h|ll|l|L|z|j|t)?[@diuoxXfFeEgGaAcspn%]"
25
+ )
26
+ POSITIONAL_PRINTF_PATTERN = re.compile(r"%\d+\$")
27
+ SWIFT_INTERPOLATION_PATTERN = re.compile(r"\\\([^)]+\)")
28
+ SUBSTITUTION_PLACEHOLDER_PATTERN = re.compile(r"%(?:\d+\$)?#@\w+@|%arg\b")
29
+
30
+
31
+ class CatalogError(Exception):
32
+ """Raised when a string catalog is missing required structure."""
33
+
34
+
35
+ @dataclass
36
+ class StringUnitReference:
37
+ """A mutable reference to a string unit inside a localization tree."""
38
+
39
+ key_path: str
40
+ string_unit: JsonObject
41
+
42
+
43
+ def load_catalog(path: Path) -> JsonObject:
44
+ """Load and validate a string catalog from disk."""
45
+ if not path.exists():
46
+ raise CatalogError(f"Catalog does not exist: {path}")
47
+ if not path.is_file():
48
+ raise CatalogError(f"Catalog path is not a file: {path}")
49
+
50
+ try:
51
+ with path.open("r", encoding="utf-8") as file:
52
+ catalog = json.load(file, object_pairs_hook=_object_rejecting_duplicate_keys)
53
+ except json.JSONDecodeError as error:
54
+ raise CatalogError(f"Catalog is not valid JSON: {error}") from error
55
+ except ValueError as error:
56
+ raise CatalogError(f"Catalog is not valid: {error}") from error
57
+ except OSError as error:
58
+ raise CatalogError(f"Catalog could not be read: {error}") from error
59
+
60
+ if not isinstance(catalog, dict):
61
+ raise CatalogError("Catalog root must be a JSON object.")
62
+ if not isinstance(catalog.get("sourceLanguage"), str):
63
+ raise CatalogError("Catalog must contain a string sourceLanguage.")
64
+ if not isinstance(catalog.get("strings"), dict):
65
+ raise CatalogError("Catalog must contain a strings object.")
66
+
67
+ version = catalog.get("version")
68
+ if version is not None and (
69
+ not isinstance(version, str) or version.split(".", 1)[0] != "1"
70
+ ):
71
+ raise CatalogError(
72
+ f"Catalog version {version!r} is not supported. Supported versions: 1.x."
73
+ )
74
+
75
+ return catalog
76
+
77
+
78
+ def write_catalog(path: Path, catalog: Mapping[str, Any]) -> None:
79
+ """Write a catalog atomically using Xcode-style JSON spacing."""
80
+ try:
81
+ atomic_write_json(path, catalog)
82
+ except OSError as error:
83
+ raise CatalogError(f"Catalog could not be written: {error}") from error
84
+
85
+
86
+ def ensure_source_localizations(catalog: JsonObject) -> bool:
87
+ """Ensure every string has a usable source localization."""
88
+ source_language = catalog["sourceLanguage"]
89
+ changed = False
90
+
91
+ for key, string_data in catalog["strings"].items():
92
+ if not isinstance(string_data, dict):
93
+ raise CatalogError(f"String entry {key!r} must be an object.")
94
+
95
+ localizations = string_data.get("localizations")
96
+ if not isinstance(localizations, dict):
97
+ localizations = {}
98
+ string_data["localizations"] = localizations
99
+ changed = True
100
+
101
+ source_localization = localizations.get(source_language)
102
+ if not isinstance(source_localization, dict) or not string_units_by_key_path(
103
+ source_localization, key
104
+ ):
105
+ localizations[source_language] = {
106
+ "stringUnit": {
107
+ "state": "translated",
108
+ "value": key,
109
+ }
110
+ }
111
+ changed = True
112
+
113
+ return changed
114
+
115
+
116
+ def ensure_target_localization(
117
+ string_data: JsonObject,
118
+ source_language: str,
119
+ target_language: str,
120
+ fallback_value: str,
121
+ ) -> Tuple[JsonObject, bool]:
122
+ """Return a target localization that contains every source string unit.
123
+
124
+ Also returns whether the target was created or mutated, so reconcile-only
125
+ changes (such as pruning stale substitutions) get persisted.
126
+ """
127
+ localizations = string_data["localizations"]
128
+ source_localization = localizations.get(source_language)
129
+ if not isinstance(source_localization, dict):
130
+ source_localization = {
131
+ "stringUnit": {
132
+ "state": "translated",
133
+ "value": fallback_value,
134
+ }
135
+ }
136
+
137
+ target_localization = localizations.get(target_language)
138
+ if isinstance(target_localization, dict):
139
+ changed = reconcile_target_localization(target_localization, source_localization)
140
+ return target_localization, changed
141
+
142
+ target_localization = clone_localization_for_translation(source_localization)
143
+ localizations[target_language] = target_localization
144
+ return target_localization, True
145
+
146
+
147
+ def clone_localization_for_translation(localization: Mapping[str, Any]) -> JsonObject:
148
+ """Deep-copy a localization and mark every string unit as new."""
149
+ cloned = deepcopy(dict(localization))
150
+ _mark_translatable_units_new(cloned)
151
+ return cloned
152
+
153
+
154
+ def string_units_by_key_path(localization: Mapping[str, Any], key_path: str) -> Dict[str, JsonObject]:
155
+ """Return string units keyed by their catalog key path."""
156
+ return {
157
+ reference.key_path: reference.string_unit
158
+ for reference in iter_string_units(localization, key_path)
159
+ }
160
+
161
+
162
+ def plural_category_for_key_path(key_path: str) -> Optional[str]:
163
+ """Return the CLDR plural category a key path ends in, or ``None``.
164
+
165
+ A plural unit's key path ends in ``.plural.<category>`` (for example
166
+ ``key.plural.few`` or ``key.device.iphone.plural.few``).
167
+ """
168
+ segments = key_path.split(".")
169
+ if (
170
+ len(segments) >= 2
171
+ and segments[-2] == PLURAL_VARIATION_KEY
172
+ and segments[-1] in CARDINAL_CATEGORIES
173
+ ):
174
+ return segments[-1]
175
+ return None
176
+
177
+
178
+ def expand_plural_categories(localization: JsonObject, target_language: str) -> bool:
179
+ """Add plural categories the target language requires but the source omits.
180
+
181
+ Walks the localization's variation tree, including plural maps nested under a
182
+ device axis and inside substitutions. Each missing CLDR cardinal category is
183
+ added by cloning the plural map's ``other`` unit and marking the clone new, so
184
+ the surrounding translate loop fills it. Never touches non-plural axes such as
185
+ ``device``, never removes a category, and is a no-op when the target language
186
+ has no curated rule. Returns whether anything was added.
187
+ """
188
+ required = required_cardinal_categories(target_language)
189
+ if required is None:
190
+ return False
191
+ return _expand_plural_in_node(localization, required)
192
+
193
+
194
+ def required_source_units_for_target(
195
+ source_localization: Mapping[str, Any],
196
+ key_path: str,
197
+ target_language: str,
198
+ ) -> Dict[str, JsonObject]:
199
+ """Source string units to translate for the target, by key path.
200
+
201
+ This is the source's own units plus, for every plural map, the categories the
202
+ target language requires but the source lacks. Each added category points at
203
+ the source's ``other`` unit, the correct base text for producing that
204
+ category's form. With no curated rule for the target, this is exactly the
205
+ source's units.
206
+ """
207
+ required = required_cardinal_categories(target_language)
208
+ units: Dict[str, JsonObject] = {}
209
+ _collect_required_source_units(source_localization, key_path, required, units)
210
+ return units
211
+
212
+
213
+ def iter_string_units(localization: Mapping[str, Any], key_path: str) -> Iterator[StringUnitReference]:
214
+ """Yield mutable string units in a localization or variation tree."""
215
+ if not isinstance(localization, dict):
216
+ return
217
+
218
+ string_unit = localization.get("stringUnit")
219
+ if isinstance(string_unit, dict):
220
+ yield StringUnitReference(key_path=key_path, string_unit=string_unit)
221
+
222
+ variations = localization.get("variations")
223
+ if isinstance(variations, dict):
224
+ yield from _iter_variation_units(variations, key_path)
225
+
226
+ substitutions = localization.get("substitutions")
227
+ if isinstance(substitutions, dict):
228
+ yield from _iter_substitution_units(substitutions, key_path)
229
+
230
+
231
+ def placeholders_match(source: str, translation: str) -> bool:
232
+ """Return whether a translation preserves source placeholders exactly."""
233
+ source_parts = _extract_placeholders(source)
234
+ translation_parts = _extract_placeholders(translation)
235
+ return (
236
+ Counter(source_parts.substitutions) == Counter(translation_parts.substitutions)
237
+ and Counter(source_parts.swift_interpolations)
238
+ == Counter(translation_parts.swift_interpolations)
239
+ and _printf_placeholders_match(source_parts.printf, translation_parts.printf)
240
+ )
241
+
242
+
243
+ @dataclass(frozen=True)
244
+ class _PlaceholderParts:
245
+ """Placeholder tokens grouped by their runtime safety rules."""
246
+
247
+ substitutions: list[str]
248
+ printf: list[str]
249
+ swift_interpolations: list[str]
250
+
251
+
252
+ def _key_source_payload(source_language: str, string_data: Mapping[str, Any]) -> JsonObject:
253
+ """The translation-relevant subtree of one key: non-localization fields plus
254
+ the source localization. Holds references; callers only serialize it."""
255
+ relevant_data = {
256
+ name: value for name, value in string_data.items() if name != "localizations"
257
+ }
258
+ relevant_data["localizations"] = {
259
+ source_language: string_data.get("localizations", {}).get(source_language)
260
+ }
261
+ return relevant_data
262
+
263
+
264
+ def key_source_fingerprint(source_language: str, string_data: Mapping[str, Any]) -> str:
265
+ """Hash one catalog key's source text and translation-relevant metadata.
266
+
267
+ Keys off the source localization only, so target edits and target plural
268
+ expansion never change a key's hash. All of a key's units share this hash.
269
+ """
270
+ payload = {
271
+ "sourceLanguage": source_language,
272
+ "string": _key_source_payload(source_language, string_data),
273
+ }
274
+ encoded = json.dumps(payload, ensure_ascii=False, sort_keys=True).encode("utf-8")
275
+ return sha256(encoded).hexdigest()
276
+
277
+
278
+ def _is_variation_leaf(value: Mapping[str, Any]) -> bool:
279
+ """The leaf-vs-axis test shared by every variation walker."""
280
+ return "stringUnit" in value or "variations" in value
281
+
282
+
283
+ def _child_key_path(key_path: str, name: str) -> str:
284
+ return f"{key_path}.{name}" if key_path else name
285
+
286
+
287
+ # This walker and its siblings — _expand_plural_in_variations,
288
+ # _collect_required_variation_units, and _mark_variation_units_new — share the
289
+ # leaf-vs-axis test (_is_variation_leaf) and key-path construction
290
+ # (_child_key_path). They must stay aligned: if the collector yields a key path
291
+ # the expander does not also create in the target, translation reports a missing
292
+ # target unit. ExpandPluralCategoriesTests and RequiredSourceUnitsForTargetTests
293
+ # guard the alignment.
294
+ def _iter_variation_units(variations: Mapping[str, Any], key_path: str) -> Iterator[StringUnitReference]:
295
+ for name, value in variations.items():
296
+ if not isinstance(value, dict):
297
+ continue
298
+
299
+ child_key_path = _child_key_path(key_path, name)
300
+ if _is_variation_leaf(value):
301
+ yield from iter_string_units(value, child_key_path)
302
+ else:
303
+ yield from _iter_variation_units(value, child_key_path)
304
+
305
+
306
+ def _expand_plural_in_node(node: Any, required: frozenset) -> bool:
307
+ if not isinstance(node, dict):
308
+ return False
309
+
310
+ changed = False
311
+ variations = node.get("variations")
312
+ if isinstance(variations, dict):
313
+ changed = _expand_plural_in_variations(variations, required) or changed
314
+
315
+ substitutions = node.get("substitutions")
316
+ if isinstance(substitutions, dict):
317
+ for substitution in substitutions.values():
318
+ changed = _expand_plural_in_node(substitution, required) or changed
319
+
320
+ return changed
321
+
322
+
323
+ # Mirrors _iter_variation_units; keep the leaf-vs-axis test and recursion aligned.
324
+ def _expand_plural_in_variations(variations: Mapping[str, Any], required: frozenset) -> bool:
325
+ changed = False
326
+ for name, value in variations.items():
327
+ if not isinstance(value, dict):
328
+ continue
329
+ if _is_variation_leaf(value):
330
+ changed = _expand_plural_in_node(value, required) or changed
331
+ continue
332
+
333
+ # value is a nested axis map keyed by category or device name. Recurse
334
+ # into it as a variations map, exactly as the collector does, so plural
335
+ # maps at any axis depth are expanded.
336
+ if name == PLURAL_VARIATION_KEY:
337
+ changed = _expand_plural_map(value, required) or changed
338
+ changed = _expand_plural_in_variations(value, required) or changed
339
+ return changed
340
+
341
+
342
+ def _expand_plural_map(plural_map: JsonObject, required: frozenset) -> bool:
343
+ other = plural_map.get("other")
344
+ if not isinstance(other, dict) or not isinstance(other.get("stringUnit"), dict):
345
+ return False
346
+
347
+ changed = False
348
+ for category in ordered_categories(required):
349
+ if category == "other" or category in plural_map:
350
+ continue
351
+ plural_map[category] = clone_localization_for_translation(other)
352
+ changed = True
353
+ return changed
354
+
355
+
356
+ def _collect_required_source_units(
357
+ node: Any,
358
+ key_path: str,
359
+ required: Optional[frozenset],
360
+ out: Dict[str, JsonObject],
361
+ ) -> None:
362
+ if not isinstance(node, dict):
363
+ return
364
+
365
+ string_unit = node.get("stringUnit")
366
+ if isinstance(string_unit, dict):
367
+ out[key_path] = string_unit
368
+
369
+ variations = node.get("variations")
370
+ if isinstance(variations, dict):
371
+ _collect_required_variation_units(variations, key_path, required, out)
372
+
373
+ substitutions = node.get("substitutions")
374
+ if isinstance(substitutions, dict):
375
+ for name, substitution in substitutions.items():
376
+ child_key_path = _child_key_path(key_path, f"substitutions.{name}")
377
+ _collect_required_source_units(substitution, child_key_path, required, out)
378
+
379
+
380
+ # Mirrors _iter_variation_units; keep the leaf-vs-axis test and key paths aligned.
381
+ def _collect_required_variation_units(
382
+ variations: Mapping[str, Any],
383
+ key_path: str,
384
+ required: Optional[frozenset],
385
+ out: Dict[str, JsonObject],
386
+ ) -> None:
387
+ for name, value in variations.items():
388
+ if not isinstance(value, dict):
389
+ continue
390
+
391
+ child_key_path = _child_key_path(key_path, name)
392
+ if _is_variation_leaf(value):
393
+ _collect_required_source_units(value, child_key_path, required, out)
394
+ continue
395
+
396
+ # value is a nested axis map keyed by category or device name.
397
+ _collect_required_variation_units(value, child_key_path, required, out)
398
+ if name == PLURAL_VARIATION_KEY and required is not None:
399
+ _synthesize_target_only_plurals(value, child_key_path, required, out)
400
+
401
+
402
+ def _synthesize_target_only_plurals(
403
+ plural_map: Mapping[str, Any],
404
+ key_path: str,
405
+ required: frozenset,
406
+ out: Dict[str, JsonObject],
407
+ ) -> None:
408
+ other = plural_map.get("other")
409
+ other_unit = other.get("stringUnit") if isinstance(other, dict) else None
410
+ if not isinstance(other_unit, dict):
411
+ return
412
+
413
+ for category in required:
414
+ if category == "other" or category in plural_map:
415
+ continue
416
+ child_key_path = _child_key_path(key_path, category)
417
+ # Collect other's full subtree, mirroring _expand_plural_map, which
418
+ # clones the entire other node (including nested substitutions and
419
+ # variations) into the synthesized category.
420
+ _collect_required_source_units(other, child_key_path, required, out)
421
+
422
+
423
+ def _object_rejecting_duplicate_keys(pairs: Any) -> JsonObject:
424
+ obj: JsonObject = {}
425
+ for key, value in pairs:
426
+ if key in obj:
427
+ raise ValueError(f"Duplicate key {key!r} in JSON object.")
428
+ obj[key] = value
429
+ return obj
430
+
431
+
432
+ def _iter_substitution_units(substitutions: Mapping[str, Any], key_path: str) -> Iterator[StringUnitReference]:
433
+ for name, substitution in substitutions.items():
434
+ if not isinstance(substitution, dict):
435
+ continue
436
+
437
+ child_key_path = _child_key_path(key_path, f"substitutions.{name}")
438
+ yield from iter_string_units(substitution, child_key_path)
439
+
440
+
441
+ def _extract_placeholders(value: str) -> _PlaceholderParts:
442
+ substitutions = SUBSTITUTION_PLACEHOLDER_PATTERN.findall(value)
443
+ remainder = SUBSTITUTION_PLACEHOLDER_PATTERN.sub(" ", value)
444
+ return _PlaceholderParts(
445
+ substitutions=substitutions,
446
+ printf=PRINTF_PLACEHOLDER_PATTERN.findall(remainder),
447
+ swift_interpolations=SWIFT_INTERPOLATION_PATTERN.findall(remainder),
448
+ )
449
+
450
+
451
+ def _printf_placeholders_match(source: list[str], translation: list[str]) -> bool:
452
+ source_escaped_percents = source.count("%%")
453
+ translation_escaped_percents = translation.count("%%")
454
+ if source_escaped_percents != translation_escaped_percents:
455
+ return False
456
+
457
+ source_arguments = [placeholder for placeholder in source if placeholder != "%%"]
458
+ translation_arguments = [placeholder for placeholder in translation if placeholder != "%%"]
459
+ if _all_printf_arguments_are_positional(source_arguments):
460
+ return Counter(source_arguments) == Counter(translation_arguments)
461
+ return source_arguments == translation_arguments
462
+
463
+
464
+ def _all_printf_arguments_are_positional(placeholders: list[str]) -> bool:
465
+ return bool(placeholders) and all(
466
+ POSITIONAL_PRINTF_PATTERN.match(placeholder) is not None
467
+ for placeholder in placeholders
468
+ )
469
+
470
+
471
+ def _clone_string_unit(source_string_unit: Mapping[str, Any]) -> JsonObject:
472
+ cloned = deepcopy(dict(source_string_unit))
473
+ cloned["state"] = "new"
474
+ return cloned
475
+
476
+
477
+ def _mark_translatable_units_new(node: JsonObject) -> None:
478
+ string_unit = node.get("stringUnit")
479
+ if isinstance(string_unit, dict):
480
+ string_unit["state"] = "new"
481
+
482
+ variations = node.get("variations")
483
+ if isinstance(variations, dict):
484
+ _mark_variation_units_new(variations)
485
+
486
+ substitutions = node.get("substitutions")
487
+ if isinstance(substitutions, dict):
488
+ for substitution in substitutions.values():
489
+ if isinstance(substitution, dict):
490
+ _mark_translatable_units_new(substitution)
491
+
492
+ if (
493
+ not isinstance(string_unit, dict)
494
+ and not isinstance(variations, dict)
495
+ and not isinstance(substitutions, dict)
496
+ ):
497
+ _mark_variation_units_new(node)
498
+
499
+
500
+ def _mark_variation_units_new(variations: Mapping[str, Any]) -> None:
501
+ for value in variations.values():
502
+ if not isinstance(value, dict):
503
+ continue
504
+ if _is_variation_leaf(value):
505
+ _mark_translatable_units_new(value)
506
+ else:
507
+ _mark_variation_units_new(value)
508
+
509
+
510
+ def reconcile_target_localization(target_node: JsonObject, source_node: Mapping[str, Any]) -> bool:
511
+ """Add missing source string units to an existing target localization."""
512
+ changed = False
513
+
514
+ source_string_unit = source_node.get("stringUnit")
515
+ source_variations = source_node.get("variations")
516
+
517
+ if isinstance(source_string_unit, dict):
518
+ if "variations" in target_node:
519
+ del target_node["variations"]
520
+ changed = True
521
+ if not isinstance(target_node.get("stringUnit"), dict):
522
+ target_node["stringUnit"] = _clone_string_unit(source_string_unit)
523
+ changed = True
524
+ elif isinstance(source_variations, dict):
525
+ if "stringUnit" in target_node:
526
+ del target_node["stringUnit"]
527
+ changed = True
528
+
529
+ target_variations = target_node.get("variations")
530
+ if not isinstance(target_variations, dict):
531
+ target_variations = {}
532
+ target_node["variations"] = target_variations
533
+ changed = True
534
+
535
+ changed = _merge_missing_variations(target_variations, source_variations) or changed
536
+
537
+ return _merge_missing_substitutions(target_node, source_node) or changed
538
+
539
+
540
+ def _merge_missing_substitutions(target_node: JsonObject, source_node: Mapping[str, Any]) -> bool:
541
+ source_substitutions = source_node.get("substitutions")
542
+ if not isinstance(source_substitutions, dict):
543
+ if "substitutions" in target_node:
544
+ del target_node["substitutions"]
545
+ return True
546
+ return False
547
+
548
+ changed = False
549
+ target_substitutions = target_node.get("substitutions")
550
+ if not isinstance(target_substitutions, dict):
551
+ target_substitutions = {}
552
+ target_node["substitutions"] = target_substitutions
553
+ changed = True
554
+
555
+ for name, source_substitution in source_substitutions.items():
556
+ if not isinstance(source_substitution, dict):
557
+ continue
558
+
559
+ target_substitution = target_substitutions.get(name)
560
+ if not isinstance(target_substitution, dict):
561
+ target_substitutions[name] = clone_localization_for_translation(source_substitution)
562
+ changed = True
563
+ continue
564
+
565
+ for metadata_key in ("argNum", "formatSpecifier"):
566
+ if metadata_key not in source_substitution:
567
+ continue
568
+ if target_substitution.get(metadata_key) != source_substitution[metadata_key]:
569
+ target_substitution[metadata_key] = deepcopy(source_substitution[metadata_key])
570
+ changed = True
571
+
572
+ changed = reconcile_target_localization(target_substitution, source_substitution) or changed
573
+
574
+ for name in list(target_substitutions):
575
+ if not isinstance(source_substitutions.get(name), dict):
576
+ del target_substitutions[name]
577
+ changed = True
578
+
579
+ return changed
580
+
581
+
582
+ def _merge_missing_variations(
583
+ target_variations: JsonObject,
584
+ source_variations: Mapping[str, Any],
585
+ ) -> bool:
586
+ changed = False
587
+
588
+ for name, source_child in source_variations.items():
589
+ if not isinstance(source_child, dict):
590
+ continue
591
+
592
+ target_child = target_variations.get(name)
593
+ if not isinstance(target_child, dict):
594
+ target_variations[name] = clone_localization_for_translation(source_child)
595
+ changed = True
596
+ continue
597
+
598
+ if "stringUnit" in source_child or "variations" in source_child:
599
+ changed = reconcile_target_localization(target_child, source_child) or changed
600
+ else:
601
+ changed = _merge_missing_variations(target_child, source_child) or changed
602
+
603
+ return changed