feat(i18n): YAML-driven translations with EN/ES + language switcher#397
Merged
Conversation
Per-language strings live in static/i18n/<code>.yaml. Two languages ship
today (en, es). Adding a third only needs a new YAML file, a constructor
in 'Language', and the matching cases in 'parseLanguage'/'languageCode'.
- New 'Web.I18n' module: 'Language' (En, Es), 't lang key' lookup,
cookie helpers ('languageFromCookies', 'languageSetCookieBS').
YAML is embedded into the binary at compile time via 'file-embed' so
the runtime stays pure and decode errors fail the build.
- 'Projects.Session' gains a 'lang :: Language' field; the value is read
from the 'lang' cookie at session-build time alongside theme/isSidebarClosed.
- 'GET /set_language/<code>?redirect_to=…' persists the cookie (Max-Age 1yr)
and bounces the user back.
- Sidebar nav items and the user-menu dropdown render via 't sess.lang';
the dropdown also shows the EN/ES switcher (rewrites href to current path
on click so users don't get bounced to /).
- Tests: 'testSessionHeader' / 'refreshSession' pass a default language
through the new 'sessionByID' parameter.
Missing keys fall through to the raw key, so typos surface as visible
'nav.dashboards' strings in the UI rather than blanks.
This was referenced May 25, 2026
Contributor
|
Thanks for the pr @victalejo . Merging it |
tonyalaribe
added a commit
that referenced
this pull request
May 26, 2026
… patterns - PR #397 added file-embed dep to monoscope.cabal by hand but not package.yaml; next hpack run would wipe it. Mirror the dep in package.yaml so they stay in sync. - LogPatterns.UpsertPattern gained an isError field; mkPattern/mkPatternWithSample test helpers were missing it, causing -Werror=missing-fields failures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-scope of #388 — auth + admin + Telegram/webhook channels are pulled out into separate follow-up PRs. This one focuses only on i18n, with the per-language YAML layout suggested in #388.
Why
This PR adds that groundwork. EN ships with all existing strings translated (drop-in: same text as today) and ES ships as the first non-English language. Other languages can be added by a contributor who doesn't know Haskell: drop a new YAML file, wire one constructor.
How
Translations as data. Per-language strings live as flat-key YAML in
static/i18n/<code>.yaml:YAML is embedded into the binary at compile time via
file-embed, so the runtime stays pure and a malformed file fails the build (not a request). Missing keys fall through to the raw key — typos surface as visiblenav.dashboardsstrings in the UI rather than blanks.New
Web.I18nmodule withLanguage(En, Es),t :: Language -> Text -> Text, and cookie helpers.Sessiongains alang :: Languagefield, read from thelangcookie at session-build time next totheme/isSidebarClosed. Templates render witht sess.lang \"key\".GET /set_language/<code>?redirect_to=…persists the cookie (Max-Age = 1 year) and bounces back. The dropdown switcher rewritesredirect_toto the current path on click so users don't get bounced to/.Adding a new language is data-only after Haskell support:
static/i18n/fr.yamlFrconstructor toLanguage, one case inparseLanguage+languageCodeWhat's NOT in this PR (deliberate)
Tested locally
gh auth status/git diffagainstmonoscope-tech/master— only the 9 files listed below.Files
monoscope.cabalsrc/Models/Projects/Projects.hssrc/Pages/BodyWrapper.hssrc/Pkg/TestUtils.hssrc/Web/Auth.hssrc/Web/I18n.hssrc/Web/Routes.hsstatic/i18n/en.yamlstatic/i18n/es.yamlHappy to iterate — let me know if the YAML format should be nested (
auth: login: title:) instead of flat (auth.login.title:), or if there's a preferred location other thanstatic/i18n/.