phrasebook-catalog 0.1.0

The language identifier and message catalog types of phrasebook, in their own crate so a library's catalog outlives phrasebook's breaking releases.
Documentation
  • Coverage
  • 100%
    11 out of 11 items documented8 out of 9 items with examples
  • Size
  • Source code size: 72.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 542.1 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 20s Average build duration of successful builds.
  • all releases: 20s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • udoprog/phrasebook
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • udoprog

phrasebook-catalog

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"));