Skip to content

Commit

Permalink
[generator] Make warning and error messages localizable. (#689)
Browse files Browse the repository at this point in the history
Context: dotnet/android@0342fe5

Adds infrastructure to make the `Java.Interop` repository localizaable,
and rebases `generator` to work on this infrastructure.

Future PR's will make additional assemblies work on this infrastructure.

~~ Approach ~~

Create a single `Java.Interop.Localization.dll` assembly that will be
referenced by all localizable assemblies.  This approach allows us to
have a single set of `.xlf` files to worry about providing to
translators, instead of a separate set for `generator`, `class-parse`,
`ApiXmlAdjuster`, etc.

The downside to this approach is that if you only wanted to ship
`generator.exe` you would be shipping the messages for the entire repo.
Given that our use case is to ship all tools together, and that we
won't have a ton of messages, this seems like an acceptable tradeoff.
(`generator` contains the most messages, and with this commit
`Java.Interop.Localization.dll` is ~9KB.)

Currently we only plan to localize the tools used on desktop to build
bindings.  If we localize assemblies that run on device in the future,
we would most likely make a separate "run-time" set, as we wouldn't
want to ship e.g. `generator` messages on a device.

~~ Usage ~~

To create a new translatable string (all assemblies):

  * Open `Java.Interop.Localization.Resources.resx` in an IDE.
  * Enter the string lookup key, string value, and any notes for
    translators.
  * The string can now be retrieved via
    `Java.Interop.Localization.Resources.MyStringKey`.

~~ Generator Usage ~~

To use the string in `generator.exe`:

  * Create a new static member in `Utilities/Report.cs` that assigns
    a build code to the string.

        public static LocalizedMessage WarningUnknownReturnType => new LocalizedMessage (8700, Java.Interop.Localization.Resources.Generator_BG8700);

  * Use `Report.LogCodedWarning()` or `Report.LogCodedError()` to
    create an `MSBuild` formatted build warning/error.

        Report.LogCodedError (Report.ErrorFailedToProcessEnumMap);
    
    Overloads are available that take exceptions, file/line/col info,
    and `string.Format()` parameters.
  • Loading branch information
jpobst authored Aug 20, 2020
1 parent 007b35b commit d664e90
Show file tree
Hide file tree
Showing 41 changed files with 3,654 additions and 134 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*.Designer.cs eol=crlf

*.cs text
*.resx text
*.xlf text
*.xml text
*.md text
Makefile eol=lf
Expand Down
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<_OutputPath>$(MSBuildThisFileDirectory)bin\Build$(Configuration)\</_OutputPath>
</PropertyGroup>

<PropertyGroup>
<XlfLanguages>cs;de;es;fr;it;ja;ko;pl;pt-BR;ru;tr;zh-Hans;zh-Hant</XlfLanguages>
<UpdateXlfOnBuild Condition="'$(RunningOnCI)' != 'true'">true</UpdateXlfOnBuild>
</PropertyGroup>

<Import
Project="$(MSBuildThisFileDirectory)Configuration.Override.props"
Condition="Exists('$(MSBuildThisFileDirectory)Configuration.Override.props')"
Expand Down
7 changes: 7 additions & 0 deletions Java.Interop.sln
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.SourceWriter", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.SourceWriter-Tests", "tests\Xamarin.SourceWriter-Tests\Xamarin.SourceWriter-Tests.csproj", "{6CF94627-BA74-4336-88CD-7EDA20C8F292}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Localization", "src\Java.Interop.Localization\Java.Interop.Localization.csproj", "{998D178B-F4C7-48B5-BDEE-44E2F869BB22}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{58b564a1-570d-4da2-b02d-25bddb1a9f4f}*SharedItemsImports = 5
Expand Down Expand Up @@ -269,6 +271,10 @@ Global
{6CF94627-BA74-4336-88CD-7EDA20C8F292}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CF94627-BA74-4336-88CD-7EDA20C8F292}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CF94627-BA74-4336-88CD-7EDA20C8F292}.Release|Any CPU.Build.0 = Release|Any CPU
{998D178B-F4C7-48B5-BDEE-44E2F869BB22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{998D178B-F4C7-48B5-BDEE-44E2F869BB22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{998D178B-F4C7-48B5-BDEE-44E2F869BB22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{998D178B-F4C7-48B5-BDEE-44E2F869BB22}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -315,6 +321,7 @@ Global
{F46EDFA5-C52A-4F0C-B5A2-5BB67E0D8C74} = {C8F58966-94BF-407F-914A-8654F8B8AE3B}
{C5B732C8-7AF3-41D3-B903-AEDFC392E5BA} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
{6CF94627-BA74-4336-88CD-7EDA20C8F292} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
{998D178B-F4C7-48B5-BDEE-44E2F869BB22} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {29204E0C-382A-49A0-A814-AD7FBF9774A5}
Expand Down
6 changes: 5 additions & 1 deletion NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
- NUnit.Console
- csc.exe
-->
<configuration>
<configuration>
<packageSources>
<!-- For XliffTasks -->
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" protocolVersion="3" />
</packageSources>
<config>
<add key="globalPackagesFolder" value="packages" />
</config>
Expand Down
26 changes: 26 additions & 0 deletions src/Java.Interop.Localization/Java.Interop.Localization.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="XliffTasks" Version="1.0.0-beta.20206.1" />
</ItemGroup>

<ItemGroup>
<Compile Update="Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
Loading

0 comments on commit d664e90

Please sign in to comment.