Skip to content

[Feature] Markup Extension for Resource string localizationΒ #3662

@HerrickSpencer

Description

@HerrickSpencer

Describe the problem this feature would solve

Microsoft's current documentation shows examples of how to globalize your UI facing strings in UWP/WPF XAML by using the Uid as a lookup in an included resx file. This technique works great, but does have some limitations. There is another way of using a custom markup extension to keep the UI development agile, as well as reduce globalization costs when redesigning UI.
Commonly used resources technique:

 <Button x:Uid="MyButton"/>

Using the markup extension:

<Button Content="{str:ResourceString Name=ButtonText}"/>

This method reduces friction in globalization efforts and translation when there are UI redesigns. Because the developer will not be tied to a Uid, they can reuse the already translated strings in resources by referencing the string name instead. It also allows one string to be used for multiple controls without the problem of duplicating the Uid.

Describe the solution

The ResourceString code example would look like this:

    private static ResourceLoader resourceLoader = ResourceLoader.GetForCurrentView();

    [MarkupExtensionReturnType(ReturnType = typeof(string))]
    public sealed class ResourceString : MarkupExtension
    {
        public string Name
        {
            get; set;
        }

        protected override object ProvideValue()
        {
            return resourceLoader.GetString(this.Name);
        }
    }

Where it would live in the code base is with the other markup extensions

Describe alternatives you've considered

Using the Uid, but it has issues as detailed above.

Additional context & Screenshots

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions