You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
Repository navigation
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
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.
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?
/// <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>publicstaticstringGetLocalized(thisstringresourceKey,stringresourcePath){// Try and retrieve resource at app level first.varresult=IndependentLoader.GetString(resourceKey);if(string.IsNullOrEmpty(result)){result=ResourceLoader.GetForViewIndependentUse(resourcePath).GetString(resourceKey);}returnresult;}
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?
@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 😀)
Activity
michael-hawker commentedon Sep 1, 2020
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?
michael-hawker commentedon Sep 1, 2020
Alright, I think this is the best choice in that we need to potentially do two lookups...
So before:
After:
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?
Initial Commit to Fix CommunityToolkit#3449
vgromfeld commentedon Sep 2, 2020
@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 😀)