Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement .NET MAUI localization

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?

like image 312
Brad Taylor Avatar asked Jan 31 '26 22:01

Brad Taylor


1 Answers

Try this - Create standard resources

  • "Add New Item/Resource File" > MauiApp1/Resources
  • set name "AppRes.resx"
  • create second lang "AppRes.ru.resx"
  • add strings

explorer resource view

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
    });


}
like image 164
mdimai666 Avatar answered Feb 03 '26 16:02

mdimai666



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!