Commit 2105747
authored
fix: reject blank locale catalog values instead of rendering them (#2163)
* fix: reject blank locale catalog values instead of rendering them
English is the per-key fallback only for a key that is ABSENT. `t()` and
`tHtml()` resolve with `hasOwnProperty` rather than truthiness, so a
present-but-empty string wins over the English source and renders as nothing at
all. Omitting a key and emptying it therefore look nearly identical in the JSON
and behave oppositely on screen — a translator clearing a value to mean "not
translated yet" silently blanks that piece of UI.
Nothing objected to it. `_validate_string_map` and `_validate_tools` checked the
type and stopped, and the parity ceilings count a key untranslated only when it
equals the English or is missing (`_untranslated_keys`), so `""` read there as
translated. Placeholder parity caught the subset whose English carries a
placeholder, which is why this stayed invisible: the loud half of the class was
already covered.
Both validators now reject a blank value the way `meta.native_name` already
does, and the error names the fix — omit the key. Measured before changing it:
0 blank values across 4,985 shipped ones (messages, tool_groups, tools and the
component catalogs), so this rejects nothing that exists today.
Each guard is pinned separately: breaking the `messages`/`tool_groups`
condition fails those six parametrizations while the two tool-field cases stay
green, and breaking the tool-field condition inverts that exactly.
The locale README gains the rule where it describes omission, since omitting is
now the only way to express "not translated yet".
* docs: state the blank rule on tool_groups without promising omission
`_validate_string_map` guards `messages` and `tool_groups` alike, but the
catalog reference stated the blank rule only under `messages`, so a
translator reading the `tool_groups` bullet had no reason to expect a load
error.
Omission is not the way out on that section: the key set is exact, and
`test_settings_catalog_keys_name_real_groups_and_tools` — gated behind the
post-merge `LOCALE_COMPLETENESS_CHECKS=1` run — fails a catalog that is
missing a group. An untranslated heading therefore keeps the English tag as
its value.
For the same reason the shared blank-value error names the mechanism, that
English renders only for an absent key, rather than prescribing "omit the
key": that advice holds for `messages` and points a `tool_groups` translator
at a catalog which then fails the completeness check.
The per-tool blank test now covers the same three blank spellings as its
`messages`/`tool_groups` sibling instead of two spaces alone.
`_style_sample_keys` claimed a hand-committed blank was "only type-checked"
by `_validate_string_map`, which this branch made false. Its defensive skip
is still worth keeping, so the docstring now names the reason that actually
holds: the script reads catalogs with `json.loads` instead of going through
`load_catalogs`, so a blank reaches it out of a tree the app never loaded.
* docs: name why the sampler still meets a blank the loader now rejects
`_style_sample_keys` and the test that pins it both justified the blank-skip
with `_validate_string_map` doing no more than a type check. The previous
commit makes that false.
The skip is still worth keeping, so both now name the reason that does hold:
`scripts/translate_locales.py` reads catalogs with `json.loads` rather than
through `load_catalogs`, so a blank reaches the sampler out of a working tree
the app never loaded.1 parent 767c248 commit 2105747
5 files changed
Lines changed: 93 additions & 10 deletions
File tree
- scripts
- src/ha_mcp/settings_ui
- locales
- tests/src/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
472 | 475 | | |
473 | 476 | | |
474 | 477 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
27 | 38 | | |
28 | 39 | | |
29 | 40 | | |
| |||
32 | 43 | | |
33 | 44 | | |
34 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
35 | 52 | | |
36 | 53 | | |
37 | 54 | | |
| |||
53 | 70 | | |
54 | 71 | | |
55 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
56 | 80 | | |
57 | 81 | | |
58 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
65 | 68 | | |
66 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
70 | | - | |
| 76 | + | |
71 | 77 | | |
72 | 78 | | |
73 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
233 | 282 | | |
234 | 283 | | |
235 | 284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
0 commit comments