Skip to content

feat: i18n support - #31

Open
kayukin wants to merge 1 commit into
barancezayirli:mainfrom
kayukin:main
Open

kayukin wants to merge 1 commit into
barancezayirli:mainfrom
kayukin:main

Conversation

@kayukin

@kayukin kayukin commented Nov 15, 2026

Copy link
Copy Markdown

What this changes, and why

Adds first-class UI localization and a complete Russian translation.

  • New leaf package internal/i18n:
    • English-keyed catalogue with English fallback for missing entries;
    • language resolution from ?lang=, cookie, configured default and
      Accept-Language;
    • Russian plural rules (1 форма, 2 формы, 5 форм).
  • New DEFAULT_LANGUAGE setting: auto (browser), en, or ru. auto is the
    default, so a Russian browser gets Russian without configuration. A typo is
    refused at startup rather than silently treated as English.
  • Per-browser switcher (EN / RU) in the admin sidebar, login page and OAuth
    consent page. The preference is stored in a dsforms_lang cookie, and the
    public /language route validates its return path with
    urlsafe.RelativePath, so it cannot become an open redirect.
  • All admin and public templates now call .T / .Plural; handler-generated
    flash messages, inline errors, validation text, scope descriptions, spam-rule
    labels, dates and relative ages are translated too.
  • Added catalogue coverage tests, language-resolution tests and a route-level
    Russian login-page test. Documented DEFAULT_LANGUAGE in
    docs/configuration.md, .env.example and README.md.

The approach keeps English as the source language: a missing translation falls
back to readable English instead of an opaque key such as forms.new.subtitle.
A test walks every template and handler T(...) call and fails when a requested
key has no Russian entry.

How it was verified

  • go test -race -count=1 ./... && go vet ./... && gofmt -l .
  • Ran it (say what you did, and what you saw)

go test -race -count=1 ./... passes for every package. go vet ./... is clean,
and gofmt -l . produces no output.

For the manual run I built the binary, started it against a temporary SQLite
database on 127.0.0.1:18080, and requested /admin/login with
Accept-Language: ru-RU,ru;q=0.9. I saw the Russian login page
(Войти, Имя пользователя), signed in as the default admin, and confirmed the
dashboard and sidebar rendered in Russian (Главная, Заявки). The language
switcher and its cookie flow were exercised by the route-level test as well.

Tests

  • New tests fail against the unfixed code
  • Assertions cover the shape of the problem, not only the reported case

The catalogue coverage guard was watched failing: removing the Forms entry
produced a failure naming all four templates that request it
(access_fields.html, base.html, dashboard.html), proving it walks the real
files rather than one known phrase. Restoring the entry made the test pass again.

The guard is deliberately shape-based: every T(...) call in every template and
handler file is checked, so a new untranslated screen is covered automatically.

Anything a reviewer should push on

  • English strings as catalogue keys. This keeps templates readable and gives
    a useful fallback, but changing an English sentence silently orphans its
    Russian translation. The coverage test catches a missing key, not a renamed
    one whose old translation is now dead.
  • Daemon-generated email is not localized. SMTP notification subjects and
    bodies and the quarantine digest remain English; waitlist confirmation and
    broadcast text are operator-authored. If email should follow the UI language,
    that needs a separate decision about which language an account-less
    notification uses.
  • Some store/screen validation errors still arrive as English sentences and
    are displayed inline. They are not template strings and need either translated
    error values or a translation layer over store errors.
  • Preference is per browser, not per user. The cookie is a reasonable default
    for a self-hosted single-operator deployment, but it does not follow an account
    across devices.
  • DEFAULT_LANGUAGE=auto is the default. Russian browsers switch
    automatically, but deployments that expect a fixed English UI may want to set
    DEFAULT_LANGUAGE=en explicitly.

This branch has not been deployed

No deployments
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