Skip to content

fix(examples): skip comment lines when decoding language bundles - #259

Merged
MarTrepodi merged 1 commit into
developfrom
fix/language-bundle-examples
Nov 7, 2026
Merged

MarTrepodi merged 1 commit into
developfrom
fix/language-bundle-examples

Conversation

@MarTrepodi

Copy link
Copy Markdown
Collaborator

Closes #248

What changed

Current localization bundles contain # comment lines with no | delimiter, such as # Start Category: Star_Wars_Strategy_RPG, # End Category: ... (65847 strings) and a bare #. examples/Sync/get_language_bundle.py and examples/Async/get_language_bundle.py ran key, value = line.split("|") on every line, so both raised ValueError on the first comment line.

  • Both examples now skip blank and # lines and split on the first | only (line.partition("|"), skipping lines with no separator). This matches the library parser in helpers/_game_data.py.
  • The module docstrings point readers to get_localization_dictionary / async_get_localization_dictionary as the supported way to build the lookup. The examples still teach the manual decode.
  • Both examples print the size of the lookup. The Async main() now returns the dict, and the module assigns it to der_str_lookup the same way the Sync script does. The Async example was already correct async code (async with / await); nothing else changed there.
  • New tests/examples/test_get_language_bundle.py runs each example against a patched client that serves a bundle with comment lines, a blank line and a value containing |. Both cases fail on develop with the unpack ValueError and pass with this change.

No library code changed.

Verification

  • uv run ruff check src/ tests/ examples/ parity/: passed
  • uv run ruff format --check src/ tests/ examples/ parity/: passed
  • uv run ty check src/swgoh_comlink/: passed
  • uv run pytest tests/unit -q: 1622 passed
  • uv run pytest tests/examples -q: 17 passed (2 new)
  • Live, against public Comlink at http://comlink.lab:3200 without HMAC, from temporary copies with the URL swapped: both the Sync and the Async example exit cleanly and report Built a lookup of 72275 German strings (72,358 lines minus 83 comment lines). The Sync example's dict is identical to get_localization_dictionary(..., language="ger_de") from the same server.

🤖 Generated with Claude Code

Current localization bundles contain '#' comment lines with no '|'
delimiter (e.g. '# Start Category: ...', a bare '#'). The Sync and Async
get_language_bundle examples unpacked line.split("|") into two names and
raised ValueError on the first of them.

Both examples now skip blank and '#' lines and split on the first '|'
only, matching the library parser. Their docstrings point to
get_localization_dictionary / async_get_localization_dictionary as the
supported way to build the lookup. Both print the lookup size, and the
Async main() returns the dict so the script exposes der_str_lookup like
the Sync one.

Adds tests/examples/test_get_language_bundle.py, which runs each example
against a patched client serving a bundle with comment lines, blank lines
and a value containing '|'.

Closes #248

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation testing labels Nov 7, 2026
@MarTrepodi
MarTrepodi merged commit db4c198 into develop Nov 7, 2026
12 checks passed
@MarTrepodi
MarTrepodi deleted the fix/language-bundle-examples branch November 7, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant