diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs b/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs index d3cffd7038f..cdfdebe5b1c 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs @@ -331,7 +331,7 @@ async Task CopyStream(HttpContent source) // Takes a second copy of the image stream, so that is can save the image data to cache. using (var saveStream = await CopyStream(response.Content)) { - await SaveImageToCache(localpath, saveStream); + await SaveImageToCache(localPath, saveStream); } #endif } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Markdown/TextToolbar/Formats/MarkDown/MarkDownButtonActions.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Markdown/TextToolbar/Formats/MarkDown/MarkDownButtonActions.cs index f25f08f4f62..087c6f54caa 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Markdown/TextToolbar/Formats/MarkDown/MarkDownButtonActions.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Markdown/TextToolbar/Formats/MarkDown/MarkDownButtonActions.cs @@ -44,8 +44,8 @@ public override void FormatLink(ToolbarButton button, string label, string forma { var select = Formatter.Selected; int originalStart = Formatter.Selected.StartPosition; - string urlLabel = StringExtensions.GetLocalized("TextToolbarStrings_UrlLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"); - string labelLabel = StringExtensions.GetLocalized("TextToolbarStrings_LabelLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"); + string urlLabel = "WCT_TextToolbar_UrlLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"); + string labelLabel = "WCT_TextToolbar_LabelLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"); // Replaces Selection of first Line only. if (select.Text.Contains("\r")) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Markdown/TextToolbar/Formats/MarkDown/MarkDownFormatter.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Markdown/TextToolbar/Formats/MarkDown/MarkDownFormatter.cs index 75a714e1424..def51acba52 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Markdown/TextToolbar/Formats/MarkDown/MarkDownFormatter.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Markdown/TextToolbar/Formats/MarkDown/MarkDownFormatter.cs @@ -55,7 +55,7 @@ public void StyleHeader(ToolbarButton button) { Content = new MarkdownTextBlock { - Text = val + StringExtensions.GetLocalized("TextToolbarStrings_HeaderLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + Text = val + "WCT_TextToolbar_HeaderLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), IsTextSelectionEnabled = false }, Tag = val, @@ -462,7 +462,7 @@ public override ButtonMap DefaultButtons QuoteButton = new ToolbarButton { Name = QuoteElement, - ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_QuoteLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + ToolTip = "WCT_TextToolbar_QuoteLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Icon = new SymbolIcon { Symbol = Symbol.Message }, Activation = FormatQuote }; @@ -479,13 +479,13 @@ public override ButtonMap DefaultButtons { Name = HeadersElement, Icon = new SymbolIcon { Symbol = Symbol.FontSize }, - ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_HeaderLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + ToolTip = "WCT_TextToolbar_HeaderLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Activation = StyleHeader }, new ToolbarButton { Name = CodeElement, - ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_CodeLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + ToolTip = "WCT_TextToolbar_CodeLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Icon = new FontIcon { Glyph = "{}", FontFamily = new FontFamily("Segoe UI"), Margin = new Thickness(0, -5, 0, 0) }, Activation = FormatCode }, diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs index e02715d8b1a..79373541841 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs @@ -68,7 +68,7 @@ protected override void OnExpanded(EventArgs args) { Width = _normalModeWidth; VisualStateManager.GoToState(this, "Expanded", true); - var name = StringExtensions.GetLocalized("WindowsCommunityToolkit_BladeView_ExpandButton_Collapsed", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"); + var name = "WCT_BladeView_ExpandButton_Collapsed".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"); if (_enlargeButton != null) { AutomationProperties.SetName(_enlargeButton, name); @@ -84,7 +84,7 @@ protected override void OnCollapsed(EventArgs args) { Width = double.NaN; VisualStateManager.GoToState(this, "Collapsed", true); - var name = StringExtensions.GetLocalized("WindowsCommunityToolkit_BladeView_ExpandButton_Expanded", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"); + var name = "WCT_BladeView_ExpandButton_Expanded".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"); if (_enlargeButton != null) { AutomationProperties.SetName(_enlargeButton, name); diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.cs b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.cs index fbf0e750bd9..facc3230bf7 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.cs @@ -168,7 +168,7 @@ public GridSplitter() { DefaultStyleKey = typeof(GridSplitter); Loaded += GridSplitter_Loaded; - string automationName = StringExtensions.GetLocalized("WindowsCommunityToolkit_GridSplitter_AutomationName", "/Microsoft.Toolkit.Uwp.UI.Controls/Resources"); + string automationName = "WCT_GridSplitter_AutomationName".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"); AutomationProperties.SetName(this, automationName); } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs index 38ddced4e5e..7f2fd97cbfc 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs @@ -63,7 +63,7 @@ protected override void OnApplyTemplate() { _dismissButton.Visibility = ShowDismissButton ? Visibility.Visible : Visibility.Collapsed; _dismissButton.Click += DismissButton_Click; - AutomationProperties.SetName(_dismissButton, StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_DismissButton_AutomationName", "Microsoft.Toolkit.Uwp.UI.Controls/Resources")); + AutomationProperties.SetName(_dismissButton, "WCT_InAppNotification_DismissButton_AutomationName".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources")); } if (_visualStateGroup != null) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.xaml b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.xaml index 5277f9b09f9..01a49faa479 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.xaml @@ -30,7 +30,7 @@ - + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/Strings/en-US/Resources.resw b/Microsoft.Toolkit.Uwp.UI.Controls/Strings/en-US/Resources.resw index d3b003e8b80..bcad38e26ee 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/Strings/en-US/Resources.resw +++ b/Microsoft.Toolkit.Uwp.UI.Controls/Strings/en-US/Resources.resw @@ -117,107 +117,107 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Bold Label for TextToolbar Control bold button. - + Cancel Label for TextToolbar Control Cancel message. - + Code Label for TextToolbar Control Code button. - + Create Link Label for TextToolbar Control Create Link button. - + Empty Text Label for TextToolbar Control Empty Text. - + Header Label for TextToolbar Control Header button. - + Italics Label for TextToolbar Control italics button. - + Label Label for TextToolbar Control Label button. - + Link Invalid Label for TextToolbar Control Link Invalid message. - + Link Label for TextToolbar Control Link button. - + List Label for TextToolbar Control List button. - + Ok Label for TextToolbar Control Ok message. - + Ordered List Label for TextToolbar Control Ordered List button. - + Quote Label for TextToolbar Control Quote button. - + Relative Label for TextToolbar Control Relative. - + Strikethrough Label for TextToolbar Control Strikethrough button. - + Underline Label for TextToolbar Control Underline button. - + Url Label for TextToolbar Control Url button. - + Warning Label for TextToolbar Control Warning message. - + Collapse Blade Narrator Resource for BladeView collapsed status - + Expand Blade Narrator Resource for BladeView expanded status - + GridSplitter Narrator Resource for GridSplitter control - + Dismiss The automation name for the dismiss button of the InAppNotification control. - + Notification The landmark name for the InAppNotification control. It is said by the narrator when using landmark navigation. - + Remove Label for TokenizingTextBox MenuFlyout 'Remove' option. - + Select All Label for TokenizingTextBox MenuFlyout 'Select All' option. diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/Formats/RichText/RichTextFormatter.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/Formats/RichText/RichTextFormatter.cs index 6e792a24fd4..9bf8ea673d4 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/Formats/RichText/RichTextFormatter.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/Formats/RichText/RichTextFormatter.cs @@ -120,7 +120,7 @@ public override ButtonMap DefaultButtons StrikeButton = CommonButtons.Strikethrough; Underline = new ToolbarButton { - ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_UnderlineLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + ToolTip = "WCT_TextToolbar_UnderlineLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Icon = new SymbolIcon { Symbol = Symbol.Underline }, ShortcutKey = VirtualKey.U, Activation = ((RichTextButtonActions)ButtonActions).FormatUnderline diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/ToolbarItems/Common/CommonButtons.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/ToolbarItems/Common/CommonButtons.Events.cs index 89971602e55..68bc7b5314e 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/ToolbarItems/Common/CommonButtons.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/ToolbarItems/Common/CommonButtons.Events.cs @@ -54,13 +54,13 @@ public async void OpenLinkCreator(ToolbarButton button) var labelBox = new RichEditBox { - PlaceholderText = StringExtensions.GetLocalized("TextToolbarStrings_LabelLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + PlaceholderText = "WCT_TextToolbar_LabelLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Margin = new Thickness(0, 0, 0, 5), AcceptsReturn = false }; var linkBox = new TextBox { - PlaceholderText = StringExtensions.GetLocalized("TextToolbarStrings_UrlLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources") + PlaceholderText = "WCT_TextToolbar_UrlLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources") }; CheckBox relativeBox = null; @@ -78,7 +78,7 @@ public async void OpenLinkCreator(ToolbarButton button) { relativeBox = new CheckBox { - Content = StringExtensions.GetLocalized("TextToolbarStrings_RelativeLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources") + Content = "WCT_TextToolbar_RelativeLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources") }; contentPanel.Children.Add(relativeBox); } @@ -89,10 +89,10 @@ public async void OpenLinkCreator(ToolbarButton button) var contentDialog = new ContentDialog { - Title = StringExtensions.GetLocalized("TextToolbarStrings_CreateLinkLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + Title = "WCT_TextToolbar_CreateLinkLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Content = contentPanel, - PrimaryButtonText = StringExtensions.GetLocalized("TextToolbarStrings_OkLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), - SecondaryButtonText = StringExtensions.GetLocalized("TextToolbarStrings_CancelLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources") + PrimaryButtonText = "WCT_TextToolbar_OkLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + SecondaryButtonText = "WCT_TextToolbar_CancelLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources") }; if (ControlHelpers.IsXamlRootAvailable && button.XamlRoot != null) @@ -107,9 +107,9 @@ public async void OpenLinkCreator(ToolbarButton button) labelBox.Document.GetText(Windows.UI.Text.TextGetOptions.None, out string labelText); labelBox.Document.GetText(Windows.UI.Text.TextGetOptions.FormatRtf, out string formattedlabelText); - string linkInvalidLabel = StringExtensions.GetLocalized("TextToolbarStrings_LinkInvalidLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"); - string okLabel = StringExtensions.GetLocalized("TextToolbarStrings_OkLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"); - string warningLabel = StringExtensions.GetLocalized("TextToolbarStrings_WarningLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"); + string linkInvalidLabel = "WCT_TextToolbar_LinkInvalidLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"); + string okLabel = "WCT_TextToolbar_OkLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"); + string warningLabel = "WCT_TextToolbar_WarningLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"); string linkText = linkBox.Text.Trim(); if (string.IsNullOrWhiteSpace(linkText)) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/ToolbarItems/Common/CommonButtons.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/ToolbarItems/Common/CommonButtons.cs index 3328f0f3748..19c782e14bc 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/ToolbarItems/Common/CommonButtons.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TextToolbar/ToolbarItems/Common/CommonButtons.cs @@ -37,7 +37,7 @@ public ToolbarButton Bold return new ToolbarButton { Name = TextToolbar.BoldElement, - ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_BoldLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + ToolTip = "WCT_TextToolbar_BoldLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Icon = new SymbolIcon { Symbol = Symbol.Bold }, ShortcutKey = VirtualKey.B, Activation = MakeBold @@ -55,7 +55,7 @@ public ToolbarButton Italics return new ToolbarButton { Name = TextToolbar.ItalicsElement, - ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_StrikethroughLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + ToolTip = "WCT_TextToolbar_ItalicsLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Icon = new SymbolIcon { Symbol = Symbol.Italic }, ShortcutKey = VirtualKey.I, Activation = MakeItalics @@ -73,7 +73,7 @@ public ToolbarButton Strikethrough return new ToolbarButton { Name = TextToolbar.StrikethoughElement, - ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_StrikethroughLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + ToolTip = "WCT_TextToolbar_StrikethroughLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Icon = new FontIcon { Glyph = "\u0335a\u0335b\u0335c\u0335", FontFamily = new FontFamily("Segoe UI"), Margin = new Thickness(0, -5, 0, 0) }, Activation = MakeStrike, ShortcutKey = VirtualKey.Subtract, @@ -92,7 +92,7 @@ public ToolbarButton Link return new ToolbarButton { Name = TextToolbar.LinkElement, - ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_LinkLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + ToolTip = "WCT_TextToolbar_LinkLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Icon = new SymbolIcon { Symbol = Symbol.Link }, ShortcutKey = VirtualKey.K, Activation = OpenLinkCreator, @@ -111,7 +111,7 @@ public ToolbarButton List return new ToolbarButton { Name = TextToolbar.ListElement, - ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_ListLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + ToolTip = "WCT_TextToolbar_ListLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Content = new TextToolbarSymbols.List(), Activation = MakeList }; @@ -128,7 +128,7 @@ public ToolbarButton OrderedList return new ToolbarButton { Name = TextToolbar.OrderedElement, - ToolTip = StringExtensions.GetLocalized("TextToolbarStrings_OrderedListLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"), + ToolTip = "WCT_TextToolbar_OrderedListLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"), Content = new TextToolbarSymbols.NumberedList(), Activation = MakeOList }; diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs index 67971826868..0b9576a565a 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs @@ -185,7 +185,7 @@ protected override void OnApplyTemplate() var selectAllMenuItem = new MenuFlyoutItem { - Text = "WindowsCommunityToolkit_TokenizingTextBox_MenuFlyout_SelectAll".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources") + Text = "WCT_TokenizingTextBox_MenuFlyout_SelectAll".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources") }; selectAllMenuItem.Click += (s, e) => this.SelectAllTokensAndText(); var menuFlyout = new MenuFlyout(); @@ -349,7 +349,7 @@ protected override void PrepareContainerForItemOverride(DependencyObject element var removeMenuItem = new MenuFlyoutItem { - Text = "WindowsCommunityToolkit_TokenizingTextBoxItem_MenuFlyout_Remove".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources") + Text = "WCT_TokenizingTextBoxItem_MenuFlyout_Remove".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources") }; removeMenuItem.Click += (s, e) => TokenizingTextBoxItem_ClearClicked(tokenitem, null); @@ -361,7 +361,7 @@ protected override void PrepareContainerForItemOverride(DependencyObject element var selectAllMenuItem = new MenuFlyoutItem { - Text = "WindowsCommunityToolkit_TokenizingTextBox_MenuFlyout_SelectAll".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources") + Text = "WCT_TokenizingTextBox_MenuFlyout_SelectAll".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources") }; selectAllMenuItem.Click += (s, e) => this.SelectAllTokensAndText(); diff --git a/Microsoft.Toolkit.Uwp/Extensions/StringExtensions.cs b/Microsoft.Toolkit.Uwp/Extensions/StringExtensions.cs index ac3fe240312..1701e70ecdd 100644 --- a/Microsoft.Toolkit.Uwp/Extensions/StringExtensions.cs +++ b/Microsoft.Toolkit.Uwp/Extensions/StringExtensions.cs @@ -57,12 +57,22 @@ public static string GetLocalized(this string resourceKey, UIContext uiContext = } /// - /// 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. /// /// Resource key to retrieve. - /// Resource path to retrieve. + /// Resource path to fall back to in case resourceKey not found in app resources. /// string value for given resource or empty string if not found. public static string GetLocalized(this string resourceKey, string resourcePath) - => ResourceLoader.GetForViewIndependentUse(resourcePath).GetString(resourceKey); + { + // 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; + } } } diff --git a/UnitTests/UnitTests.UWP/Strings/en-us/Resources.resw b/UnitTests/UnitTests.UWP/Strings/en-us/Resources.resw new file mode 100644 index 00000000000..404a7e50ab7 --- /dev/null +++ b/UnitTests/UnitTests.UWP/Strings/en-us/Resources.resw @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ItalicsOverride + + \ No newline at end of file diff --git a/UnitTests/UnitTests.UWP/Strings/fr/Resources.resw b/UnitTests/UnitTests.UWP/Strings/fr/Resources.resw new file mode 100644 index 00000000000..813119439c2 --- /dev/null +++ b/UnitTests/UnitTests.UWP/Strings/fr/Resources.resw @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ItalicsFr + + \ No newline at end of file diff --git a/UnitTests/UnitTests.UWP/UI/Controls/Test_TextToolbar_Localization.cs b/UnitTests/UnitTests.UWP/UI/Controls/Test_TextToolbar_Localization.cs new file mode 100644 index 00000000000..e4acdf40096 --- /dev/null +++ b/UnitTests/UnitTests.UWP/UI/Controls/Test_TextToolbar_Localization.cs @@ -0,0 +1,109 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.Toolkit.Uwp.Helpers; +using Microsoft.Toolkit.Uwp.UI.Controls; +using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarButtons.Common; +using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.RichText; +using Microsoft.Toolkit.Uwp.UI.Extensions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer; +using System.Linq; +using System.Threading.Tasks; +using Windows.ApplicationModel.Core; +using Windows.Globalization; +using Windows.System; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Markup; + +namespace UnitTests.UI.Controls +{ + [TestClass] + public class Test_TextToolbar_Localization + { + /// + /// Tests the general ability to look-up a resource from the UI control as a base-case. + /// + [TestCategory("Test_TextToolbar_Localization")] + [UITestMethod] + public void Test_TextToolbar_Localization_Retrieve() + { + var treeRoot = XamlReader.Load( +@" + + + + +") as FrameworkElement; + + Assert.IsNotNull(treeRoot, "Could not load XAML tree."); + + var toolbar = treeRoot.FindChildByName("TextToolbarControl") as TextToolbar; + + Assert.IsNotNull(toolbar, "Could not find TextToolbar in tree."); + + var commonButtons = new CommonButtons(toolbar); + var boldButton = commonButtons.Bold; + + Assert.IsNotNull(boldButton, "Bold Button not found."); + + Assert.AreEqual("Bold", boldButton.ToolTip, "Label doesn't match expected default value."); + } + + /// + /// Tests the ability to override the resource lookup for a toolkit component in the app resource dictionary. + /// See Link:Strings/en-us/Resources.resw + /// + [TestCategory("Test_TextToolbar_Localization")] + [UITestMethod] + public void Test_TextToolbar_Localization_Override() + { + var commonButtons = new CommonButtons(new TextToolbar()); + var italicsButton = commonButtons.Italics; + + Assert.IsNotNull(italicsButton, "Italics Button not found."); + + Assert.AreEqual("ItalicsOverride", italicsButton.ToolTip, "Label doesn't match expected default value."); + } + + /// + /// Tests the ability to have different overrides in different languages. + /// + /// A representing the asynchronous operation. + [TestCategory("Test_TextToolbar_Localization")] + [TestMethod] + public async Task Test_TextToolbar_Localization_Override_Fr() + { + await CoreApplication.MainView.DispatcherQueue.ExecuteOnUIThreadAsync(async () => + { + // Just double-check we've got the right environment setup in our tests. + CollectionAssert.AreEquivalent(new string[] { "en-US", "fr" }, ApplicationLanguages.ManifestLanguages.ToArray(), "Missing locales for test"); + + // Override the default language for this test only (we'll set it back after). + var defaultLanguage = ApplicationLanguages.PrimaryLanguageOverride; + ApplicationLanguages.PrimaryLanguageOverride = "fr"; + + // Need to add a delay for release mode as otherwise the language switch doesn't kickover quick enough + // This should be sufficient as we're just using this as a test-harness. + await Task.Delay(3000); + + var commonButtons = new CommonButtons(new TextToolbar()); + var italicsButton = commonButtons.Italics; + + // Note: When running locally if the test somehow fails before the default is reset, then + // the tests will be in a bad state as PrimaryLanguageOverride is persisted. + // To fix this, uninstall the UnitTests UWP app and run the tests again. + ApplicationLanguages.PrimaryLanguageOverride = defaultLanguage; + + // Check for expected values. + Assert.IsNotNull(italicsButton, "Italics Button not found."); + + Assert.AreEqual("ItalicsFr", italicsButton.ToolTip, "Label doesn't match expected default value."); + }); + } + } +} diff --git a/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj index a9893fa92c0..d6b29c94c02 100644 --- a/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj +++ b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj @@ -180,6 +180,7 @@ + @@ -205,6 +206,10 @@ Designer + + + Designer + diff --git a/UnitTests/UnitTests.XamlIslands.UWPApp/FakeTestClasses/Assert.cs b/UnitTests/UnitTests.XamlIslands.UWPApp/FakeTestClasses/Assert.cs index c192ef9bfdc..fca5bc08d60 100644 --- a/UnitTests/UnitTests.XamlIslands.UWPApp/FakeTestClasses/Assert.cs +++ b/UnitTests/UnitTests.XamlIslands.UWPApp/FakeTestClasses/Assert.cs @@ -3,16 +3,37 @@ // See the LICENSE file in the project root for more information. using System; +using System.Linq; namespace Microsoft.VisualStudio.TestTools.UnitTesting { public static class Assert { - internal static void AreEqual(object expected, object actual) + internal static void AreEqual(object expected, object actual, string message = "") { if (!expected.Equals(actual)) { - throw new Exception($"Assert.AreEqual failed. Expected:<{expected}>. Actual:<{actual}>."); + throw new Exception($"Assert.AreEqual failed. Expected:<{expected}>. Actual:<{actual}>. {message}"); + } + } + + internal static void IsNotNull(object actual, string message = "") + { + if (actual == null) + { + throw new Exception($"Assert.IsNotNull failed. Expected:. Actual:. {message}"); + } + } + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Internal Types used to mimic unit test framework.")] + public static class CollectionAssert + { + internal static void AreEquivalent(T[] expected, T[] actual, string message = "") + { + if (expected.Length != actual.Length || expected.Intersect(actual).Count() != actual.Length) + { + throw new Exception($"CollectionAssert.AreEquivalent failed. Expected:<{expected.Length}>. Actual:<{actual.Length}>. {message}"); // TODO: Not sure what the actual message displays here... } } } diff --git a/UnitTests/UnitTests.XamlIslands.UWPApp/Strings/en-us/Resources.resw b/UnitTests/UnitTests.XamlIslands.UWPApp/Strings/en-us/Resources.resw index 291d768851a..1e8b69afad1 100644 --- a/UnitTests/UnitTests.XamlIslands.UWPApp/Strings/en-us/Resources.resw +++ b/UnitTests/UnitTests.XamlIslands.UWPApp/Strings/en-us/Resources.resw @@ -120,4 +120,7 @@ ABCDEF + + ItalicsOverride + \ No newline at end of file diff --git a/UnitTests/UnitTests.XamlIslands.UWPApp/UnitTests.XamlIslands.UWPApp.csproj b/UnitTests/UnitTests.XamlIslands.UWPApp/UnitTests.XamlIslands.UWPApp.csproj index 5d4f2ab6393..8b08d562ea9 100644 --- a/UnitTests/UnitTests.XamlIslands.UWPApp/UnitTests.XamlIslands.UWPApp.csproj +++ b/UnitTests/UnitTests.XamlIslands.UWPApp/UnitTests.XamlIslands.UWPApp.csproj @@ -204,6 +204,11 @@ + + + Strings\fr\Resources.resw + + 14.0 diff --git a/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_StringExtensions.cs b/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_StringExtensions.cs index fb59c2ca320..fd81c47a93b 100644 --- a/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_StringExtensions.cs +++ b/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_StringExtensions.cs @@ -2,10 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Linq; using System.Threading.Tasks; using Microsoft.Toolkit.Uwp.Extensions; using Microsoft.Toolkit.Uwp.Helpers; +using Microsoft.Toolkit.Uwp.UI.Controls; +using Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarButtons.Common; +using Microsoft.Toolkit.Uwp.UI.Extensions; using Microsoft.VisualStudio.TestTools.UnitTesting; +using Windows.Globalization; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Markup; namespace UnitTests.XamlIslands.UWPApp { @@ -29,7 +36,7 @@ public async Task StringExtensions_GetLocalized() await App.Dispatcher.ExecuteOnUIThreadAsync(() => { var xamlRoot = App.XamlRoot; - var str = StringExtensions.GetLocalized("abc", xamlRoot.UIContext); + var str = "abc".GetLocalized(xamlRoot.UIContext); Assert.AreEqual("ABCDEF", str); }); } @@ -37,8 +44,98 @@ await App.Dispatcher.ExecuteOnUIThreadAsync(() => [TestMethod] public void StringExtensions_GetLocalizedWithResourcePath() { - var str = StringExtensions.GetLocalized("TextToolbarStrings_OkLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"); + var str = "WCT_TextToolbar_OkLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"); Assert.AreEqual("Ok", str); } + + /// + /// Tests the general ability to look-up a resource from the UI control as a base-case. + /// + /// A representing the asynchronous unit test. + [TestMethod] + public async Task Test_TextToolbar_Localization_Retrieve() + { + await App.Dispatcher.ExecuteOnUIThreadAsync(() => + { + var treeRoot = XamlReader.Load( +@" + + + + +") as FrameworkElement; + + Assert.IsNotNull(treeRoot, "Could not load XAML tree."); + + var toolbar = treeRoot.FindChildByName("TextToolbarControl") as TextToolbar; + + Assert.IsNotNull(toolbar, "Could not find TextToolbar in tree."); + + var commonButtons = new CommonButtons(toolbar); + var boldButton = commonButtons.Bold; + + Assert.IsNotNull(boldButton, "Bold Button not found."); + + Assert.AreEqual("Bold", boldButton.ToolTip, "Label doesn't match expected default value."); + }); + } + + /// + /// Tests the ability to override the resource lookup for a toolkit component in the app resource dictionary. + /// See Link:Strings/en-us/Resources.resw + /// + /// A representing the asynchronous unit test. + [TestMethod] + public async Task Test_TextToolbar_Localization_Override() + { + await App.Dispatcher.ExecuteOnUIThreadAsync(() => + { + var commonButtons = new CommonButtons(new TextToolbar()); + var italicsButton = commonButtons.Italics; + + Assert.IsNotNull(italicsButton, "Italics Button not found."); + + Assert.AreEqual("ItalicsOverride", italicsButton.ToolTip, "Label doesn't match expected default value."); + }); + } + + /// + /// Tests the ability to have different overrides in different languages. + /// + /// A representing the asynchronous operation. + [TestMethod] + public async Task Test_TextToolbar_Localization_Override_Fr() + { + await App.Dispatcher.ExecuteOnUIThreadAsync(async () => + { + // Just double-check we've got the right environment setup in our tests. + //// Note: This seems to fail on XAML Islands, but the rest of the test works fine...? + ////CollectionAssert.AreEquivalent(new string[] { "en-US", "fr" }, ApplicationLanguages.ManifestLanguages.ToArray(), "Missing locales for test"); + + // Override the default language for this test only (we'll set it back after). + var defaultLanguage = ApplicationLanguages.PrimaryLanguageOverride; + ApplicationLanguages.PrimaryLanguageOverride = "fr"; + + // Need to add a delay for release mode as otherwise the language switch doesn't kickover quick enough + // This should be sufficient as we're just using this as a test-harness. + await Task.Delay(3000); + + var commonButtons = new CommonButtons(new TextToolbar()); + var italicsButton = commonButtons.Italics; + + // Note: When running locally if the test somehow fails before the default is reset, then + // the tests will be in a bad state as PrimaryLanguageOverride is persisted. + // To fix this, uninstall the UnitTests UWP app and run the tests again. + ApplicationLanguages.PrimaryLanguageOverride = defaultLanguage; + + // Check for expected values. + Assert.IsNotNull(italicsButton, "Italics Button not found."); + + Assert.AreEqual("ItalicsFr", italicsButton.ToolTip, "Label doesn't match expected default value."); + }); + } } } \ No newline at end of file