banditoth.MAUI.Multilanguage
1.0.4
See the version list below for details.
dotnet add package banditoth.MAUI.Multilanguage --version 1.0.4
NuGet\Install-Package banditoth.MAUI.Multilanguage -Version 1.0.4
<PackageReference Include="banditoth.MAUI.Multilanguage" Version="1.0.4" />
paket add banditoth.MAUI.Multilanguage --version 1.0.4
#r "nuget: banditoth.MAUI.Multilanguage, 1.0.4"
// Install banditoth.MAUI.Multilanguage as a Cake Addin #addin nuget:?package=banditoth.MAUI.Multilanguage&version=1.0.4 // Install banditoth.MAUI.Multilanguage as a Cake Tool #tool nuget:?package=banditoth.MAUI.Multilanguage&version=1.0.4
banditoth's MAUI.Packages 🏝
A toolkit for .NET MAUI, containing useful stuff to ease development for MAUI applications.
banditoth.MAUI.Multilanguage
A multilanguage translation provider for XAML and for code behind.
Tutorial
A full tutorial can be found here https://www.banditoth.net/2022/08/29/net-maui-write-multilingual-apps-easily/
Usage
Create your resx
files in your solution. For example if your applications default language is English, create a Translations.en.resx
file, which contains the english translations, and if you want to support Hungarian language, you need to create a Translations.hu.resx
file, which will contain the hungarian key value pairs.
You can add different resx files, also from different assembly. Just call the UseResource
when initalizing the plugin multiple times.
Usage in cs files: Inject or resolve an ITranslator instance from the dependency continaer.
public string Foo()
{
// Get the currently set culture
if(translator.CurrentCulture.Name != "English")
// Set the culture by calling SetCurrentCulture
translator.SetCurrentCulture(new CultureInfo("en"));
// Get the translation from resources
return translator.GetTranslation("The_Translation_Key")
}
Usage in XAML files:
Start using translations in your XAML by adding reference to the clr-namespace
and using the markup extension:
xmlns:multilanguage="clr-namespace:banditoth.MAUI.Multilanguage"
Whenever you need a translation, you can use:
<Label IsVisible="True"
Text="{multilanguage:Translation Key=TranslationKey}"/>
Initalization
Initalize the plugin within your MauiProgram.cs
's CreateMauiApp
method.
Use the .ConfigureMultilanguage
extension method with the using banditoth.MAUI.Multilanguage
;
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
.ConfigureMultilanguage(config =>
{
// Set the source of the translations
// You can use multiple resource managers by calling UseResource multiple times.
config.UseResource(YourAppResource.ResourceManager);
config.UseResource(YourAnotherAppResource.ResourceManager);
// If the app is not storing last used culture, this culture will be used by default
config.UseDefaultCulture(new System.Globalization.CultureInfo("en-US"));
// Determines whether the app should store the last used culture
config.StoreLastUsedCulture(true);
// Determines whether the app should throw an exception if a translation is not found.
config.ThrowExceptionIfTranslationNotFound(false);
// You can set custom translation not found text by calling this method
config.SetTranslationNotFoundText("Transl_Not_Found:", appendTranslationKey: true);
});
return builder.Build();
}
Icon
https://www.flaticon.com/free-icons/responsive" Responsive icons created by rukanicon - Flaticon
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-android31.0 is compatible. net6.0-ios was computed. net6.0-ios15.4 is compatible. net6.0-maccatalyst was computed. net6.0-maccatalyst15.4 is compatible. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.Maui.Dependencies (>= 6.0.486)
- Microsoft.Maui.Extensions (>= 6.0.486)
-
net6.0-android31.0
- Microsoft.Maui.Dependencies (>= 6.0.486)
- Microsoft.Maui.Extensions (>= 6.0.486)
-
net6.0-ios15.4
- Microsoft.Maui.Dependencies (>= 6.0.486)
- Microsoft.Maui.Extensions (>= 6.0.486)
- System.Runtime.InteropServices.NFloat.Internal (>= 6.0.1)
-
net6.0-maccatalyst15.4
- Microsoft.Maui.Dependencies (>= 6.0.486)
- Microsoft.Maui.Extensions (>= 6.0.486)
- System.Runtime.InteropServices.NFloat.Internal (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.6 | 912 | 7/19/2024 |
1.0.5 | 6,952 | 12/20/2022 |
1.0.4 | 1,817 | 8/29/2022 |
1.0.3 | 390 | 8/29/2022 |
1.0.1 | 399 | 8/29/2022 |
1.0.0-pre3 | 176 | 5/31/2022 |
1.0.0-pre2 | 292 | 5/31/2022 |
1.0.0-pre1 | 148 | 5/17/2022 |
TBD