Skip to content

Commit 328644a

Browse files
authored
[OneLoc] Localize Microsoft.Android.Templates (#7248)
Context: https://github.com/dotnet/templating/blob/6ecea73aad1ce3444dbf28fc340e5f464f6278df/docs/Localization.md The `dotnet new` template engine supports localization as of .NET 6. Update the `Microsoft.Android.Templates` project to use the new localization system. Local template builds now use `Microsoft.TemplateEngine.Tasks` to generate the `templatestrings.*.json` files used for localization. The new `update-locproject.ps1` script runs as part of the `OneLocBuild` job in CI (fa9629d). This script will copy each english `templatestrings.en.json` file to `templatestrings.json`, and add it as a new translation source file entry to `LocProject.json`. This update to `LocProject.json` will tell the `OneLocBuild` task to process our templates. This script borrows heavily from the [generate-locproject.ps1][0] script found in dotnet/arcade. Every time there is a change to one of the templates: 1. The dev making the change should build the modified template project. This will update the loc files on the local working copy, dotnet build src/Microsoft.Android.Templates/Microsoft.Android.Templates.csproj # -or- dotnet build Xamarin.Android.sln 2. Push the loc files together with the template modifications. Review & merge. 3. OneLocBuild integration will automatically pick up the changes and will send them for translation. 4. You will receive a PR containing the translated template loc files when they are ready. Review & merge. [0]: https://github.com/dotnet/arcade/blob/e771d68edea1cfcd4a49e160093a4f32df8a6288/eng/common/generate-locproject.ps1
1 parent 8ce34b0 commit 328644a

File tree

92 files changed

+573
-2
lines changed

Some content is hidden

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

92 files changed

+573
-2
lines changed

Documentation/workflow/Localization.md

Lines changed: 7 additions & 0 deletions

Localize/LocProject.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"CopyOption": "LangIDOnName",
1313
"SourceFile": ".\\src\\Xamarin.Android.Build.Tasks\\Properties\\Resources.resx",
1414
"OutputPath": ".\\src\\Xamarin.Android.Build.Tasks\\Properties\\"
15-
},
15+
}
1616
]
1717
}
1818
]

Localize/update-locproject.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
param ($SourcesDirectory, $LocProjectPath)
2+
3+
$jsonFiles = @()
4+
$jsonTemplateFiles = Get-ChildItem -Recurse -Path "$SourcesDirectory" | Where-Object { $_.FullName -Match "\.template\.config\\localize\\.+\.en\.json" } # .NET templating pattern
5+
$jsonTemplateFiles | ForEach-Object {
6+
$null = $_.Name -Match "(.+)\.[\w-]+\.json" # matches '[filename].[langcode].json
7+
8+
$destinationFile = "$($_.Directory.FullName)\$($Matches.1).json"
9+
$jsonFiles += Copy-Item "$($_.FullName)" -Destination $destinationFile -PassThru
10+
Write-Host "Template loc file generated: $destinationFile"
11+
}
12+
13+
Push-Location "$SourcesDirectory"
14+
$projectObject = Get-Content $LocProjectPath | ConvertFrom-Json
15+
$jsonFiles | ForEach-Object {
16+
$sourceFile = ($_.FullName | Resolve-Path -Relative)
17+
$outputPath = "$(($_.DirectoryName | Resolve-Path -Relative) + "\")"
18+
$projectObject.Projects[0].LocItems += (@{
19+
SourceFile = $sourceFile
20+
CopyOption = "LangIDOnName"
21+
OutputPath = $outputPath
22+
})
23+
}
24+
Pop-Location
25+
26+
$locProjectJson = ConvertTo-Json $projectObject -Depth 5
27+
Set-Content $LocProjectPath $locProjectJson
28+
Write-Host "LocProject.json was updated to contain template localizations:`n`n$locProjectJson`n`n"

