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, useXA0000as the name:Be sure to use Visual Studio or Visual Studio for Mac to edit the
.resxfile so that theResXFileCodeGeneratortool will run and update the correspondingResources.Designer.csfile. -
Use the generated property from
Resources.Designer.csin theLogCodedError()andLogCodedWarning()calls:Log.LogCodedError ("XA0000", Properties.Resources.XA0000);
Or, to log a message directly from an MSBuild target, pass the name of the resource to the
ResourceNameparameter of the<AndroidError/>or<AndroidWarning/>task instead:<AndroidError Code="XA0000" ResourceName="XA0000" />
-
After adding the new message, build
Xamarin.Android.Build.Tasks.csprojlocally. This will run the targets from dotnet/xliff-tasks to update the.xlfXLIFF localization files with the latest changes from the.resxfile. -
Include the changes to the
.resxfile as well as the generated changes to theResources.Designer.csfile and the.xlffiles 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
.resxinfrastructure 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
.resxfile 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 nameFor a few more examples, see the dotnet/sdk repo:
https://github.com/dotnet/sdk/blob/master/src/Tasks/Common/Resources/Strings.resx
