foliplus.locale#
Localization support for foliplus UI components.
Provides language-specific string tables for all frontend UI text and a helper to inject the correct locale into Jinja2 templates.
Usage#
>>> from foliplus import HeatmapControl
# String input (recommended) >>> HeatmapControl(locale=”zh”) >>> HeatmapControl(locale=”en”)
# Load from external JSON >>> from foliplus.locale import LocaleConfig >>> HeatmapControl(locale=LocaleConfig.from_json(“my_locale.json”))
Functions
|
Normalise a |
Classes
|
Locale configuration for a control instance. |
- class foliplus.locale.LocaleConfig(language: str = 'en')[source]#
Bases:
objectLocale configuration for a control instance.
Stores the selected language code and provides string lookup.
Parameters#
- languagestr, default “en”
Language code, e.g.
"en","zh". Falls back to English if the code is not in_LOCALES_TABLES.- tabledict or None
Optional custom string table (key → localized text). If provided, language is only used to set
locale.code.
Examples#
>>> LocaleConfig("zh") >>> LocaleConfig("en") >>> LocaleConfig(table={"locale.code": "ja", "hello": "こんにちは"})
- classmethod from_json(path: str | Path) LocaleConfig[source]#
Load locale strings from an external JSON file.
The file must contain a flat dictionary of
key: "translated text"entries, plus alocale.codekey that identifies the language.Parameters#
- pathstr or Path
Path to a
.jsonfile.
Returns#
LocaleConfig
Examples#
>>> LocaleConfig.from_json("locales/ja.json")
- foliplus.locale.resolve_locale(locale: str | LocaleConfig) LocaleConfig[source]#
Normalise a
localeparameter to aLocaleConfiginstance.Parameters#
- localestr or LocaleConfig
Language code (
"en","zh") or aLocaleConfiginstance.
Returns#
LocaleConfig
Raises#
- ValueError
If
localeis a string not in_LOCALES_TABLES, or if it is neither a string nor aLocaleConfig.