[Proposal]: Localization with Fluent C# and XAML Support #3291
stephenquan
started this conversation in
New Feature Discussions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There have been several previous discussions, proposals, and pull requests exploring localization support within the CommunityToolkit ecosystem:
I'd like to revisit localization support for the .NET MAUI CommunityToolkit, this time focusing on .NET MAUI-specific capabilities such as Fluent C# extensions and XAML markup extensions that can make localized UI development simpler and more ergonomic.
Proposed API
N.B. This is a minimal skeleton of the proposed API. The GitHub repository below has additional details, such as additonal overloads on the Translate Fluent C# markup extension and the corresponding overloads on TranslateBindingBase.Create.
Example: Fluent C# localization
The following example demonstrates the
Translateextension method. Rather than supplying a static string,Translateaccepts a delegate that is evaluated on demand, allowing localized values to be re-resolved whenever the UI culture changesExample: XAML localization
The
Translatemarkup extension provides a simple XAML syntax for localization through a configurable localization provider and automatically updates bound UI elements when the active UI culture changes.While the
LocalizationProvidercan be implemented using any localization source, a RESX ResourceManager can be wired up as follows:Example: Runtime culture switching
CurrentUICultureis exposed through an observable wrapper that raises property change notifications. As a result, updating the value automatically triggers localization updates throughout the application.Example: Bindable arguments
If a localized resource has arguments, e.g. "Button clicked {0} times", the arguments may be supplied as bindings to the Translate markup extension rather than scalar values. For example:
Likewise, arguments can be provided through bindings as parameters to the Translate XAML markup extension using X0 or X1, e.g.
Example: TranslateBindingBase.Create
TranslateBindingBase.Create can also be used to create culture-aware bindings.
While this approach is more verbose than the Fluent C# Translate extension,
TranslateBindingBase.Createis provided to support MultiBinding scenarios that require a BindingBase instance and therefore cannot be implemented using the Fluent C# Translate extension.Example: Localize non-string types
The localization APIs are not limited to strings. Any bindable property can react to culture changes, enabling scenarios such as automatically switching FlowDirection or mirroring directional images for right-to-left languages.
Example: Localize collections
If a collection contains localization keys (for example,
"CHOICE_YES","CHOICE_NO", and"CHOICE_MAYBE"), theTranslatemarkup extension can bind to each key and automatically resolve the corresponding localized value:Example: Complex LocalizationProvider
LocalizationManager.Current.LocalizationProviderabstracts ResourceManager string lookups, allowing applications to source translations from one or more RESX files, custom resource managers, or third-party localization engines.Sample Implementation
The following repository contains source code for a working proof of concept, including fully functional backend implementations and examples of both the Fluent C# and XAML localization experiences within the .NET MAUI starter template application.
https://github.com/stephenquan/MauiLocalize2026
All reactions