kellpossible / cargo-i18n

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

Add FluentLanguageLoader::lang method #88

Closed bikeshedder closed 1 year ago

bikeshedder commented 2 years ago

This is an alternative implementation for #59 and is based on the code from #84.

This PR adds a single new method:

This methods allows creating a shallow copy of the FluentLanguageLoader which can than be used just like the original loader but with a different current language setting. That makes it possible to use the fl! macro without any changes and is a far more elegant implementation than adding multiple get_lang* methods as done in #84.

For a future change I'd like to remove the RwLock and change that to a builder pattern. e.g. while building the loader you can still access the bundles in a mutable way but once the build is complete the internal language config is locked in and can't be changed anymore. That would get rid of locking primitive which is there just because of the set_use_isolating and with_bundles_mut methods.

This PR doesn't change the public API so it is a non-breaking change just like the other PR.

bikeshedder commented 2 years ago

I rebased this branch on the current master branch and marked the get_lang* methods as deprecated rather than removing them.

kellpossible commented 2 years ago

@bikeshedder did you still want to proceed with this?

bikeshedder commented 2 years ago

I do prefer this implementation over the other one. It's much cleaner and makes it possible to pick the language using the regular fl! macro without any further code changes.

kellpossible commented 1 year ago

Closed in favour of #100