Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ async Task<Stream> 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
}
Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "WindowsCommunityToolkit_BladeView_ExpandButton_Collapsed".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources");
if (_enlargeButton != null)
{
AutomationProperties.SetName(_enlargeButton, name);
Expand All @@ -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 = "WindowsCommunityToolkit_BladeView_ExpandButton_Expanded".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources");
if (_enlargeButton != null)
{
AutomationProperties.SetName(_enlargeButton, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "WindowsCommunityToolkit_GridSplitter_AutomationName".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources");
AutomationProperties.SetName(this, automationName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "WindowsCommunityToolkit_InAppNotification_DismissButton_AutomationName".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"));
}

if (_visualStateGroup != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "TextToolbarStrings_BoldLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"),
Icon = new SymbolIcon { Symbol = Symbol.Bold },
ShortcutKey = VirtualKey.B,
Activation = MakeBold
Expand All @@ -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 = "TextToolbarStrings_ItalicsLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"),
Icon = new SymbolIcon { Symbol = Symbol.Italic },
ShortcutKey = VirtualKey.I,
Activation = MakeItalics
Expand All @@ -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 = "TextToolbarStrings_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,
Expand All @@ -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 = "TextToolbarStrings_LinkLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"),
Icon = new SymbolIcon { Symbol = Symbol.Link },
ShortcutKey = VirtualKey.K,
Activation = OpenLinkCreator,
Expand All @@ -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 = "TextToolbarStrings_ListLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"),
Content = new TextToolbarSymbols.List(),
Activation = MakeList
};
Expand All @@ -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 = "TextToolbarStrings_OrderedListLabel".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources"),
Content = new TextToolbarSymbols.NumberedList(),
Activation = MakeOList
};
Expand Down
16 changes: 13 additions & 3 deletions Microsoft.Toolkit.Uwp/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,22 @@ public static string GetLocalized(this string resourceKey, UIContext uiContext =
}

/// <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)
=> ResourceLoader.GetForViewIndependentUse(resourcePath).GetString(resourceKey);
{
// Try and retrieve resource at app level first.
var result = IndependentLoader.GetString(resourceKey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hummmmm, have you tried this code path on Xaml Islands? We might need to use the other overload for GetLocalized, that accepts a UIContext, and force the use of this parameter, but I'm not 100% sure. Lets test it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azchohfi I can just try this out over here, eh?

https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/6a05a3c264407fbd1bee43fae57197a6e75af561/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_StringExtensions.cs#L26-L42

I'll just add a test that doesn't provide the UIContext? I'll try copying the three tests I have over there...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, create a test, just in case, and test it out on the Xaml Island test project, as the Xaml Islands tests are not automated into the CI.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azchohfi I tested this out and our API is working fine. However, the test itself was having trouble with the ApplicationLanguages.ManifestLanguages.ToArray() API as it only returned 1 result instead of 2 like in the default UWP cases... Any ideas? FYI @marb2000

I'll check-in the updates I do have with that line commented out for now.


if (string.IsNullOrEmpty(result))
{
result = ResourceLoader.GetForViewIndependentUse(resourcePath).GetString(resourceKey);
}

return result;
}
}
}
123 changes: 123 additions & 0 deletions UnitTests/UnitTests.UWP/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="TextToolbarStrings_ItalicsLabel" xml:space="preserve">
<value>ItalicsOverride</value>
</data>
</root>
123 changes: 123 additions & 0 deletions UnitTests/UnitTests.UWP/Strings/fr/Resources.resw
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="TextToolbarStrings_ItalicsLabel" xml:space="preserve">
<value>ItalicsFr</value>
</data>
</root>
Loading