Skip to content

Commit

Permalink
feat(i18n): ✨ feature-gated translators
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Sep 9, 2021
1 parent 24f4362 commit a123f0d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
11 changes: 9 additions & 2 deletions packages/perseus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@ urlencoding = "2.1"
chrono = "0.4"
http = "0.2"
async-trait = "0.1"
fluent-bundle = "0.15"
unic-langid = "0.9"
fluent-bundle = { version = "0.15", optional = true }
unic-langid = { version = "0.9", optional = true }

[features]
default = ["translator-fluent", "translator-dflt-fluent"]
# Each `translator-dflt-*` feature enables a certain translator as the default, and is mutually exclusive with others like it
# One MUST be specified, or the crate will not compile
translator-fluent = ["fluent-bundle", "unic-langid"]
translator-dflt-fluent = ["translator-fluent", "fluent-bundle", "unic-langid"]
7 changes: 7 additions & 0 deletions packages/perseus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
* - [Crate page](https://crates.io/crates/perseus)
* - [Gitter chat](https://gitter.im/perseus-framework/community)
* - [Discord server channel](https://discord.com/channels/820400041332179004/883168134331256892) (for Sycamore-related stuff)
*
* # Features
*
* Perseus performs internationalization using translators, each of which utilizes some translation engine, like [Fluent](https://projectfluent.org).
* Each of the available translations are feature-gated, and can be enabled with the `translator-[engine-name]` feature. You can set
* the default translator by setting the `translator-dflt-[engine-name]` (you of course can't have more than one default translator).
* You can read more about this system [here](https://arctic-hen7.github.io/perseus/i18n.html).
*/

#![deny(missing_docs)]
Expand Down
7 changes: 5 additions & 2 deletions packages/perseus/src/translator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/// Errors for translators. These are separate so new translators can easily be created in a modular fashion.
pub mod errors;
mod fluent;

// We export each translator by name
#[cfg(feature = "translator-fluent")]
mod fluent;
#[cfg(feature = "translator-fluent")]
pub use fluent::{FluentTranslator, FLUENT_TRANSLATOR_FILE_EXT};

// And then we export defaults using feature gates
// TODO feature-gate these lines
#[cfg(feature = "translator-dflt-fluent")]
pub use FluentTranslator as Translator;
#[cfg(feature = "translator-dflt-fluent")]
pub use FLUENT_TRANSLATOR_FILE_EXT as TRANSLATOR_FILE_EXT;

0 comments on commit a123f0d

Please sign in to comment.