|
| 1 | +# Localization |
| 2 | + |
| 3 | +All new Xamarin.Android MSBuild error or warning messages should be localizable, |
| 4 | +so when adding a new message, follow these steps: |
| 5 | + |
| 6 | + 1. Add the new message to |
| 7 | + `src/Xamarin.Android.Build.Tasks/Properties/Resources.resx`. Use the |
| 8 | + message code as the name of the resource. For example, for the message text |
| 9 | + associated with code `XA0000`, use `XA0000` as the name: |
| 10 | + |
| 11 | + ![Managed Resources Editor with XA0000 as the name for a |
| 12 | + resource][resources-editor] |
| 13 | + |
| 14 | + Be sure to use Visual Studio or Visual Studio for Mac to edit the `.resx` |
| 15 | + file so that the `ResXFileCodeGenerator` tool will run and update the |
| 16 | + corresponding `Resources.Designer.cs` file. |
| 17 | + |
| 18 | + 2. In the call to `LogCodedError()` or `LogCodedWarning()`, reference the |
| 19 | + message string using the generated C# property name like |
| 20 | + `Properties.Resources.XA0000`. |
| 21 | + |
| 22 | + 3. After adding the new message, build `Xamarin.Android.Build.Tasks.csproj` |
| 23 | + locally. This will run the targets from [dotnet/xliff-tasks][xliff-tasks] |
| 24 | + to update the `.xlf` [XLIFF][xliff] localization files with the latest |
| 25 | + changes from the `.resx` file. |
| 26 | + |
| 27 | + 4. Include the changes to the`.resx` file as well as the generated changes to |
| 28 | + the `Resources.Designer.cs` file and the `.xlf` files in the commit. |
| 29 | + |
| 30 | +## Guidelines |
| 31 | + |
| 32 | + * If a message code is used in multiple calls to `LogCodedError()` or |
| 33 | + `LogCodedWarning()` that each logs a different message, append short |
| 34 | + descriptive phrases to the end of the code to create additional resource |
| 35 | + names as needed. For example, you could have names like `XA0000_Files` and |
| 36 | + `XA0000_Directories` for two different strings. |
| 37 | + |
| 38 | + * To include values of variables in the message, use numbered format items |
| 39 | + like `{0}` and `{1}` rather than string interpolation or string |
| 40 | + concatenation. |
| 41 | + |
| 42 | + String interpolation won't work because string resources are not subject to |
| 43 | + interpolation. String concatenation should also be avoided because it means |
| 44 | + the message text will be split across multiple string resources, which makes |
| 45 | + it more complicated to provide appropriate context about the message for the |
| 46 | + translation team. |
| 47 | + |
| 48 | + * Use the comments field in the `.resx` file to provide additional context to |
| 49 | + the translation team about the message. For example, for a message that |
| 50 | + includes a format item like `{0}`, it can sometimes be helpful to add a |
| 51 | + comment about what will appear for that item in the final formatted string: |
| 52 | + |
| 53 | + ``` |
| 54 | + {0} - The managed type name |
| 55 | + ``` |
| 56 | +
|
| 57 | + For a few more examples, see the dotnet/sdk repo: |
| 58 | +
|
| 59 | + https://github.com/dotnet/sdk/blob/master/src/Tasks/Common/Resources/Strings.resx |
| 60 | +
|
| 61 | +[resources-editor]: ../images/resources-editor-xa0000.png |
| 62 | +[xliff-tasks]: https://github.com/dotnet/xliff-tasks |
| 63 | +[xliff]: http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html |
0 commit comments