-
Notifications
You must be signed in to change notification settings - Fork 10
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
Setting locale based on browser language #87
Comments
What do you mean by that? A browser will send a weighted list of supported languages with the request, by default the server look at that list and choose the locale based on that, the only moment it does not do that is when a different locale is set on the client with the |
@Baptistemontan I mean like this i18next plugin: https://www.npmjs.com/package/i18next-browser-languagedetector |
I'm working on v0.3 and want to better understand what you are asking. At the moment the locale is decided in those steps:
I know that for now the implementation of step 2 is really naive, I'll look into it to have a more robust implementation. Could you give me a list of what detection methods you would like to get added ? |
Hello @Baptistemontan ! let Some(navigator) = leptos_use::use_window().navigator() else {
return crate::i18n::Locale::default();
};
let locales: Vec<String> = navigator
.languages()
.into_iter()
.filter_map(|val| val.as_string())
.collect();
crate::18n::Locale::find_locale(&locales) Which is pretty handful as it allows me to have my website translated given the browser's language, and if none is found, the default is used, which is the behavior I would expect on most websites. Especially when it comes to CSR, it makes the UX much better. Regarding SSR, I must tell that I never used it, but ig as you mentioned, using the Let me know if I can help on this ! It would make this crate even more useful for everyone 😄 |
I completly forgot about this issue, I could'nt really understand what was the problem because with ssr it worked, I did'nt realised the problem was with csr. I just hit that problem trying to implement end to end testing for the examples for a more robust CI and I basically came up with the same implementation as @nag763. The fix is with #108, I have some small things to finish up before releasing a new version, but it will come soon. For the time being I'm closing this issue, sorry for the wait it's been a rough 6 months for me |
It would be nice to have a helper function to set the locale based on the browser language if it's not set already.
The text was updated successfully, but these errors were encountered: