keyvalue_utils¶
keyvalue_utils
¶
Key-value file parsing and serialization utilities.
Supports YAML (.yaml, .yml), Java Properties (.properties), and Apple
Strings (.strings). Each format has a parse/serialize pair. The unified
parse_keyvalue / serialize_keyvalue dispatchers select the correct
pair based on file extension.
is_keyvalue_format
¶
_extract_yaml_strings
¶
Recursively extracts string leaf values from a YAML structure.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Parsed YAML data (dict, list, or scalar).
TYPE:
|
path
|
Current key path (tuple of keys/indices).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[tuple[str | int, ...], str]]
|
List of (key_path, string_value) pairs. |
Source code in src/utils/keyvalue_utils.py
_inject_yaml_string
¶
Sets a value at a nested path in a YAML structure in-place.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Parsed YAML data (dict or list).
TYPE:
|
path
|
Key path to the target leaf.
TYPE:
|
value
|
New string value to set.
TYPE:
|
Source code in src/utils/keyvalue_utils.py
parse_yaml
¶
Parses a YAML file into localization entries.
Only string leaf values are extracted. Numbers, booleans, and null values are skipped.
| PARAMETER | DESCRIPTION |
|---|---|
content
|
Raw YAML file content.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[list[LocalizationEntry], object]
|
Tuple of (entries, parsed_data). |
Source code in src/utils/keyvalue_utils.py
serialize_yaml
¶
Reconstructs a YAML file with translated values.
| PARAMETER | DESCRIPTION |
|---|---|
entries
|
Localization entries with translated text.
TYPE:
|
original_data
|
Original parsed YAML structure from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Complete YAML file content. |
Source code in src/utils/keyvalue_utils.py
_unescape_properties
¶
Unescapes a Java Properties value string.
Source code in src/utils/keyvalue_utils.py
_escape_properties_value
¶
Escapes a string for Java Properties value output.
Source code in src/utils/keyvalue_utils.py
_join_continuation_lines
¶
Joins backslash-continued lines in a Properties file.
| PARAMETER | DESCRIPTION |
|---|---|
lines
|
Raw lines from the file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
Logical lines with continuations merged. |
Source code in src/utils/keyvalue_utils.py
_parse_properties_line
¶
Parses a single Properties key-value line.
| PARAMETER | DESCRIPTION |
|---|---|
line
|
A logical (continuation-joined) line.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, str, str] | None
|
Tuple of (key, separator, value) or None if not a kv line. |
Source code in src/utils/keyvalue_utils.py
parse_properties
¶
Parses a Java Properties file into localization entries.
Preserves comments, blank lines, and key ordering via a structure list that records the sequence of elements.
| PARAMETER | DESCRIPTION |
|---|---|
content
|
Raw Properties file content.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[LocalizationEntry]
|
Tuple of (entries, structure) where structure is a list of |
list[tuple[str, object]]
|
|
tuple[list[LocalizationEntry], list[tuple[str, object]]]
|
tuples. |
Source code in src/utils/keyvalue_utils.py
serialize_properties
¶
Reconstructs a Java Properties file from entries and structure.
| PARAMETER | DESCRIPTION |
|---|---|
entries
|
Localization entries with translated text.
TYPE:
|
structure
|
Structure list from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Complete Properties file content. |
Source code in src/utils/keyvalue_utils.py
_unescape_strings
¶
Unescapes an Apple Strings value.
Source code in src/utils/keyvalue_utils.py
_escape_strings
¶
Escapes a string for Apple Strings output.
Source code in src/utils/keyvalue_utils.py
parse_strings
¶
Parses an Apple Strings file into localization entries.
Preserves comments and blank lines via a structure list.
| PARAMETER | DESCRIPTION |
|---|---|
content
|
Raw .strings file content.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[list[LocalizationEntry], list[tuple[str, object]]]
|
Tuple of (entries, structure). |
Source code in src/utils/keyvalue_utils.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
serialize_strings
¶
Reconstructs an Apple Strings file from entries and structure.
| PARAMETER | DESCRIPTION |
|---|---|
entries
|
Localization entries with translated text.
TYPE:
|
structure
|
Structure list from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Complete .strings file content. |
Source code in src/utils/keyvalue_utils.py
parse_keyvalue
¶
Dispatches to the format-specific key-value parser.
| PARAMETER | DESCRIPTION |
|---|---|
content
|
Raw file content.
TYPE:
|
suffix
|
Lowercase file extension (e.g.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[list[LocalizationEntry], object]
|
Tuple of (entries, format_data). |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the extension is not a supported key-value format. |
Source code in src/utils/keyvalue_utils.py
serialize_keyvalue
¶
Dispatches to the format-specific key-value serializer.
| PARAMETER | DESCRIPTION |
|---|---|
entries
|
Localization entries with translated text.
TYPE:
|
format_data
|
Format-specific data from
TYPE:
|
suffix
|
Lowercase file extension.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Complete file content. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the extension is not a supported key-value format. |