Skip to content

Commit

Permalink
[l10n] Use Arcade to generate resource properties (#5270)
Browse files Browse the repository at this point in the history
Context: 0342fe5

Now that `Xamarin.Android.Build.Tasks.csproj` is a short-form project
(03743f3), add a dependency on the [`Microsoft.DotNet.Arcade.Sdk`][0]
NuGet package, and switch to using the
[`$(GenerateResxSource)` mechanism][1] instead of using
`%(EmbeddedResource.Generator)`=`ResXFileCodeGenerator`, which only
updates `Resources.Designer.cs` when using the Visual Studio IDEs.

For this initial use of `Microsoft.DotNet.Arcade.Sdk`, import only
`..\tools\BuildTasks.props` and `..\tools\GenerateResxSource.targets`.
Avoid importing the full `Sdk.props` and `Sdk.targets` for now because
those files have other consequences that aren't desired at this time.
For example, `Sdk.props` indirectly imports `ProjectDefaults.props`,
which sets `$(DebugType)`=`embedded` by default, and
`[assembly:AssemblyVersion("42.42.42.42")]` is added.

An advantage of `$(GenerateResxSource)`=True compared to
`ResXFileCodeGenerator` is that contributors no longer need to worry
about updating `Resources.Designer.cs` when updating `Resources.resx`.
This is especially helpful for contributors who use an editor other
than Visual Studio (macOS & Windows), because it means they no longer
need to hand-edit the `Resource.Designer.cs` file to match the format
that `ResXFileCodeGenerator` generates on Windows.

The generated file
`obj/$(Configuration)/Xamarin.Android.Tasks.Properties.Resources.cs`
has essentially the same setup as the previous `Resources.Designer.cs`.
The properties are still `internal` and still include `<summary/>`
comments to surface the non-localized messages in IntelliSense, and the
file is still updated by a design-time build any time the `.resx`
file changes.

One difference is that the new generated `.cs` file is not shown in the
Solution Explorer because it's located in `obj/`.  If any contributors
were previously using `Resources.Designer.cs` as a starting place to do
"find all references" on the property names, they would now need to open
the generated file from the `obj/` directory instead.

[0]: https://github.com/dotnet/arcade/tree/0940dc72b8d9886c1605c38f7190b984463903c6/src/Microsoft.DotNet.Arcade.Sdk
[1]: https://github.com/dotnet/arcade/blob/c6f24c0d1264f6f80ceb39d2b0477d054c3f8ffc/Documentation/ArcadeSdk.md#generateresxsource-bool
  • Loading branch information
brendanzagaeski authored Nov 11, 2020
1 parent 55e5c34 commit 77d4af8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1,391 deletions.
18 changes: 10 additions & 8 deletions Documentation/workflow/Localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ so when adding a new message, follow these steps:
![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. If using Visual Studio or Visual Studio for Mac, skip to the next step.

2. Use the generated property from `Resources.Designer.cs` in the
`LogCodedError()` and `LogCodedWarning()` calls:
If using an editor that does not automatically run design-time builds for
MSBuild targets specified via `%(Generator)` MSBuild item metadata,
explicitly build the project to update the generated properties.

3. Use the generated C# property for the resource in the `LogCodedError()` and
`LogCodedWarning()` calls:

```csharp
Log.LogCodedError ("XA0000", Properties.Resources.XA0000);
Expand All @@ -30,13 +32,13 @@ so when adding a new message, follow these steps:
<AndroidError Code="XA0000" ResourceName="XA0000" />
```

3. After adding the new message, build `Xamarin.Android.Build.Tasks.csproj`
4. 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.
5. Include the changes to the`.resx` file as well as the generated changes to
the `.xlf` files in the commit.

## Guidelines

Expand Down
1 change: 1 addition & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"msbuild-sdks": {
"Microsoft.Build.NoTargets": "2.0.1",
"Microsoft.DotNet.Arcade.Sdk": "6.0.0-beta.20555.6",
"Microsoft.DotNet.Build.Tasks.SharedFramework.Sdk": "5.0.0-beta.20120.1"
}
}
Loading

0 comments on commit 77d4af8

Please sign in to comment.