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.
| 引数 | デスクリプション |
|---|---|
data
|
Parsed YAML data (dict, list, or scalar).
タイプ:
|
path
|
Current key path (tuple of keys/indices).
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
list[tuple[tuple[str | int, ...], str]]
|
List of (key_path, string_value) pairs. |
ソースコード位置: src/utils/keyvalue_utils.py
_inject_yaml_string
¶
Sets a value at a nested path in a YAML structure in-place.
| 引数 | デスクリプション |
|---|---|
data
|
Parsed YAML data (dict or list).
タイプ:
|
path
|
Key path to the target leaf.
タイプ:
|
value
|
New string value to set.
タイプ:
|
ソースコード位置: 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.
| 引数 | デスクリプション |
|---|---|
content
|
Raw YAML file content.
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
tuple[list[LocalizationEntry], object]
|
Tuple of (entries, parsed_data). |
ソースコード位置: src/utils/keyvalue_utils.py
serialize_yaml
¶
Reconstructs a YAML file with translated values.
| 引数 | デスクリプション |
|---|---|
entries
|
Localization entries with translated text.
タイプ:
|
original_data
|
Original parsed YAML structure from
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
str
|
Complete YAML file content. |
ソースコード位置: src/utils/keyvalue_utils.py
_unescape_properties
¶
Unescapes a Java Properties value string.
ソースコード位置: src/utils/keyvalue_utils.py
_escape_properties_value
¶
Escapes a string for Java Properties value output.
ソースコード位置: src/utils/keyvalue_utils.py
_join_continuation_lines
¶
Joins backslash-continued lines in a Properties file.
| 引数 | デスクリプション |
|---|---|
lines
|
Raw lines from the file.
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
list[str]
|
Logical lines with continuations merged. |
ソースコード位置: src/utils/keyvalue_utils.py
_parse_properties_line
¶
Parses a single Properties key-value line.
| 引数 | デスクリプション |
|---|---|
line
|
A logical (continuation-joined) line.
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
tuple[str, str, str] | None
|
Tuple of (key, separator, value) or None if not a kv line. |
ソースコード位置: 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.
| 引数 | デスクリプション |
|---|---|
content
|
Raw Properties file content.
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
list[LocalizationEntry]
|
Tuple of (entries, structure) where structure is a list of |
list[tuple[str, object]]
|
|
tuple[list[LocalizationEntry], list[tuple[str, object]]]
|
tuples. |
ソースコード位置: src/utils/keyvalue_utils.py
serialize_properties
¶
Reconstructs a Java Properties file from entries and structure.
| 引数 | デスクリプション |
|---|---|
entries
|
Localization entries with translated text.
タイプ:
|
structure
|
Structure list from
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
str
|
Complete Properties file content. |
ソースコード位置: src/utils/keyvalue_utils.py
_unescape_strings
¶
Unescapes an Apple Strings value.
ソースコード位置: src/utils/keyvalue_utils.py
_escape_strings
¶
Escapes a string for Apple Strings output.
ソースコード位置: src/utils/keyvalue_utils.py
parse_strings
¶
Parses an Apple Strings file into localization entries.
Preserves comments and blank lines via a structure list.
| 引数 | デスクリプション |
|---|---|
content
|
Raw .strings file content.
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
tuple[list[LocalizationEntry], list[tuple[str, object]]]
|
Tuple of (entries, structure). |
ソースコード位置: 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.
| 引数 | デスクリプション |
|---|---|
entries
|
Localization entries with translated text.
タイプ:
|
structure
|
Structure list from
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
str
|
Complete .strings file content. |
ソースコード位置: src/utils/keyvalue_utils.py
parse_keyvalue
¶
Dispatches to the format-specific key-value parser.
| 引数 | デスクリプション |
|---|---|
content
|
Raw file content.
タイプ:
|
suffix
|
Lowercase file extension (e.g.
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
tuple[list[LocalizationEntry], object]
|
Tuple of (entries, format_data). |
| 発生 | デスクリプション |
|---|---|
ValueError
|
If the extension is not a supported key-value format. |
ソースコード位置: src/utils/keyvalue_utils.py
serialize_keyvalue
¶
Dispatches to the format-specific key-value serializer.
| 引数 | デスクリプション |
|---|---|
entries
|
Localization entries with translated text.
タイプ:
|
format_data
|
Format-specific data from
タイプ:
|
suffix
|
Lowercase file extension.
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
str
|
Complete file content. |
| 発生 | デスクリプション |
|---|---|
ValueError
|
If the extension is not a supported key-value format. |