All new Xamarin.Android MSBuild error or warning messages should be localizable, so when adding a new message, follow these steps:
-
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, forXA0000
, useXA0000
as the name:Be sure to use Visual Studio or Visual Studio for Mac to edit the
.resx
file so that theResXFileCodeGenerator
tool will run and update the correspondingResources.Designer.cs
file. -
Use the generated property from
Resources.Designer.cs
in theLogCodedError()
andLogCodedWarning()
calls:Log.LogCodedError ("XA0000", Properties.Resources.XA0000);
-
After adding the new message, build
Xamarin.Android.Build.Tasks.csproj
locally. This will run the targets from dotnet/xliff-tasks to update the.xlf
XLIFF localization files with the latest changes from the.resx
file. -
Include the changes to the
.resx
file as well as the generated changes to theResources.Designer.cs
file and the.xlf
files in the commit.
-
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:
<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