Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

[Testing] Check for overriding string resources in the controls package #3449

Closed

Description

@michael-hawker

Describe the problem this feature would solve

If a developer wants to override a string resource from a control in the Toolkit, we have no guidance on how to do this.

Describe the solution

I believe they can just append the assembly name to the resource key in their own app's resource file to do this, I thought I had tested this, but we should have an actual test case and document how this can be done.

Additional context & Screenshots

Some info about resources here

Activity

  1. added this to the 7.0 milestone on Aug 25, 2020
  2. michael-hawker commented on Sep 1, 2020

    @michael-hawker
    MemberAuthor

    Alright, so if we don't specify the resource path in the toolkit usages, then we can override it, but then the toolkit can't find it either for the default value.

    We almost need a fallback approach where we look things up first without a path and then look for the path afterwards?

  3. michael-hawker commented on Sep 1, 2020

    @michael-hawker
    MemberAuthor

    Alright, I think this is the best choice in that we need to potentially do two lookups...

    So before:

            public static string GetLocalized(this string resourceKey, string resourcePath)
                => ResourceLoader.GetForViewIndependentUse(resourcePath).GetString(resourceKey);

    After:

            /// <summary>
            /// Retrieves the provided resource for the given key for use independent of the UI thread.
            /// Retrieves the provided resource for the given key for use independent of the UI thread. First looks up resource at the application level, before falling back to provided resourcePath. This allows for easily overridable resources within a library.
            /// </summary>
            /// <param name="resourceKey">Resource key to retrieve.</param>
            /// <param name="resourcePath">Resource path to retrieve.</param>
            /// <param name="resourcePath">Resource path to fall back to in case resourceKey not found in app resources.</param>
            /// <returns>string value for given resource or empty string if not found.</returns>
            public static string GetLocalized(this string resourceKey, string resourcePath)
            {
                // Try and retrieve resource at app level first.
                var result = IndependentLoader.GetString(resourceKey);
    
                if (string.IsNullOrEmpty(result))
                {
                    result = ResourceLoader.GetForViewIndependentUse(resourcePath).GetString(resourceKey);
                }
    
                return result;
            }

    Good news is that it wouldn't be a breaking code change, just behavioral, and should make it easier for any developer to allow for this type of 'override'.

    @Sergio0694 I'm assuming there's a more performant way we can do this?

    @vgromfeld I can do some further testing here, for instance different locales, but how does this seem to you?

  4. added a commit that references this issue on Sep 1, 2020
    ff5f32f
  5. vgromfeld commented on Sep 2, 2020

    @vgromfeld
    Contributor

    @michael-hawker It seems good to me. I allows apps to easily override strings in their own resources files without the need of another file (which reduces the burden on the localization teams 😀)

  6. ghost locked as resolved and limited conversation to collaborators on Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions