Skip to content

i18n: localize per-metric status labels (Poor/Elevated/…) across all locales#37

Open
mzspicoli wants to merge 1 commit into
KadenThomp36:mainfrom
mzspicoli:fix/translate-metric-status
Open

i18n: localize per-metric status labels (Poor/Elevated/…) across all locales#37
mzspicoli wants to merge 1 commit into
KadenThomp36:mainfrom
mzspicoli:fix/translate-metric-status

Conversation

@mzspicoli
Copy link
Copy Markdown
Contributor

@mzspicoli mzspicoli commented May 17, 2026

Summary

First — thanks again for merging PR #33 (the Portuguese translation)! It's working great. While using it I noticed one remaining spot that didn't pick up the translation: the small status pill inside each metric card (CO₂, PM2.5, humidity, temperature, …) was always rendering "Poor" / "Elevated" / "Warm" / etc. in English regardless of the configured language. I reproduced the same thing with es and de, so it's not pt-specific.

Here's the bug with language: pt — header badge says "Ruim" (translated) but the per-metric pills still say "Poor":

Before fix: per-metric badges still in English

Root cause: METRIC_DEFS.labels held English display strings, and _getMetricStatus() returned them verbatim — the only place that bypassed the _t('status', …) lookup that _getOverallStatus() already uses for the header badge.

Fix: smallest viable patch that reuses the existing translation machinery — no new helpers, no new translation groups, no change to thresholds, recommendation cascade, or overall-status logic:

  1. Rename METRIC_DEFS[*].labelslabelKeys and lowercase the values into status translation keys ('Poor''poor', 'Too Dry''too_dry', etc.).
  2. _getMetricStatus() resolves the key through this._t('status', key) — the same path the header badge already uses.
  3. Extend each locale's status group with the previously-untranslated keys: safe, low, high, elevated, clean, too_dry, dry, comfortable, humid, too_humid, cold, cool, warm, hot. English values match what was in METRIC_DEFS.labels so en behavior is byte-identical.
  4. Bumps CARD_VERSION to 2.9.2.

Spanish, French, German, and Portuguese values follow the same domain vocabulary already used elsewhere in those locales (e.g. pt uses "Muito Seco" / "Muito Úmido" matching the existing recommendation.too_dry / too_humid).

Test plan

All 368 tests pass (node test.js) — 360 existing + 8 new covering the bug:

  • en CO₂ 2000 ppm → Poor (unchanged)
  • pt CO₂ 2000 ppm → Ruim
  • es CO₂ 2000 ppm → Malo
  • de PM2.5 50 µg/m³ → Schlecht
  • fr CO₂ 1200 ppm → Élevé
  • pt humidity 20% → Muito Seco
  • pt temperature 23 °C → Morno
  • es temperature 23 °C → Cálido
  • Existing English assertions for _getCO2Status / _getMetricStatus / _getTempStatus continue to pass (English fallback is byte-identical to the old hard-coded labels).

Tested locally in Home Assistant with language: pt — the per-metric pill now matches the header badge ("Ruim" instead of "Poor"). Screenshot above shows the pre-fix state.

🤖 Generated with Claude Code / I reviewed each translation before opening :)

The per-metric status badge (the "Poor" / "Elevated" chip inside each
CO₂, PM2.5, humidity, etc. card) was rendered in English regardless of
the configured language because METRIC_DEFS held the display strings
directly. Only the overall header badge went through the translation
layer, leaving non-English users with mixed-language cards.

Replace `labels` with `labelKeys` in METRIC_DEFS — these are now keys
into TRANSLATIONS[<lang>].status — and have _getMetricStatus resolve
them through _t(). Add the previously-untranslated status keys (safe,
low, high, elevated, clean, too_dry, dry, comfortable, humid, too_humid,
cold, cool, warm, hot) to every locale (en/es/fr/de/pt). Test coverage
in test.js verifies CO₂, PM2.5, humidity, and temperature badges
translate correctly across locales.

Bumps CARD_VERSION to 2.9.2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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