Expand description
The language identifier and message catalog types of phrasebook:
Lang, Source and Catalog. They are plain const data, with
no dependencies by default and no need for std or alloc.
An app uses them through phrasebook, which re-exports them at its crate
root as phrasebook::{Lang, Source, Catalog, ParseLangError}. They live in
this crate of their own so that a library’s catalog outlives phrasebook’s
breaking releases: a library such as watchword ships its messages as a
pub static L10N: Catalog, and an app hands that catalog to its own
phrasebook. Both name this crate’s Catalog, which changes far more rarely
than phrasebook does, so an app can move to a new phrasebook without waiting
for every library it uses to move with it.
A library that only ships a catalog depends on this crate alone, with
phrasebook as a dev-dependency for its check helpers in tests. A library
whose components read the app’s handle depends on phrasebook as well,
since that handle, phrasebook’s Phrases, is the context type.
§Features
None is on by default. Each versioned feature adds trait impls on
Lang for a dependency that is not yet 1.0, which phrasebook’s feature
of the same name turns on; they live here because only the crate that
defines Lang may implement another crate’s traits for it. A later
version of such a dependency is another feature beside it, not a breaking
release.
| Feature | What it provides |
|---|---|
| (none) | Lang, ParseLangError, Source and Catalog |
koine03 | koine03: TryFrom between Lang and koine 0.3’s Locale and Language, the conversion functions they are built on, and their Error |
yew023 | yew 0.23’s ImplicitClone for Lang, and IntoPropValue from Lang into AttrValue and Option<AttrValue>, for an element’s lang attribute |
§Example
use phrasebook_catalog::{Catalog, Lang, Source};
const SV_SE: Lang = Lang::new("sv-SE");
pub static L10N: Catalog = Catalog::new("watchword", &[
Source::new(Lang::EN_US, "watchword-sign-in = Sign in"),
Source::new(SV_SE, "watchword-sign-in = Logga in"),
])
.with_prefix("watchword-");
assert_eq!(L10N.default_lang(), Some(Lang::EN_US));
assert_eq!(L10N.source(SV_SE).map(|s| s.ftl()), Some("watchword-sign-in = Logga in"));Modules§
Structs§
- Catalog
- Everything one crate ships: its name, the prefix every id it defines must
start with (if any), and one
Sourceper language. - Lang
- A language identifier: a language subtag and an optional region subtag,
such as
en-USorsv. - Parse
Lang Error - The error when a string is not a language tag.
- Source
- One language’s Fluent source, usually embedded with
include_str!.