cargo-i18n icon indicating copy to clipboard operation
cargo-i18n copied to clipboard

Add FluentLanguageLoader::lang method

Open bikeshedder opened this issue 3 years ago • 3 comments

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

This PR adds a single new method:

  • lang

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 avatar Feb 23 '22 02:02 bikeshedder

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

bikeshedder avatar Feb 23 '22 19:02 bikeshedder

@bikeshedder did you still want to proceed with this?

kellpossible avatar Mar 21 '22 11:03 kellpossible

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.

bikeshedder avatar Mar 21 '22 12:03 bikeshedder

Closed in favour of #100

kellpossible avatar Jan 14 '23 06:01 kellpossible