i18n

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package i18n is lys-shell's Fluent localization: a port of the runtime the Rust crates get from i18n-embed 0.16 (FluentLanguageLoader), fluent-bundle 0.16, fluent-syntax 0.12, and fluent-langneg 0.13.

Three domains exist, as in Rust:

  • the shell domain (crates/wayle-shell-core/src/i18n.rs, the t!/td! macros): bar labels, dropdowns, OSD, notification popups. T and Attr read it.
  • the settings domain (crates/wayle-i18n/src/lib.rs, t/t_attr): the settings GUI and config field labels. Settings returns it.
  • the greeter domain (crates/lys-greeter/src/i18n.rs, t!): the login screen's labels. Greeter returns it.

Each domain negotiates the desktop locale (LANGUAGE, LC_ALL, LC_MESSAGES, LANG) against its embedded locales once, on first use, with en-US as the always-loaded fallback. Lookups fall through the negotiated languages in order; a missing message yields i18n-embed's "No localization for id" marker rather than an empty string.

Interpolated placeables are wrapped in Unicode isolation marks (U+2068 ... U+2069) exactly as fluent-bundle does by default, which i18n-embed never turns off.

Index

Constants

This section is empty.

Variables

View Source
var Fallback = MustLangID("en-US")

Fallback is the fallback language both lys-shell domains declare in their i18n.toml.

Functions

func Attr

func Attr(id, attr string, args ...Arg) string

Attr formats a shell message attribute.

func T

func T(id string, args ...Arg) string

T formats a shell message: wayle-shell-core's t!/td!.

Types

type Arg

type Arg struct {
	// contains filtered or unexported fields
}

Arg is one named Fluent argument, built with Str, Int, or Float.

func Float

func Float(name string, v float64) Arg

Float is a numeric argument with Rust f64 formatting.

func Int

func Int(name string, v int64) Arg

Int is a numeric argument; it formats and selects plural variants like a Rust integer passed to fl!.

func Str

func Str(name, v string) Arg

Str is a string argument.

type Assets

type Assets struct {
	// contains filtered or unexported fields
}

Assets is an embedded locale tree: top-level locale directories holding `_*.ftl` partials at any depth.

func NewAssets

func NewAssets(fsys fs.FS) Assets

NewAssets wraps a locale tree of `_*.ftl` partials.

func NewFileAssets

func NewFileAssets(fsys fs.FS, file string) Assets

NewFileAssets wraps a locale tree holding one file per locale, <locale>/<file>.

func (Assets) Available

func (a Assets) Available() ([]LangID, error)

Available lists the locales that carry at least one partial, sorted like rust-embed's file list, with the fallback first when missing (i18n-embed's available_languages).

func (Assets) Source

func (a Assets) Source(locale string) (string, error)

Source is a locale's combined FTL, exactly as wayle-shell-core's and wayle-i18n's build.rs write it (each partial followed by a newline), with CRLF folded to LF as i18n-embed does before parsing.

type LangID

type LangID struct {
	// contains filtered or unexported fields
}

LangID is a Unicode language identifier as unic-langid 0.9 parses it: a lowercase language ("" is und), an optional titlecase script, an optional uppercase region, and sorted, deduplicated variants.

func MustLangID

func MustLangID(s string) LangID

MustLangID parses a compile-time identifier.

func ParseLangID

func ParseLangID(s string) (LangID, error)

ParseLangID ports unic-langid's parse_language_identifier: subtags split on '-' or '_', case-normalized; anything past the variants (an extension, an empty subtag) is an error.

func (LangID) Equal

func (id LangID) Equal(other LangID) bool

Equal reports whether both identifiers carry the same subtags.

func (LangID) Language

func (id LangID) Language() string

Language is the language subtag, "und" when unset.

func (LangID) String

func (id LangID) String() string

String renders the identifier canonically ("und" for no language).

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader is i18n-embed's FluentLanguageLoader over one embedded locale tree: the negotiated languages' bundles in preference order, the en-US fallback last.

func Greeter

func Greeter() *Loader

Greeter returns the greeter-domain loader (lys-greeter's loader()).

func Select

func Select(assets Assets, requested []LangID) (*Loader, error)

Select negotiates the requested languages against the available ones (i18n_embed::select: fluent-langneg filtering, en-US default) and loads the result, fallback last. It is an error only when the fallback itself has no partials.

func Settings

func Settings() *Loader

Settings returns the settings-domain loader (wayle-i18n's loader()).

func Shell

func Shell() *Loader

Shell returns the shell-domain loader (wayle-shell-core's loader()).

func (*Loader) Attr

func (l *Loader) Attr(id, attr string, args ...Arg) string

Attr formats a message attribute from the first bundle that has it, or returns i18n-embed's missing-attribute marker.

func (*Loader) Get

func (l *Loader) Get(id string, args ...Arg) string

Get formats a message's value from the first bundle that has one, or returns i18n-embed's `No localization for id: "<id>"` marker.

func (*Loader) Has

func (l *Loader) Has(id string) bool

Has reports whether any loaded bundle defines the message with a value.

func (*Loader) Languages

func (l *Loader) Languages() []LangID

Languages are the negotiated languages in preference order.

Directories

Path Synopsis
locales
greeter
Package locales embeds the greeter's Fluent file.
Package locales embeds the greeter's Fluent file.
settings
Package locales embeds the settings app's and the config schema's Fluent partials.
Package locales embeds the settings app's and the config schema's Fluent partials.
shell
Package locales embeds the shell's Fluent partials: the bar, its dropdowns, the lock screen, the OSD and the notification surfaces.
Package locales embeds the shell's Fluent partials: the bar, its dropdowns, the lock screen, the OSD and the notification surfaces.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL