Pass locale and language settings: bin/fragjan reads the locale, config holds lang and default_lang #148

Closed
opened 2026-10-16 13:45:26 +02:00 by michael · 2 comments
Owner

Goal

Give berhtjan-core the language information it needs to resolve texts:
the locale is read in bin/fragjan and passed as a runtime parameter,
the language settings come from the program config, adapters/ui only
assembles them. Berhtjan checks the fields; it never reads the
environment.

Background

Found while tracing where the language comes from for
DAW/daw-modul-berhtjan-core#13. Nothing in fragjan, berhtjan-cli or
berhtjan-core sets user_locale, lang or default_lang (no getenv/LANG
anywhere). berhtjan-cli reads ctx.default_lang and calls
core.resolve_lang(ctx), which therefore returns no_language_resolvable
as soon as a label has to be resolved.

bin/fragjan already determines the facts of the environment (OS, HOME,
Lua binary) and passes them to main.lua as --runtime-* parameters; the
locale belongs there.

Scope

  • bin/fragjan: read the locale in POSIX order, an empty value counts as
    unset: LOCALE="${LC_ALL:-${LC_MESSAGES:-${LANG:-}}}"; pass it as
    --runtime-locale
  • main.lua: --runtime-locale is an optional runtime parameter. The four
    existing parameters are required (an empty value stops with 9998);
    an empty or unset locale is normal (cron, containers) and must not
  • program config: a [language] section with lang (used when the locale
    is absent or not resolvable) and default_lang (the guaranteed
    fallback, must be an installed language)
  • adapters/ui build_ctx: map runtime.locale to the language fields and
    pass lang / default_lang from the config unchanged; berhtjan-core
    validates them (language code of lowercase letters)
  • a missing or invalid [language] section is reported, not defaulted
    silently

Acceptance criteria

  • bin/fragjan passes --runtime-locale; LC_ALL, LC_MESSAGES and LANG
    are honoured in that order
  • main.lua accepts an empty or missing locale
  • build_ctx provides the language fields; no environment access
    outside bin/
  • tests: de_DE.UTF-8, C, POSIX, empty, unset, LC_ALL over LANG
  • Tests pass on Lua 5.1 and 5.4

DAW/daw-modul-berhtjan-core#13, DAW/fragjan#141
Handing only the needed fields to each part (instead of the whole ctx)
is a separate topic.

## Goal Give berhtjan-core the language information it needs to resolve texts: the locale is read in bin/fragjan and passed as a runtime parameter, the language settings come from the program config, adapters/ui only assembles them. Berhtjan checks the fields; it never reads the environment. ## Background Found while tracing where the language comes from for DAW/daw-modul-berhtjan-core#13. Nothing in fragjan, berhtjan-cli or berhtjan-core sets user_locale, lang or default_lang (no getenv/LANG anywhere). berhtjan-cli reads ctx.default_lang and calls core.resolve_lang(ctx), which therefore returns no_language_resolvable as soon as a label has to be resolved. bin/fragjan already determines the facts of the environment (OS, HOME, Lua binary) and passes them to main.lua as --runtime-* parameters; the locale belongs there. ## Scope - bin/fragjan: read the locale in POSIX order, an empty value counts as unset: LOCALE="${LC_ALL:-${LC_MESSAGES:-${LANG:-}}}"; pass it as --runtime-locale - main.lua: --runtime-locale is an optional runtime parameter. The four existing parameters are required (an empty value stops with 9998); an empty or unset locale is normal (cron, containers) and must not - program config: a [language] section with lang (used when the locale is absent or not resolvable) and default_lang (the guaranteed fallback, must be an installed language) - adapters/ui build_ctx: map runtime.locale to the language fields and pass lang / default_lang from the config unchanged; berhtjan-core validates them (language code of lowercase letters) - a missing or invalid [language] section is reported, not defaulted silently ## Acceptance criteria - [ ] bin/fragjan passes --runtime-locale; LC_ALL, LC_MESSAGES and LANG are honoured in that order - [ ] main.lua accepts an empty or missing locale - [ ] build_ctx provides the language fields; no environment access outside bin/ - [ ] tests: de_DE.UTF-8, C, POSIX, empty, unset, LC_ALL over LANG - [ ] Tests pass on Lua 5.1 and 5.4 ## Related DAW/daw-modul-berhtjan-core#13, DAW/fragjan#141 Handing only the needed fields to each part (instead of the whole ctx) is a separate topic.
Author
Owner

