Skip to content

Expose the user's preferred language to packages for localized diagnostics #8944

Open

Description

@fengyangsi

Description

Could Typst expose the host-provided user language preference through a small API, so packages can choose a language for their own error messages without requiring a custom --input lang=... on every project?

For example, an API such as sys.locale() could return a BCP 47 language tag, or none when no preference is available. The name is only illustrative; the intended value is the user's preferred UI/message language, not necessarily their regional number/date formatting locale. An ordered list of preferred languages could also be useful, but a single preference would already address our immediate use case.

Suggested semantics:

  • In the CLI, obtain the preference from the user's OS/message-language settings and normalize it to a language tag.
  • Allow embedding applications and editors to supply the preference. A web host should use the user's preference, rather than its server's locale; hosts unable or unwilling to provide one could return none.
  • Make it available during ordinary evaluation, including package initialization and validation before layout, without requiring a context block.
  • Keep the value stable within a compilation and provide a way to pin or disable automatic detection for CI and reproducible builds. Changes to the preference should be reflected in any relevant compilation caches.
  • Keep it separate from text.lang; document language and the language preferred by the person reading an error can differ.

datetime.today() seems like a useful precedent for a host-provided value with explicit overrides: it already supports --creation-timestamp / SOURCE_DATE_EPOCH. This proposal does not require arbitrary environment-variable access or automatically changing the document's language. Packages would still provide their own translations and language matching.

Use Case

We're developing a Typst helper that lets packages register translated message catalogs and produce localized panic messages. It currently selects the language with:

let lang = match-lang(sys.inputs.at("lang", default: default-lang), shared)

Here, shared contains the languages available in both the message and terminology catalogs. Users currently need to pass --input lang=ja-JP, for example, or configure an equivalent input in their editor. A wrapper could inject the OS language, but that requires separate integration for each compilation environment.

With a standard API, our selection order could be: explicit package/project input, then the host's user-language preference, then the package's fallback. A Japanese-speaking user compiling an English document could receive Japanese package errors without extra setup or changing the document language.

Related: #7536 concerns access to Typst's existing translated strings. This request is about discovering the user's preferred message language; our package already supplies the translations.

Would a host-provided API in sys fit Typst's model, or would a standardized host-supplied input be a better approach?

Activity

  1. added
    feature request
    on Oct 10, 2026
  2. added
    scripting
    i18n
    on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requesti18nscripting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions