[pr-tests] darner-core i18n: unit tests for tag resolution, precedence and catalog placeholders #317

Open
ElGibbone wants to merge 3 commits from elgibbone/i18n-and-catalogs into main AGit
First-time contributor

What it changes

  • The problem on main: read from the code only. darner-core::i18n had no tests for language choice, fallback or the bundled catalogs.

Extracts small helpers (parse_saved_language, select, lookup_in, format_template) and adds six tests: tag normalisation; explicit > environment > saved > system, with auto/system using the OS list; saved settings strip a BOM and keep the last entry; untranslated keys fall back to English; templates replace numbered arguments and keep other braces; every bundled catalog is sorted, unique and keeps English's placeholders.

Behaviour is the same as on main: the OS language list is still read only when no language is set (andrewpozdnakov7-jpg's 1e1d4da, kept as their commit). lookup_in sits below text, so lookup keeps its place and #154, #196 and #217 still merge.

How it was tested

  • Tested revision: 3c342de
  • Commands and results (macOS aarch64, toolchain 1.98.1):
    • cargo test -p darner-core --locked: 39 passed, 0 failed
    • cargo clippy -p darner-core --all-targets --locked -- -D warnings, and with --all-features: clean
    • the same two with cargo xwin clippy --target x86_64-pc-windows-msvc: clean
    • cargo xtask policy: 555 files ok
    • With #196 (es) and #217 (pt-BR) merged on top locally, the six i18n tests pass, so the catalog check accepts both new catalogs.
  • Changes a default: no
  • Gates run on that revision: the three on darner-core only, on macOS, plus Windows-target clippy. Not --workspace, not on Windows.
  • Gameplay: not relevant (tests only).
  • Hardware dependence: none.
  • Coverage gaps: workspace-wide gates not run; nothing run on Windows by me (andrewpozdnakov7-jpg ran the six i18n tests and the asset policy on 1e1d4da).

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only). Not run in the game: tests only, no behaviour change.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #154, #196, #217 and #302 change crates/darner-core/src/i18n.rs. #154, #196 and #217 merge with this branch without a conflict; #302 conflicts in lookup (it rewrites lookup's body), in one place.
  • Replaces or overlaps: none found
## What it changes - The problem on main: read from the code only. darner-core::i18n had no tests for language choice, fallback or the bundled catalogs. Extracts small helpers (parse_saved_language, select, lookup_in, format_template) and adds six tests: tag normalisation; explicit > environment > saved > system, with auto/system using the OS list; saved settings strip a BOM and keep the last entry; untranslated keys fall back to English; templates replace numbered arguments and keep other braces; every bundled catalog is sorted, unique and keeps English's placeholders. Behaviour is the same as on main: the OS language list is still read only when no language is set (andrewpozdnakov7-jpg's 1e1d4da, kept as their commit). lookup_in sits below text, so lookup keeps its place and #154, #196 and #217 still merge. ## How it was tested - Tested revision: 3c342de - Commands and results (macOS aarch64, toolchain 1.98.1): - `cargo test -p darner-core --locked`: 39 passed, 0 failed - `cargo clippy -p darner-core --all-targets --locked -- -D warnings`, and with `--all-features`: clean - the same two with `cargo xwin clippy --target x86_64-pc-windows-msvc`: clean - `cargo xtask policy`: 555 files ok - With #196 (es) and #217 (pt-BR) merged on top locally, the six i18n tests pass, so the catalog check accepts both new catalogs. - Changes a default: no - Gates run on that revision: the three on darner-core only, on macOS, plus Windows-target clippy. Not --workspace, not on Windows. - Gameplay: not relevant (tests only). - Hardware dependence: none. - Coverage gaps: workspace-wide gates not run; nothing run on Windows by me (andrewpozdnakov7-jpg ran the six i18n tests and the asset policy on 1e1d4da). ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). Not run in the game: tests only, no behaviour change. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #154, #196, #217 and #302 change crates/darner-core/src/i18n.rs. #154, #196 and #217 merge with this branch without a conflict; #302 conflicts in lookup (it rewrites lookup's body), in one place. - Replaces or overlaps: none found
Extracts pure helpers for saved settings parsing, language selection, fallback lookup and placeholder formatting in darner-core::i18n, and adds six unit tests covering tag normalisation, override precedence, English fallback and placeholder/key invariants across bundled locale catalogs.
First-time contributor

One production detail changed in the refactor. On main, the OS language list is queried only for the system fallback. On c9291a617, initialize queries it before selecting even an explicit, environment or saved language.

1e1d4da passes a lazy iterator to the same selector. In a fixture using its production initialization code, the four configured-language cases went from one OS lookup to zero. Auto and the default still queried once, and all six cases chose the same catalog. The six existing i18n tests and asset policy passed.

If you cherry-pick or rebase the contribution, please keep the Git author. If you fold it into your own commit, please add this trailer.

Co-authored-by: andrewpozdnakov7-jpg <[email protected]>

One production detail changed in the refactor. On main, the OS language list is queried only for the system fallback. On c9291a617, `initialize` queries it before selecting even an explicit, environment or saved language. [1e1d4da](https://git.gtahub.st/andrewpozdnakov7-jpg/Darner/commit/1e1d4da8e72c351dbf7db4c0b18ffb6bcf8f486d) passes a lazy iterator to the same selector. In a fixture using its production initialization code, the four configured-language cases went from one OS lookup to zero. Auto and the default still queried once, and all six cases chose the same catalog. The six existing i18n tests and asset policy passed. If you cherry-pick or rebase the contribution, please keep the Git author. If you fold it into your own commit, please add this trailer. `Co-authored-by: andrewpozdnakov7-jpg <296776509+[email protected]>`
Author
First-time contributor

Thanks, you're right, the eager system_languages() call was a behaviour change. I fast-forwarded the branch to your 1e1d4da unchanged, so it keeps you as the author. On 1e1d4da, on macOS (aarch64): cargo test -p darner-core --locked 39 passed; both clippy gates on darner-core clean for the host and for x86_64-pc-windows-msvc (cargo-xwin). Not run on Windows.

Thanks, you're right, the eager system_languages() call was a behaviour change. I fast-forwarded the branch to your 1e1d4da unchanged, so it keeps you as the author. On 1e1d4da, on macOS (aarch64): `cargo test -p darner-core --locked` 39 passed; both clippy gates on darner-core clean for the host and for `x86_64-pc-windows-msvc` (cargo-xwin). Not run on Windows.
Open pull requests that add catalogs or i18n helpers (#154, #196, #217)
insert next to lookup. With lookup_in after text instead of before
lookup, they merge without a conflict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ElGibbone changed title from Add unit tests for i18n tag resolution, precedence and catalog placeholders to [pr-tests] darner-core i18n: unit tests for tag resolution, precedence and catalog placeholders 2026-12-04 14:42:01 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/317/head:elgibbone/i18n-and-catalogs'
git switch 'elgibbone/i18n-and-catalogs'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'elgibbone/i18n-and-catalogs'
git switch 'elgibbone/i18n-and-catalogs'
git rebase 'main'
git switch 'main'
git merge --ff-only 'elgibbone/i18n-and-catalogs'
git switch 'elgibbone/i18n-and-catalogs'
git rebase 'main'
git switch 'main'
git merge --no-ff 'elgibbone/i18n-and-catalogs'
git switch 'main'
git merge --squash 'elgibbone/i18n-and-catalogs'
git switch 'main'
git merge --ff-only 'elgibbone/i18n-and-catalogs'
git switch 'main'
git merge 'elgibbone/i18n-and-catalogs'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!317
No description provided.