Update 2026-10-17

Partly superseded by DAW/fragjan#149 (accepted decision: ctx is built in
the host, not in adapters/ui, and each module gets only the fields it
requests).

Changes to the scope of this issue:

  • The line "adapters/ui build_ctx: map runtime.locale ..." no longer
    applies. The host builds the language fields (user_locale, lang,
    default_lang) and hands them only to modules that request them.

Unchanged:

  • bin/fragjan reads the locale (LC_ALL, LC_MESSAGES, LANG) and passes
    --runtime-locale
  • main.lua takes --runtime-locale as an optional parameter
  • [language] section in the program config with lang and default_lang

Also relevant: the resource catalog build (DAW/daw-modul-berhtjan-core#13)
reads [language] default_lang from the program config.

## Update 2026-10-17 Partly superseded by DAW/fragjan#149 (accepted decision: ctx is built in the host, not in adapters/ui, and each module gets only the fields it requests). Changes to the scope of this issue: - The line "adapters/ui build_ctx: map runtime.locale ..." no longer applies. The host builds the language fields (user_locale, lang, default_lang) and hands them only to modules that request them. Unchanged: - bin/fragjan reads the locale (LC_ALL, LC_MESSAGES, LANG) and passes --runtime-locale - main.lua takes --runtime-locale as an optional parameter - [language] section in the program config with lang and default_lang Also relevant: the resource catalog build (DAW/daw-modul-berhtjan-core#13) reads [language] default_lang from the program config.
Author
Owner

Implemented on develop

Checked against the code on develop (a626250):

  • [OK] bin/fragjan reads the locale in POSIX order (LC_ALL, LC_MESSAGES,
    LANG; an empty value counts as unset) and passes --runtime-locale.
  • [OK] main.lua takes --runtime-locale as an optional runtime parameter;
    an empty or missing value is accepted. The four other runtime
    parameters stay required.
  • [OK] No environment access outside bin/ (no getenv in the program code).
  • [OK] [language] with lang and default_lang is in
    templates/config/fragjan.conf; a missing or invalid section is reported
    (language_section_invalid), not defaulted.
  • [OK] Tests: test/test_runtime_locale.lua (de_DE.UTF-8, C, POSIX, empty,
    unset, LC_ALL before LC_MESSAGES before LANG) and
    test/test_ui_context.lua (language chain).
  • [OK] make test passes on Lua 5.4 and 5.1 (26 files, 1306 tests each).

Still in adapters/ui build_ctx for now: the mapping of runtime.locale to
the language fields. It moves to the host together with
DAW/fragjan#149, as noted in the update of 2026-10-17.

## Implemented on develop Checked against the code on develop (a626250): - [OK] bin/fragjan reads the locale in POSIX order (LC_ALL, LC_MESSAGES, LANG; an empty value counts as unset) and passes --runtime-locale. - [OK] main.lua takes --runtime-locale as an optional runtime parameter; an empty or missing value is accepted. The four other runtime parameters stay required. - [OK] No environment access outside bin/ (no getenv in the program code). - [OK] [language] with lang and default_lang is in templates/config/fragjan.conf; a missing or invalid section is reported (language_section_invalid), not defaulted. - [OK] Tests: test/test_runtime_locale.lua (de_DE.UTF-8, C, POSIX, empty, unset, LC_ALL before LC_MESSAGES before LANG) and test/test_ui_context.lua (language chain). - [OK] make test passes on Lua 5.4 and 5.1 (26 files, 1306 tests each). Still in adapters/ui build_ctx for now: the mapping of runtime.locale to the language fields. It moves to the host together with DAW/fragjan#149, as noted in the update of 2026-10-17.
michael 2026-11-15 14:24:22 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/fragjan#148
No description provided.