SQuan.Helpers.Maui.Localization
9.0.19
See the version list below for details.
dotnet add package SQuan.Helpers.Maui.Localization --version 9.0.19
NuGet\Install-Package SQuan.Helpers.Maui.Localization -Version 9.0.19
<PackageReference Include="SQuan.Helpers.Maui.Localization" Version="9.0.19" />
<PackageVersion Include="SQuan.Helpers.Maui.Localization" Version="9.0.19" />
<PackageReference Include="SQuan.Helpers.Maui.Localization" />
paket add SQuan.Helpers.Maui.Localization --version 9.0.19
#r "nuget: SQuan.Helpers.Maui.Localization, 9.0.19"
#:package SQuan.Helpers.Maui.Localization@9.0.19
#addin nuget:?package=SQuan.Helpers.Maui.Localization&version=9.0.19
#tool nuget:?package=SQuan.Helpers.Maui.Localization&version=9.0.19
SQuan.Helpers.Maui.Localization
The SQuan.Helpers.Maui.Localization
provides a localization resource manager, a XAML markup extension and a C# extension method to make localization easier.
Installation
In order to use the toolkit correctly the UseSQuanHelpersMauiLocalization method must be called with your string resource on the MauiAppBuilder class when bootstrapping an application the MauiProgram.cs file. The following example shows how to perform this.
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseSQuanHelperMauiLocalization<AppStrings>()
Include the XAML namespace
In order to use the Localize markup extension in XAML, the following xmlns
needs to be added into your page or view:
xmlns:i18n="clr-namespace:SQuan.Helpers.Maui.Localization;assembly=SQuan.Helpers.Maui.Localization"
Include the C# namespace
In order to use the Localize extension method in C#, the following using
statement needs to be added into your file:
using SQuan.Helpers.Maui.Localization;
Get/Set culture values through the LocalizationManager
The LocalizationManager provides wrappers for InstalledUICulture,CurrentCulture and CurrentUICulture. These wrappers have property change and other event notification to ensure changes in culture are broadcasted to localized strings.
var de_DE = new CultureInfo("de-DE");
LocalizationManager.Current.CurrentCulture = de_DE; // Set date, time, currency to Germany.
LocalizationManager.Current.CurrentUICulture = de_DE; // Set strings to German.
XAML Localize markup extension example
You can use the Localize markup extension in XAML to assign localize string resources to your text properties, e.g.
<Label
SemanticProperties.HeadingLevel="Level1"
Style="{StaticResource Headline}"
Text="{i18n:Localize LBL_HELLO}" />
C# Localize extension method example
You can use the Localize extension method in C# to assign localize string resources to your text properties with parameters, e.g.
[RelayCommand]
void IncrementCounter()
{
Count++;
CounterBtn.Localize(Button.TextProperty, "BTN_CLICKED_N_TIMES", Count);
SemanticScreenReader.Announce(CounterBtn.Text);
}
C# Localize extension method with bindings
You can use the Localize extension method in C# to assign localization string resources to your text properties with bindings.
public MainPage()
{
BindingContext = this;
InitializeComponent();
CounterBtn.Localize(
Button.TextProperty,
"BTN_CLICKED_N_TIMES",
BindingBase.Create(static (LocalizePage m) => m.Count, BindingMode.OneWay, source: this));
}
[RelayCommand]
void IncrementCounter()
{
Count++;
SemanticScreenReader.Announce(CounterBtn.Text);
}
XAML Localize markup extension with bindings
You can use the Localize markup extension in XAML to assign localize string resources to your text properties with bindings.
<Button
x:Name="CounterBtn"
Command="{Binding IncrementCounterCommand}"
HorizontalOptions="Start"
Text="{i18n:Localize BTN_CLICKED_N_TIMES, X0={Binding Count}}" />
Further information
For more information please visit:
- Documentation: https://github.com/stephenquan/SQuan.Helpers.Maui/wiki/Localization
- GitHub repository: https://github.com/stephenquan/SQuan.Helpers.Maui
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0-android35.0 is compatible. net9.0-ios18.0 is compatible. net9.0-maccatalyst18.0 is compatible. net9.0-windows10.0.19041 is compatible. net10.0-android was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-windows was computed. |
-
net9.0-android35.0
- Microsoft.Extensions.Localization (>= 9.0.6)
-
net9.0-ios18.0
- Microsoft.Extensions.Localization (>= 9.0.6)
-
net9.0-maccatalyst18.0
- Microsoft.Extensions.Localization (>= 9.0.6)
-
net9.0-windows10.0.19041
- Microsoft.Extensions.Localization (>= 9.0.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.