Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Application locale

This example sets the application locale at startup and observes it through commands, Chromium and native menus. It illustrates the framework locale setting; translating application-owned text remains the responsibility of the application.

56_i18n · Source files: main.mbt, app.html

Behavior

The app selects zh-CN and displays backend preferences alongside navigator.language and navigator.languages.

Implementation

Excerpt from the entry point; use the source link above for the complete context.

async fn main {
  let locale = @proton.Locale::parse("zh-CN") catch {
    error => abort(error.message())
  }
  @proton.html("Proton 国际化", resource, width=860, height=600, debug=true)
  ..locale(locale)
  ..capability(@proton_extension.capability(i18n_extension()))
  ..identifier("dev.proton.56-i18n")
  .run_or_abort()
}

The application explicitly parses zh-CN and passes it to locale(). The extension reads the resulting locale preferences from its command context; Chromium and native framework labels use the same startup choice. Windows uses a separate entry variant without the menu declared for other hosts.

This selects framework/browser locale; it does not translate arbitrary application strings. Keep application text in your own catalog. Locale is a startup choice in this example, not a live language-switch implementation.

Run

After completing source checkout and runtime setup, run from the repository root:

moon -C examples run 56_i18n --target native

Limits and interpretation

Proton propagates locale; it does not translate application text. This example omits native menus on Windows; do not infer menu parity from its other platforms.