# LocalizationResourceManager.Maui **Repository Path**: LiuShuiRuoBing/LocalizationResourceManager.Maui ## Basic Information - **Project Name**: LocalizationResourceManager.Maui - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-28 - **Last Updated**: 2025-10-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LocalizationResourceManager.Maui Buy Me A Coffee Enhanced .NET MAUI version of the Xamarin Community Toolkit LocalizationResourceManager. ## NuGet |Name|Info| | ------------------- | :------------------: | |LocalizationResourceManager.Maui|[![NuGet](https://img.shields.io/nuget/v/LocalizationResourceManager.Maui)](https://www.nuget.org/packages/LocalizationResourceManager.Maui/#versions-body-tab)| ## Background I have been a fan of the Localization helpers and extensions in the [Xamarin Community Toolkit](https://github.com/xamarin/XamarinCommunityToolkit) and have been using this in my Xamarin projects. Since moving to [.NET MAUI](https://github.com/dotnet/maui), I hoped for this to be part of the [MAUI Community Toolkit](https://github.com/CommunityToolkit/Maui). For good reasons the team has decided not to include this in MCT and a [proposal](https://github.com/CommunityToolkit/dotnet/issues/312) is issued in the [.NET Community Toolkit](https://github.com/CommunityToolkit/dotnet). But the XCT solution have dependencies to the Xamarin `IMarkupExtension` interface and the XCT `WeakEventManager` helper class, which makes it tricky to port to a non MAUI library. So until we have a official solution, or anyway is added to MCT, I have created this library for .NET MAUI. Big shoutout to the original authors, [Charlin Agramonte](https://github.com/Char0394), [Brandon Minnick](https://github.com/brminnick), [Maksym Koshovyi](https://github.com/maxkoshevoi) and the entire [Xamarin Community Toolkit Team](https://github.com/xamarin/XamarinCommunityToolkit/graphs/contributors)! ## What's included? Compared to the original solution we have some enhanced and added features: - Easy setup with builder pattern extension - Supports multiple Resource managers - Supports file based Resource managers - Supports storing and restoring of the latest set culture - New `ILocalizationResourceManager` interface registered for constructor injection with DI - Stores current Default / System culture - Supports Resource names with dots. - Option to set a placeholder text to be displayed if text is not found. - `TranslateBindingExtension` for custom binding with format and plural support in XAML by [Stephen Quan](https://github.com/stephenquan). - Uses the [WeakEventManager](https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.weakeventmanager) (.NET MAUI) For localized texts used in XAML and/or code behind, we still have: - `TranslateExtension` (XAML Markup Extension) - `LocalizedString` (Track Culture Change in code behind) ## Setup Use the `UseLocalizationResourceManager`builder pattern extension method for library configuration. ```csharp var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }) .UseLocalizationResourceManager(settings => { settings.AddResource(AppResources.ResourceManager); settings.RestoreLatestCulture(true); }); ``` Settings contains 6 methods for configuration: - **AddResource** (Add one or more Resource Managers) - **AddFileResource** (Add file based Resource Managers. Create/Read/Write at runtime with [ResourceWriter](https://learn.microsoft.com/en-us/dotnet/api/system.resources.resourcewriter) and [ResourceReader](https://learn.microsoft.com/en-us/dotnet/api/system.resources.resourcereader).) - **InitialCulture** (Set initial/startup culture, Default: Current System Culture) - **RestoreLatestCulture** (Restore latest set culture flag, Default: false, Note: Will override InitalCulture!) - **SupportNameWithDots** (Activate support for Resource Names with Dots when used with TranslateExtension. Option to set custom dot substitution. Default: "_") - **SuppressTextNotFoundException** (Suppress/Deactivate throwing the text not found exception. Option to set a placeholder text to be displayed if text is not found.) ## Use in XAML When used for localized texts in XAML pages, use the `TranslateExtension`: - Add namespace reference to library. - Use Translate extension with name of resource. (All resource libraries will be searched until name is found!) ```csharp ``` ```csharp