kellpossible / cargo-i18n

A Rust Cargo sub-command and libraries to extract and build localization resources to embed in your application/library
MIT License
121 stars 25 forks source link

Disabling Bidirectional Isolation in Fluent #45

Closed fosskers closed 3 years ago

fosskers commented 3 years ago

This is a feature request that stems from discoveries in the following issues:

I see that a FluentLanguageLoader has an inner LanguageConfig, a struct private to that module:

struct LanguageConfig {
    current_language: LanguageIdentifier,
    language_bundles: Vec<LanguageBundle>,
}

struct LanguageBundle {
    language: LanguageIdentifier,
    bundle: FluentBundle<Arc<FluentResource>>,
    resources: Vec<Arc<FluentResource>>,
}

The FluentBundle is what, by default, wraps injected arguments in the supposed-to-be-invisible directionality characters described in #44 . If one has direct control over the bundle, this wrapping can be disabled via:

bundle.set_use_isolating(false);

Could a config option be offered, perhaps a field in i18n.toml, to set this to false?

fosskers commented 3 years ago

The setting could perhaps be set after this line: https://github.com/kellpossible/cargo-i18n/blob/master/i18n-embed/src/fluent.rs#L329

Although it's unclear to me at the moment how that setting should be communicated to load_languages, which is a trait method. The signature can't naively be changed, since GettextLanguageLoader also implements this trait, and wouldn't care about this Bidirectionality setting.

fosskers commented 3 years ago

Oh, a method directly on FluentLanguageLoader might do it. I will experiment with this.

kellpossible commented 3 years ago

Implemented now in i18n-embed version 0.9.4