-
Notifications
You must be signed in to change notification settings - Fork 562
[Xamarin.Android.Build.Tasks] Move XA4214 warning text into .resx file #3900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jonpryor
merged 4 commits into
dotnet:master
from
brendanzagaeski:error-warning-localization-1
Dec 7, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a071aec
[Xamarin.Android.Build.Tasks] Make XA4214 warning localizable
brendanzagaeski a52abde
Address review comments
brendanzagaeski a1b304e
Fix the Test MSBuild Azure Pipelines build
brendanzagaeski 08a5c40
Shorten some wording in workflow doc
brendanzagaeski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
*.Designer.cs eol=crlf | ||
|
||
*.cs text | ||
*.resx text | ||
*.xlf text | ||
*.xml text | ||
*.md text | ||
Makefile eol=lf | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Localization | ||
|
||
All new Xamarin.Android MSBuild error or warning messages should be localizable, | ||
so when adding a new message, follow these steps: | ||
|
||
1. Add the new message to | ||
`src/Xamarin.Android.Build.Tasks/Properties/Resources.resx`. Use the error | ||
or warning code as the resource name. For example, for `XA0000`, use | ||
`XA0000` as the name: | ||
|
||
![Managed Resources Editor with XA0000 as the name for a | ||
resource][resources-editor] | ||
|
||
Be sure to use Visual Studio or Visual Studio for Mac to edit the `.resx` | ||
file so that the `ResXFileCodeGenerator` tool will run and update the | ||
corresponding `Resources.Designer.cs` file. | ||
|
||
2. Use the generated property from `Resources.Designer.cs` in the | ||
`LogCodedError()` and `LogCodedWarning()` calls: | ||
|
||
```csharp | ||
Log.LogCodedError ("XA0000", Properties.Resources.XA0000); | ||
``` | ||
|
||
3. After adding the new message, build `Xamarin.Android.Build.Tasks.csproj` | ||
locally. This will run the targets from [dotnet/xliff-tasks][xliff-tasks] | ||
to update the `.xlf` [XLIFF][xliff] localization files with the latest | ||
changes from the `.resx` file. | ||
|
||
4. Include the changes to the`.resx` file as well as the generated changes to | ||
the `Resources.Designer.cs` file and the `.xlf` files in the commit. | ||
|
||
## Guidelines | ||
|
||
* When an error or warning code is used with more than one output string, use | ||
semantically meaningful suffixes to distinguish the resource names. As a | ||
made-up example: | ||
|
||
```xml | ||
<data name="XA0000_Files" xml:space="preserve"> | ||
<value>Invalid files.</value> | ||
</data> | ||
<data name="XA0000_Directories" xml:space="preserve"> | ||
<value>Invalid directories.</value> | ||
</data> | ||
``` | ||
|
||
* To include values of variables in the message, use numbered format items | ||
like `{0}` and `{1}` rather than string interpolation or string | ||
concatenation. | ||
|
||
The `.resx` infrastructure does not interoperate with C# 6 string | ||
interpolation. | ||
|
||
String concatenation should also be avoided because it means splitting up | ||
the message across multiple string resources, which makes it more | ||
complicated to provide appropriate context to the translators. | ||
|
||
* Use the comments field in the `.resx` file to provide additional context to | ||
the translators. For example, if a format item like `{0}` needs additional | ||
explanation, add a comment: | ||
|
||
``` | ||
{0} - The managed type name | ||
``` | ||
|
||
For a few more examples, see the dotnet/sdk repo: | ||
|
||
https://github.com/dotnet/sdk/blob/master/src/Tasks/Common/Resources/Strings.resx | ||
|
||
[resources-editor]: ../images/resources-editor-xa0000.png | ||
[xliff-tasks]: https://github.com/dotnet/xliff-tasks | ||
[xliff]: http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<_LocalizationLanguages Include="$(XlfLanguages)" /> | ||
</ItemGroup> | ||
</Project> |
81 changes: 81 additions & 0 deletions
81
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?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="XA4214" xml:space="preserve"> | ||
<value>The managed type `{0}` exists in multiple assemblies: {1}. Please refactor the managed type names in these assemblies so that they are not identical.</value> | ||
<comment>{0} - The managed type name | ||
{1} - Comma-separated list of all the assemblies where the managed type exists</comment> | ||
</data> | ||
<data name="XA4214_Result" xml:space="preserve"> | ||
<value>References to the type `{0}` will refer to `{0}, {1}`.</value> | ||
<comment>The phrase "`{0}, {1}`" does not need to be translated. | ||
{0} - The managed type name | ||
{1} - The the name of the library that contains the type</comment> | ||
</data> | ||
</root> |
20 changes: 20 additions & 0 deletions
20
src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.cs.xlf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd"> | ||
<file datatype="xml" source-language="en" target-language="cs" original="../Resources.resx"> | ||
<body> | ||
<trans-unit id="XA4214"> | ||
<source>The managed type `{0}` exists in multiple assemblies: {1}. Please refactor the managed type names in these assemblies so that they are not identical.</source> | ||
<target state="new">The managed type `{0}` exists in multiple assemblies: {1}. Please refactor the managed type names in these assemblies so that they are not identical.</target> | ||
<note>{0} - The managed type name | ||
{1} - Comma-separated list of all the assemblies where the managed type exists</note> | ||
</trans-unit> | ||
<trans-unit id="XA4214_Result"> | ||
<source>References to the type `{0}` will refer to `{0}, {1}`.</source> | ||
<target state="new">References to the type `{0}` will refer to `{0}, {1}`.</target> | ||
<note>The phrase "`{0}, {1}`" does not need to be translated. | ||
{0} - The managed type name | ||
{1} - The the name of the library that contains the type</note> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this property used by? I see no other references to
UpdateXlfOnBuild
within this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, whoops. I meant to surface all the notes from the new commit message. For this question, step 3 in particular is the key info.
The dotnet/xliff-tasks tasks and targets find
.resx
files in aproject, generate or update corresponding
.xlf
XLIFF files asneeded, and then build satellite assemblies from the
.xlf
files.Using xliff-tasks involves a few steps:
Add the dotnet-eng Azure DevOps NuGet package feed or the
dotnet-core MyGet NuGet package feed to
NuGet.config
. This commituses dotnet-eng because that appears to be the more up-to-date
recommendation, based on the dotnet/arcade README.
Add the XliffTasks NuGet package to the project to localize.
Set
$(UpdateXlfOnBuild)
totrue
for the project when buildinglocally, but not when building on CI. This follows the strategy
suggested in the xliff-tasks README:
This commit sets the property globally via
Configuration.props
tohelp make it easily visible to contributors.
Build the project to generate the initial set of
.xlf
files.Add the generated
.xlf
files to source control.Update the targets for the installer packages so that they include
the satellite assemblies generated by XliffTasks.
In the future, if
Xamarin.Android.Build.Tasks.csproj
is converted to ashort-form project, it would probably be best to add a dependency on
dotnet/arcade, set
$(UsingToolXliff)
totrue
, and then undo steps1-3 since dotnet/arcade takes care of those steps automatically.
I locally verified that the satellite assemblies were included in the
expected locations in both the Windows and macOS installers with this
commit in place.
I also locally verified that MSBuild used the text from
Resources.fr.xlf
for the XA4214 warning if I modifiedGenerateJavaStubs.Run()
to set bothThread.CurrentThread.CurrentCulture()
andThread.CurrentThread.CurrentUICulture()
tonew CultureInfo ("fr-FR")
.