build-tools/automation/azure-pipelines.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ stages:
18801880
# Check - "Xamarin.Android (Tenets OneLocBuild)"
18811881
- job: OneLocBuild
18821882
displayName: OneLocBuild
1883-
condition: eq(variables['MicroBuildSignType'], 'Real')
1883+
condition: and(eq(variables['MicroBuildSignType'], 'Real'), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
18841884
pool: VSEngSS-MicroBuild2022-1ES
18851885
timeoutInMinutes: 30
18861886
variables:
@@ -1891,6 +1891,13 @@ stages:
18911891
- checkout: self
18921892
clean: true
18931893

1894+
- task: PowerShell@2
1895+
displayName: Update LocProject.json
1896+
inputs:
1897+
targetType: filePath
1898+
filePath: $(Build.SourcesDirectory)\Localize\update-locproject.ps1
1899+
arguments: -SourcesDirectory "$(Build.SourcesDirectory)" -LocProjectPath "$(Build.SourcesDirectory)\Localize\LocProject.json"
1900+
18941901
- task: OneLocBuild@2
18951902
displayName: OneLocBuild
18961903
env:

eng/Version.Details.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@
2626
<Uri>https://github.com/dotnet/arcade</Uri>
2727
<Sha>70831f0d126fe88b81d7dc8de11358e17a5ce364</Sha>
2828
</Dependency>
29+
<Dependency Name="Microsoft.TemplateEngine.Tasks" Version="7.0.100-rc.1.22410.7">
30+
<Uri>https://github.com/dotnet/templating</Uri>
31+
<Sha>66ccf71bc4f0ba64f66b1674803e9999cd8111c8</Sha>
32+
</Dependency>
2933
</ToolsetDependencies>
3034
</Dependencies>

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<MicrosoftDotNetBuildTasksFeedPackageVersion>7.0.0-beta.22103.1</MicrosoftDotNetBuildTasksFeedPackageVersion>
99
<MicrosoftNETWorkloadEmscriptenManifest70100Version>7.0.0-rc.1.22368.1</MicrosoftNETWorkloadEmscriptenManifest70100Version>
1010
<MicrosoftNETWorkloadEmscriptenPackageVersion>$(MicrosoftNETWorkloadEmscriptenManifest70100Version)</MicrosoftNETWorkloadEmscriptenPackageVersion>
11+
<MicrosoftTemplateEngineTasksPackageVersion>7.0.100-rc.1.22410.7</MicrosoftTemplateEngineTasksPackageVersion>
1112
</PropertyGroup>
1213
<PropertyGroup>
1314
<!-- Match the first three version numbers and append 00 -->
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
templatestrings.json

src/Microsoft.Android.Templates/Microsoft.Android.Templates.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Description>Templates for Android platforms.</Description>
99
<IncludeContentInPack>true</IncludeContentInPack>
1010
<IncludeBuildOutput>false</IncludeBuildOutput>
11+
<LocalizeTemplates Condition=" '$(RunningOnCI)' != 'true' ">true</LocalizeTemplates>
1112
<ContentTargetFolders>content</ContentTargetFolders>
1213
<OutputPath>..\..\bin\Build$(Configuration)\nuget-unsigned\</OutputPath>
1314
<!-- Remove the `<group targetFramework=".NETStandard2.0" />` entry from the .nuspec. -->
@@ -22,4 +23,8 @@
2223
<Compile Remove="**\*" />
2324
</ItemGroup>
2425

26+
<ItemGroup Condition=" '$(RunningOnCI)' != 'true' ">
27+
<PackageReference Include="Microsoft.TemplateEngine.Tasks" Version="$(MicrosoftTemplateEngineTasksPackageVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
28+
</ItemGroup>
29+
2530
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"author": "Microsoft",
3+
"name": "Android Activity template",
4+
"description": "An Android Activity class",
5+
"symbols/namespace/description": "namespace for the generated code"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"author": "Microsoft",
3+
"name": "Android Activity template",
4+
"description": "An Android Activity class",
5+
"symbols/namespace/description": "namespace for the generated code"
6+
}

0 commit comments

Comments
 (0)