Skip to content

Commit d664e90

Browse files
authored
[generator] Make warning and error messages localizable. (#689)
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.
1 parent 007b35b commit d664e90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3654
-134
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*.Designer.cs eol=crlf
2020

2121
*.cs text
22+
*.resx text
23+
*.xlf text
2224
*.xml text
2325
*.md text
2426
Makefile eol=lf

Directory.Build.props

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<_OutputPath>$(MSBuildThisFileDirectory)bin\Build$(Configuration)\</_OutputPath>
77
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<XlfLanguages>cs;de;es;fr;it;ja;ko;pl;pt-BR;ru;tr;zh-Hans;zh-Hant</XlfLanguages>
11+
<UpdateXlfOnBuild Condition="'$(RunningOnCI)' != 'true'">true</UpdateXlfOnBuild>
12+
</PropertyGroup>
13+
814
<Import
915
Project="$(MSBuildThisFileDirectory)Configuration.Override.props"
1016
Condition="Exists('$(MSBuildThisFileDirectory)Configuration.Override.props')"

Java.Interop.sln

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.SourceWriter", "src
9797
EndProject
9898
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.SourceWriter-Tests", "tests\Xamarin.SourceWriter-Tests\Xamarin.SourceWriter-Tests.csproj", "{6CF94627-BA74-4336-88CD-7EDA20C8F292}"
9999
EndProject
100+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Localization", "src\Java.Interop.Localization\Java.Interop.Localization.csproj", "{998D178B-F4C7-48B5-BDEE-44E2F869BB22}"
101+
EndProject
100102
Global
101103
GlobalSection(SharedMSBuildProjectFiles) = preSolution
102104
src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{58b564a1-570d-4da2-b02d-25bddb1a9f4f}*SharedItemsImports = 5
@@ -269,6 +271,10 @@ Global
269271
{6CF94627-BA74-4336-88CD-7EDA20C8F292}.Debug|Any CPU.Build.0 = Debug|Any CPU
270272
{6CF94627-BA74-4336-88CD-7EDA20C8F292}.Release|Any CPU.ActiveCfg = Release|Any CPU
271273
{6CF94627-BA74-4336-88CD-7EDA20C8F292}.Release|Any CPU.Build.0 = Release|Any CPU
274+
{998D178B-F4C7-48B5-BDEE-44E2F869BB22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
275+
{998D178B-F4C7-48B5-BDEE-44E2F869BB22}.Debug|Any CPU.Build.0 = Debug|Any CPU
276+
{998D178B-F4C7-48B5-BDEE-44E2F869BB22}.Release|Any CPU.ActiveCfg = Release|Any CPU
277+
{998D178B-F4C7-48B5-BDEE-44E2F869BB22}.Release|Any CPU.Build.0 = Release|Any CPU
272278
EndGlobalSection
273279
GlobalSection(SolutionProperties) = preSolution
274280
HideSolutionNode = FALSE
@@ -315,6 +321,7 @@ Global
315321
{F46EDFA5-C52A-4F0C-B5A2-5BB67E0D8C74} = {C8F58966-94BF-407F-914A-8654F8B8AE3B}
316322
{C5B732C8-7AF3-41D3-B903-AEDFC392E5BA} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
317323
{6CF94627-BA74-4336-88CD-7EDA20C8F292} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
324+
{998D178B-F4C7-48B5-BDEE-44E2F869BB22} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
318325
EndGlobalSection
319326
GlobalSection(ExtensibilityGlobals) = postSolution
320327
SolutionGuid = {29204E0C-382A-49A0-A814-AD7FBF9774A5}

NuGet.Config

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
- NUnit.Console
55
- csc.exe
66
-->
7-
<configuration>
7+
<configuration>
8+
<packageSources>
9+
<!-- For XliffTasks -->
10+
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" protocolVersion="3" />
11+
</packageSources>
812
<config>
913
<add key="globalPackagesFolder" value="packages" />
1014
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="XliffTasks" Version="1.0.0-beta.20206.1" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<Compile Update="Resources.Designer.cs">
13+
<DesignTime>True</DesignTime>
14+
<AutoGen>True</AutoGen>
15+
<DependentUpon>Resources.resx</DependentUpon>
16+
</Compile>
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<EmbeddedResource Update="Resources.resx">
21+
<Generator>PublicResXFileCodeGenerator</Generator>
22+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
23+
</EmbeddedResource>
24+
</ItemGroup>
25+
26+
</Project>

0 commit comments

Comments
 (0)