Skip to content

Read Rails YAML by its root key in check without a config - #107

Merged
arvida merged 1 commit into
mainfrom
fix/803-check-root-key-locale
Oct 2, 2026
Merged

arvida merged 1 commit into
mainfrom
fix/803-check-root-key-locale

Conversation

@arvida

@arvida arvida commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Fixes localheroai/localhero-ai#803.

Rails loads a YAML file as the locale its root key names, whatever the file is called. check took the locale from the file name, so config/locales/sr.yml starting with sr-Latn: had every key reported as an orphan (sr-Latn.hello) and every source key as missing. On a clean run over chatwoot/chatwoot that was 986 false orphans, all from sr.yml, devise.sr.yml and ur_IN.yml (root ur:), and the summary line a first-time user reads was wrong.

Without a localhero.json, check now reads such a file under its file's locale and says so once:

ℹ config/locales/sr.yml is named for sr but defines sr-Latn, the locale Rails loads it as. Checked it as sr.
chatwoot before after
summary 85% complete, 986 orphans 88% complete, 0 orphans
sr 5%, 518 orphans 88%, 0 orphans
ur_IN 13%, 468 orphans 88%, 0 orphans

Scope

  • Only check, and only without a localhero.json. With a config, check keeps reading files the way translate does. Shared loaders (files.ts, translation-utils.ts) are untouched; isLanguage is exported from locale-detection.ts, nothing else changes there.
  • Only when every source YAML file is wrapped in the source locale, so plain YAML whose single namespace happens to be a language code (id:) is left alone.
  • A target whose root key is the source locale (de.yml starting with en:) is still reported. Rails would load it as the source language.
  • The tree is re-serialised under the file's locale rather than renamed in the text, so any valid YAML spelling of the root key works.
  • --changed-only aligns base files too, judged by the base's own source files, so a key dropped in a pull request is still flagged as new.

Known limits

  • In --format github, findings in a realigned file come without a line number (the line lookup reads the original file). Before this they were all false orphans.
  • The info line is text output only.
  • ur_IN.yml is checked as ur_IN, not merged into ur as Rails does. Pairing files to sources stays filename-based.

Verified

  • Full suite passes, lint and build clean. Tests cover the plain and "sr-Latn" : root spellings, a comment-only file, a source-locale root, an unwrapped id: namespace, a key dropped under --changed-only, and a base branch whose source was not yet wrapped.
  • Built CLI on chatwoot as above; lago-api and excalidraw (--path packages/excalidraw/locales) give the same summary as 0.0.76.

- A file named for one locale whose root key names another (sr.yml with sr-Latn:) is checked under its file's locale instead of reporting every key as an orphan
- Says once per file which locale it defines
- Only when there is no localhero.json and the source YAML is wrapped in the source locale; the base branch is judged the same way
- A target whose root key is the source locale is still reported
@arvida
arvida merged commit 0bb15c1 into main Oct 2, 2026
1 check passed
@arvida arvida mentioned this pull request Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant