Localization RESX File

Version: v9.x

In the MauiProgram.cs file,

builder
    .UseMauiApp<App>()
    .UseMauiMarkupLocalizationWithResx(AppResources.ResourceManager);
    // .UseMauiMarkupLocalizationWithResx(AppResources.ResourceManager, "en-US"); // set default lang

should be added.

You should have source files with the extension resx in your project. The translation will be read from this file and imported. Then, in MauiProgram.cs, pass your ResourceManager value as a parameter to UseMauiMarkupLocalizationWithResx.

You can also change the 'tr-TR' and 'en-US' language keys with words or sentences as you wish. But it is recommended to use expressions such as 'en-US', 'tr-TR', 'fr-FR'.

You can change the language of the system with the following statement: TranslatorResx.Instance.ChangeCulture(CultureInfo.GetCultureInfo("en-US"));

You can simply use

new Label()
.Text(e => e.TranslateResx("Hello"))
.FontSize(32)
.CenterHorizontal()
.SemanticHeadingLevel(SemanticHeadingLevel.Level1),

new Label()
.Text(e => e.TranslateResx(nameof(AppResource.Msg)))
.FontSize(18)
.CenterHorizontal()
.SemanticDescription(e => e.TranslateResx("Msg"))
.SemanticHeadingLevel(SemanticHeadingLevel.Level1),

new VerticalStackLayout()
.Center()
.Children(
    new RadioButton()
    .IsChecked(TranslatorResx.Instance.CurrentCulture.Name == "tr-TR")
    .Content("tr-TR")
    .OnCheckedChanged((sender, e) =>
    {
        TranslatorResx.Instance.ChangeCulture(CultureInfo.GetCultureInfo("tr-TR"));
    }),
    new RadioButton()
    .IsChecked(TranslatorResx.Instance.CurrentCulture.Name == "en-US")
    .Content("en-US")
    .OnCheckedChanged((sender, e) =>
    {
        TranslatorResx.Instance.ChangeCulture(CultureInfo.GetCultureInfo("en-US"));
    })
)

in the code.