Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FluentLanguageLoader::lang method #88

Closed
wants to merge 5 commits into from

Conversation

bikeshedder
Copy link
Contributor

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.

This field was always the first loaded language or the
fallback_language so this field contained redundant
information.
This commit changes the internal structure of the FluentLanguageLoader
into a wrapper that contains an internal structure which can be copied
and replaced in a cheap way so that creating a copy of the loader is
as cheap as possible.
@bikeshedder
Copy link
Contributor Author

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

@kellpossible
Copy link
Owner

@bikeshedder did you still want to proceed with this?

@bikeshedder
Copy link
Contributor Author

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 pushed a commit that referenced this pull request Jan 14, 2023
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.

Co-authored-by: Michael P. Jung <[email protected]>
@kellpossible
Copy link
Owner

Closed in favour of #100

kellpossible added a commit that referenced this pull request Jan 14, 2023
Re-implementation of #59 (a rebase and cleanup of #88)

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.

Co-authored-by: Michael P. Jung <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants