phrasebook_catalog/lib.rs
1//! [<img alt="github" src="https://img.shields.io/badge/github-udoprog/phrasebook-8da0cb?style=for-the-badge&logo=github" height="20">](https://github.com/udoprog/phrasebook)
2//! [<img alt="crates.io" src="https://img.shields.io/crates/v/phrasebook-catalog.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/phrasebook-catalog)
3//! [<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-phrasebook--catalog-66c2a5?style=for-the-badge&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K" height="20">](https://docs.rs/phrasebook-catalog)
4//!
5//! The language identifier and message catalog types of [phrasebook]:
6//! [`Lang`], [`Source`] and [`Catalog`]. They are plain `const` data, with
7//! no dependencies by default and no need for `std` or `alloc`.
8//!
9//! An app uses them through phrasebook, which re-exports them at its crate
10//! root as `phrasebook::{Lang, Source, Catalog, ParseLangError}`. They live in
11//! this crate of their own so that a library's catalog outlives phrasebook's
12//! breaking releases: a library such as watchword ships its messages as a
13//! `pub static L10N: Catalog`, and an app hands that catalog to its own
14//! phrasebook. Both name this crate's `Catalog`, which changes far more rarely
15//! than phrasebook does, so an app can move to a new phrasebook without waiting
16//! for every library it uses to move with it.
17//!
18//! A library that only ships a catalog depends on this crate alone, with
19//! phrasebook as a dev-dependency for its `check` helpers in tests. A library
20//! whose components read the app's handle depends on phrasebook as well,
21//! since that handle, phrasebook's `Phrases`, is the context type.
22//!
23//! <br>
24//!
25//! ## Features
26//!
27//! None is on by default. Each versioned feature adds trait impls on
28//! [`Lang`] for a dependency that is not yet 1.0, which phrasebook's feature
29//! of the same name turns on; they live here because only the crate that
30//! defines `Lang` may implement another crate's traits for it. A later
31//! version of such a dependency is another feature beside it, not a breaking
32//! release.
33//!
34//! | Feature | What it provides |
35//! |---|---|
36//! | *(none)* | [`Lang`], [`ParseLangError`], [`Source`] and [`Catalog`] |
37//! | `koine03` | [`koine03`]: `TryFrom` between [`Lang`] and koine 0.3's `Locale` and `Language`, the conversion functions they are built on, and their `Error` |
38//! | `yew023` | yew 0.23's `ImplicitClone` for [`Lang`], and `IntoPropValue` from [`Lang`] into `AttrValue` and `Option<AttrValue>`, for an element's `lang` attribute |
39//!
40//! <br>
41//!
42//! ## Example
43//!
44//! ```
45//! use phrasebook_catalog::{Catalog, Lang, Source};
46//!
47//! const SV_SE: Lang = Lang::new("sv-SE");
48//!
49//! pub static L10N: Catalog = Catalog::new("watchword", &[
50//! Source::new(Lang::EN_US, "watchword-sign-in = Sign in"),
51//! Source::new(SV_SE, "watchword-sign-in = Logga in"),
52//! ])
53//! .with_prefix("watchword-");
54//!
55//! assert_eq!(L10N.default_lang(), Some(Lang::EN_US));
56//! assert_eq!(L10N.source(SV_SE).map(|s| s.ftl()), Some("watchword-sign-in = Logga in"));
57//! ```
58//!
59//! [`Catalog`]: https://docs.rs/phrasebook-catalog/latest/phrasebook_catalog/struct.Catalog.html
60//! [`koine03`]: https://docs.rs/phrasebook-catalog/latest/phrasebook_catalog/koine03/index.html
61//! [`Lang`]: https://docs.rs/phrasebook-catalog/latest/phrasebook_catalog/struct.Lang.html
62//! [`ParseLangError`]: https://docs.rs/phrasebook-catalog/latest/phrasebook_catalog/struct.ParseLangError.html
63//! [`Source`]: https://docs.rs/phrasebook-catalog/latest/phrasebook_catalog/struct.Source.html
64//! [phrasebook]: https://docs.rs/phrasebook
65
66#![no_std]
67#![cfg_attr(phrasebook_docsrs, feature(doc_cfg))]
68#![deny(missing_docs)]
69
70#[cfg(feature = "yew023")]
71extern crate alloc;
72
73#[cfg(test)]
74extern crate std;
75
76mod catalog;
77mod lang;
78
79#[cfg(feature = "koine03")]
80#[cfg_attr(phrasebook_docsrs, doc(cfg(feature = "koine03")))]
81pub mod koine03;
82
83#[cfg(feature = "yew023")]
84mod yew023;
85
86pub use self::catalog::{Catalog, Source};
87pub use self::lang::{Lang, ParseLangError};