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 FluentMultiLanguageLoader to allow easy translations access #62

Closed
wants to merge 8 commits into from

Conversation

saskenuba
Copy link

PR draft as discussed on #59

There is a lot of duplicated code because FluentLanguageLoader and FluentMultiLanguageLoader work the same way for loading and bundling, with exception of retrieval of translated strings. Perhaps moving some of this functionality as free functions?

Will work towards better docs of methods!

@kellpossible
Copy link
Owner

hey @saskenuba thanks again for the PR, sorry I haven't reviewed it yet, I'm in the middle of moving countries so I don't have much spare time, but hopefully in about a week I can get to it.

@saskenuba
Copy link
Author

no problem @kellpossible! take a look when you have the time.

@@ -373,3 +326,68 @@ impl LanguageLoader for FluentLanguageLoader {
Ok(())
}
}

/// Retrieve and load the file for the designated `LanguageIdentifier`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fallback_language variable is unused here, I think some of the original logic might have been been altered

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see the unused variable has been removed but I haven't spent the time to see how the error logic has been altered as a result of this.

i18n-embed/src/fluent/mod.rs Show resolved Hide resolved
i18n-embed/src/fluent/mod.rs Outdated Show resolved Hide resolved
saskenuba added 5 commits May 8, 2021 20:13
Signed-off-by: Martin <[email protected]>
FluentMultiLang loader only errors out if the fallback language is missing,
otherwise it skips to the next one. Added new error variant for this behaviour.

FluentLang remains with the same behaviour as before.

Signed-off-by: Martin <[email protected]>
@saskenuba
Copy link
Author

Hello @kellpossible! Sorry, it took so long to reply to this PR. I followed your thoughts and I believe the API is simplified now. Can you review it again?

Thanks!

@kellpossible
Copy link
Owner

hey @saskenuba thanks! I'll take another look at it as soon as I get the time 🙂

Copy link
Owner

@kellpossible kellpossible left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! just the breaking change comment with Cow for the arguments map. Happy to accept the change if there's a good reason and we can update the failing unit test and treat this as a breaking update.

@@ -113,7 +118,7 @@ impl FluentLanguageLoader {
pub fn get_args_concrete<'source>(
&self,
message_id: &str,
args: HashMap<&'source str, FluentValue<'source>>,
args: HashMap<Cow<'source, str>, FluentValue<'source>>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change (see fl_macro failing unit test), was there are particular motivation for using Cow over &str?

@kellpossible
Copy link
Owner

@saskenuba did you have a chance to look at this again?

@bikeshedder
Copy link
Contributor

I'm in need for a working translation system that is able to switch the language between requests. Sometimes even within a request when generating multi-language responses. So this PR does exactly what I need. I'd like to jump in and complete this work if @kellpossible doesn't want to finish it.

I guess this PR needs to be rebased on the master branch and that breaking change (use of Cow) taken care of. Is there anything else that needs to be done for this to get merged?

@kellpossible
Copy link
Owner

@bikeshedder thanks for the offer of contribution, it is well received! That sounds like a good summary, there is also this #62 (comment) that needs to be resolved.

@bikeshedder
Copy link
Contributor

This PR can be closed now that #84 is merged.

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.

Allow passing language to each localization request
3 participants