I'm unable to find any direction on implementing localization for a MAUI app. I've read some info about localizing Xamarin apps but am unable to translate it forward to MAUI even after extensive web searching.
Can anyone point me to a reference that I may have missed?
Try this - Create standard resources

how use in XAML
[...] xmlns:res="clr-namespace:MauiApp1.Resources"
<Button Text="{x:Static res:AppRes.Title}" />
use code
//get lang as "en"
string lang = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
//toggle lang
if(lang == "ru")
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ru-RU");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ru-RU");
}
else
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
}
//get translated title
//using MauiApp1.Resources;
string title = AppRes.Title
And for update just reset app
(App.Current as App).MainPage = new AppShell();
That's All
UPD1: for restart from anywere
void Reset()
{
(App.Current as App).MainPage.Dispatcher.Dispatch(() =>
{
// there some LoadLang method;
(App.Current as App).MainPage = new AppShell();//REQUIRE RUN MAIN THREAD
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With