diff --git a/CommunityToolkit.WinUI.UI/Converters/ResourceNameToResourceStringConverter.cs b/CommunityToolkit.WinUI.UI/Converters/ResourceNameToResourceStringConverter.cs index 00fe921e5eb..8866c8e5c1b 100644 --- a/CommunityToolkit.WinUI.UI/Converters/ResourceNameToResourceStringConverter.cs +++ b/CommunityToolkit.WinUI.UI/Converters/ResourceNameToResourceStringConverter.cs @@ -13,7 +13,7 @@ namespace CommunityToolkit.WinUI.UI.Converters /// public sealed class ResourceNameToResourceStringConverter : IValueConverter { - private readonly ResourceLoader _resourceLoader = new ResourceLoader(); + private readonly ResourceManager _resourceManager = new ResourceManager(); /// /// Take the source string as a resource name that will be looked up in the App Resources. @@ -31,7 +31,7 @@ public object Convert(object value, Type targetType, object parameter, string la return string.Empty; } - return _resourceLoader.GetString(value.ToString()); + return _resourceManager.MainResourceMap.TryGetValue(value.ToString()).ValueAsString; } /// diff --git a/CommunityToolkit.WinUI/Extensions/StringExtensions.cs b/CommunityToolkit.WinUI/Extensions/StringExtensions.cs index 4a46ea95066..3d111d9d6d1 100644 --- a/CommunityToolkit.WinUI/Extensions/StringExtensions.cs +++ b/CommunityToolkit.WinUI/Extensions/StringExtensions.cs @@ -11,13 +11,13 @@ namespace CommunityToolkit.WinUI /// public static class StringExtensions { - private static readonly ResourceLoader Loader; + private static readonly ResourceManager ResourceManager; static StringExtensions() { try { - Loader = new ResourceLoader(); + ResourceManager = new ResourceManager(); } catch { @@ -47,7 +47,7 @@ public static string GetViewLocalized(this string resourceKey, UIContext uiConte /// string value for given resource or empty string if not found. public static string GetLocalized(this string resourceKey) { - return Loader?.GetString(resourceKey); + return ResourceManager.MainResourceMap.TryGetValue(resourceKey)?.ValueAsString; } /* @@ -75,11 +75,20 @@ public static string GetLocalized(this string resourceKey, UIContext uiContext) public static string GetLocalized(this string resourceKey, string resourcePath) { // Try and retrieve resource at app level first. - var result = Loader?.GetString(resourceKey); + var result = ResourceManager.MainResourceMap.TryGetValue(resourceKey)?.ValueAsString; if (string.IsNullOrEmpty(result)) { - result = new ResourceLoader(ResourceLoader.GetDefaultResourceFilePath(), resourcePath).GetString(resourceKey); + var manager = new ResourceManager(); + var subTree = manager.MainResourceMap.TryGetSubtree(resourcePath); + if (subTree != null) + { + var r = subTree.TryGetValue(resourceKey); + if (r != null) + { + result = r.ValueAsString; + } + } } return result;