Closed Letram closed 1 year ago
@jsakamoto
Would be really nice to have / know
would it be possible to post is, or get the demo code?
Thank you for asking me.
The source code of the demo is in the following link:
And you can see the code that changes the current language in the MainLayout.razor
.
You can also see another example in the following link that is a part of another standalone Blazor WebAssembly app:
The point is just calling the I18nText.SetCurrentLanguageAsync("{language code}")
method.
Please remember the "Blazor I18n Text" library doesn't provide any UI components and doesn't care about the CurrentCulture
and CurrentUICulture
of the current thread. For example, even if you change the language from "en" to "fr" by calling I18nText.SetCurrentLanguageAsync("fr")
, CultureInfo.CurrentCulture
and CultureInfo.CurrentUICulture
would never be changed. If you want to make the CultureInfo.CurrentCulture
and CultureInfo.CurrentUICulture
follow to the language settings on the I18nText service, you have to subscribe the ChanegLanguage
event of the I18nText service and do it by yourself (I don't have examples of doing that for now).
And also, on Blazor Server apps, you should know that changing the CultureInfo.CurrentCulture
and CultureInfo.CurrentUICulture
in the application thread doesn't work expectedly. The change will be dropped next event handling. That is by the design of Blazor Server apps. To change the culture of Blazor Server apps, you have to set the cookie and restart the entire session.
Appendix: If you don't mind dirty hacking, there is a NuGet package that allows you to change the culture of the current session of Blazor Server apps on the fly without restarting. (if you have an interest in it, follow the link below.)
yeah I have tried to implement the example into my solution, after digging around in the solution, I found your examples
but cant seam to get it to work?
as seen her:
https://github.com/jsakamoto/Toolbelt.Blazor.I18nText/issues/56
Is there any available demo of the project to see how to change the current culture of the app?