Localization
Overview
rs-grid ships with 15 built-in locales and supports custom translations.
All user-visible strings in the grid chrome (context menu, search bar) are
driven by a Locale struct that can be swapped at any time.
The grid can also auto-detect the browser language and select the matching locale automatically.
Built-in locales
Browser language detection
Locale::from_browser() reads navigator.language and returns the best
matching built-in locale. It matches on the primary subtag only — "fr-FR",
"fr-CA", and "fr" all resolve to Locale::fr(). Unknown languages fall
back to English.
You can also match a BCP 47 tag manually:
Framework usage
The <GridCanvas> component accepts an optional reactive locale prop.
When the signal changes, the grid updates its UI strings in place without
remounting.
To switch language at runtime:
Translated strings
The Locale struct contains all UI chrome strings:
Column headers are not part of the locale system. They come from
ColumnDef.label and should be translated by your application code.
Custom locale
You can build a fully custom locale for any language:
Locale file format
Built-in locales are stored as flat TOML files in the rs-grid-web crate
under src/locale/. Each file contains simple key = "value" pairs:
Files are embedded at compile time via include_str! — no runtime I/O.
Adding a new locale
- Copy an existing
.tomlfile (e.g.en.toml→xx.toml) - Translate all values
- In
locale/mod.rs, add:- A
pub fn xx()constructor callingparse_toml(include_str!("xx.toml")) - A
"xx"branch infrom_language_tag
- A
Per-item overrides
Individual context menu labels can also be overridden per-item, independently
of the locale, using ContextMenuItem::with_label():
These per-item overrides take precedence over the locale.