Skip to content

Add OneLoc localization foundation - #206

Merged
Mike Krüger (mkrueger) merged 11 commits into
mainfrom
dev/mkrueger/localization-oneloc-foundation
Sep 8, 2026
Merged

Mike Krüger (mkrueger) merged 11 commits into
mainfrom
dev/mkrueger/localization-oneloc-foundation

Conversation

@mkrueger

@mkrueger Mike Krüger (mkrueger) commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Establish the repository-side localization foundation for OneLoc while keeping Fluent as the source and runtime resource format.

  • Add a Fluent-to-JSON converter and canonical English catalog, preserving Fluent expressions through validated placeholders.
  • Generate localized Fluent resources from translated JSON catalogs before compilation and embed the generated locales.
  • Load exact and parent UI cultures before falling back to English.
  • Add regression coverage for catalog conversion, placeholders, culture fallback, and unchanged-file preservation.

Catalog Synchronization

  • Local shell builds automatically update l10n/CosmosDBShell.json from CosmosDBShell/lang/en.ftl, without rewriting unchanged catalogs.
  • CI builds verify the committed catalog instead of repairing it and fail when it is missing or stale.
  • Add an independent Localization Catalog GitHub Actions check alongside the existing catalog verification in build-test-package.
  • Document the developer workflow and required-check enforcement in CONTRIBUTING.md.
  • Keep the converter as a build-only dependency, separate from the shipped shell payload.

OneLoc Onboarding

The OneLocBuild@3 task remains in the official pipeline as a commented-out block pending OneLoc onboarding. Its dependency feed, authentication, and localization bot/repository permissions must be confirmed before enabling it. Repository-side catalog validation and localized-resource generation remain active.

Relates to #118

Add Fluent-to-OneLoc catalog conversion, culture fallback, localized resource generation, pipeline validation, and regression tests.

Relates to #118.
@github-code-quality

github-code-quality Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall line coverage in commit fbd7cf8 in the dev/mkrueger/localiz... branch is 62%. The line coverage in commit f0ece29 in the main branch is 61%.

Show a line coverage summary of the most impacted files.
File main f0ece29 dev/mkrueger/localiz... fbd7cf8 +/-
D:\a\CosmosDBSh...tion\Program.cs 0% 0% 0%
D:\a\CosmosDBSh...ssageService.cs 70% 76% +6%
D:\a\CosmosDBSh...logConverter.cs 0% 85% +85%

Updated September 08, 2026 09:25 UTC

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The build script currently skips multi-hyphen locale catalogs (e.g., zh-Hans-CN), and the converter unnecessarily rejects duplicate placeholders, both of which can break localization generation/import in valid scenarios.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR establishes the repository-controlled foundation for OneLoc localization by introducing a Fluent ↔ OneLoc JSON converter, a canonical localization catalog, build-time generation of localized Fluent resources, and runtime culture fallback loading in the shell.

Changes:

  • Added a tools/Localization converter tool plus a build script to validate/sync the canonical catalog and generate CosmosDBShell/lang/<locale>.ftl files.
  • Updated the shell to embed all lang/*.ftl resources and to load exact + parent culture resources before falling back to English.
  • Added regression tests for catalog conversion, numeric select handling, embedded resources, and culture fallback behavior; updated CI pipelines to validate/generate localized resources.
File summaries
File Description
tools/Localization/Program.cs Adds a small CLI entrypoint for export/import/verify operations.
tools/Localization/FluentCatalogConverter.cs Implements Fluent AST ↔ JSON catalog conversion, verification, and serialization.
tools/Localization/CosmosDBShell.Localization.csproj Introduces the converter tool project and its Fluent.Net dependency.
tools/Localization/build-localized-resources.ps1 Validates canonical catalog sync and generates localized .ftl files from OneLoc JSON.
l10n/LocProject.json Adds OneLoc project metadata pointing at the canonical JSON catalog.
l10n/CosmosDBShell.json Adds the canonical localization catalog exported from en.ftl.
CosmosDBShell/CosmosDBShell.csproj Embeds all .ftl resources (not only English) into the app.
CosmosDBShell/Azure.Data.Cosmos.Shell.Util/MessageService.cs Implements culture fallback enumeration and resource lookup for embedded lang.<culture>.ftl.
CosmosDBShell.Tests/MessageServiceCultureTests.cs Adds tests for culture fallback ordering and English embedded fallback presence.
CosmosDBShell.Tests/Localization/FluentCatalogConverterTests.cs Adds converter regression tests including selects, numeric variants, and round-tripping en.ftl.
CosmosDBShell.Tests/CosmosDBShell.Tests.csproj References the new localization tool project for test access.
.pipelines/CosmosDB-Shell-Official.yml Adds localized-resource generation + preserves localization diagnostics in artifacts.
.github/workflows/validate-and-package.yml Adds localized-resource generation step to GitHub Actions validation.
.gitignore Ignores build-generated localized lang/*.ftl files while keeping en.ftl.
Review details
  • Files reviewed: 12/14 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tools/Localization/Program.cs Resolved
Use a static Regex instance so Guardian's Roslyn analysis build, which overrides compiler feature flags, does not suppress the generated partial implementation.
Copilot AI review requested due to automatic review settings September 2, 2026 08:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The build-localized-resources PowerShell script is not cross-platform due to embedded backslashes in Join-Path inputs, and the converter currently rejects duplicate placeholders that can be valid in real translations.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

tools/Localization/FluentCatalogConverter.cs:252

  • ImportPattern rejects duplicate placeholders in translations, but some locales legitimately need to repeat the same variable/value more than once (e.g., using {0} twice). Throwing here will break valid translations even though the AST can safely reuse the same placeholder node.
            if (!seen.Add(index))
            {
                throw new InvalidDataException($"Translation '{path}' contains duplicate placeholder '{{{index}}}'.");
            }

tools/Localization/build-localized-resources.ps1:27

  • The output path uses a Windows-style backslash in an interpolated string ("CosmosDBShell\lang$locale.ftl"), which will not resolve correctly on non-Windows agents. Build it via Join-Path segments so generated locale files land in the expected folder cross-platform.
    $output = Join-Path $repoRoot "CosmosDBShell\lang\$locale.ftl"
  • Files reviewed: 12/14 changed files
  • Comments generated: 1
  • Review effort level: Lite
Dispose test readers, allow repeated placeholders, support multi-part locale names, and clarify localization tool usage.
Copilot AI review requested due to automatic review settings September 2, 2026 08:59
Use platform-neutral paths so localized resource generation works under PowerShell on Windows, Linux, and macOS runners.
Comment thread tools/Localization/Program.cs Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The current English-culture short-circuit in culture fallback conflicts with the stated “exact culture then parent” behavior (e.g., en-US would never be attempted even if present).

Review details

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

CosmosDBShell/Azure.Data.Cosmos.Shell.Util/MessageService.cs:59

  • GetCultureFallbacks returns an empty list for any English UI culture (e.g. en-US), so the runtime will never attempt to load an exact English culture resource even if one is embedded. This seems inconsistent with the PR description of loading the exact culture + parent chain before falling back to English; an en-US-specific resource would be ignored.
    CosmosDBShell.Tests/MessageServiceCultureTests.cs:25
  • The GetCultureFallbacks test currently asserts that en-US produces no fallbacks, which matches the current implementation but conflicts with the stated goal of trying the exact culture before falling back to English. If GetCultureFallbacks is updated to include en-US, this test should be adjusted accordingly.
  • Files reviewed: 12/14 changed files
  • Comments generated: 0 new
  • Review effort level: Lite
Try an exact English culture such as en-US before using the neutral English fallback, and update culture fallback coverage.
Copilot AI review requested due to automatic review settings September 2, 2026 09:18
@mkrueger

Copy link
Copy Markdown
Collaborator Author

Addressed the two suppressed Copilot findings in 8da7dd4: regional English resources such as en-US are now attempted before neutral English, and the culture fallback test now verifies that behavior.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The catalog reader deserializes into a culture-sensitive SortedDictionary, which can make key ordering/comparisons vary by culture and should be changed to StringComparer.Ordinal for canonical stability.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

tools/Localization/FluentCatalogConverter.cs:107

  • ReadCatalog deserializes directly into SortedDictionary<string,string>, which uses the default string comparer (culture-sensitive ordering via string.CompareTo). That can make key ordering/comparisons vary by CurrentCulture and can even treat distinct keys as equal in edge cases. Since the catalog is intended to be canonical and stable, prefer deserializing into a Dictionary and then constructing a SortedDictionary with StringComparer.Ordinal.
  • Files reviewed: 12/14 changed files
  • Comments generated: 0 new
  • Review effort level: Lite
Preserve ordinal catalog ordering, narrow expected CLI exception handling, and use non-resetting path joins in tests.
Copilot AI review requested due to automatic review settings September 2, 2026 09:31
@mkrueger

Copy link
Copy Markdown
Collaborator Author

Addressed the suppressed canonical-ordering finding in ab243c9: JSON is deserialized into a dictionary and copied into a SortedDictionary with StringComparer.Ordinal.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The converter’s placeholder parsing can throw an uncaught OverflowException on malformed catalogs, causing the localization tool to crash instead of reporting a clean validation error.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 12/14 changed files
  • Comments generated: 1
  • Review effort level: Lite
Report malformed oversized catalog placeholders as InvalidDataException instead of allowing integer parsing overflow, with regression coverage.
Copilot AI review requested due to automatic review settings September 2, 2026 09:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The official pipeline’s new “Stage localization diagnostics” step appears to be a no-op as placed (no producer of loc/** is defined before it), so the intended diagnostics preservation likely won’t work as-is.

Review details

Suppressed comments (4)

Previously missed (3) — in code that hasn't changed since the last review.

.pipelines/CosmosDB-Shell-Official.yml:99

  • This "Stage localization diagnostics" step currently copies loc/** from $(Build.ArtifactStagingDirectory), but this YAML doesn’t define any prior task that creates a loc folder under the artifact staging directory. As written (and placed at the very start of the job), it will consistently stage nothing, so localization diagnostics won’t actually make it into the published out artifact.
    tools/Localization/build-localized-resources.ps1:12
  • dotnet run defaults to Debug configuration; in CI this can cause an extra Debug build of the localization tool before the main solution is built in Release (and it can also diverge from CI build settings). Passing an explicit configuration avoids the redundant build work.

This issue also appears on line 28 of the same file.
tools/Localization/CosmosDBShell.Localization.csproj:9

  • This project is executed via dotnet run in CI (see tools/Localization/build-localized-resources.ps1). Setting SelfContained=true with UseCurrentRuntimeIdentifier=true forces RID-specific builds and can download runtime packs unnecessarily, increasing build time and output size for a tool that doesn’t need to be self-contained when run from the SDK.

tools/Localization/build-localized-resources.ps1:28

  • This dotnet run invocation also defaults to Debug, which can trigger redundant builds in CI and slow down localization generation for each locale. Use an explicit configuration to align with CI builds and reduce extra work.
    dotnet run --project $project --no-restore -- import $source $_.FullName $output
  • Files reviewed: 12/14 changed files
  • Comments generated: 0 new
  • Review effort level: Lite
Remove premature diagnostics staging, run localization conversion in Release, and build the converter as an executable only when invoked so test references remain lightweight.
Copilot AI review requested due to automatic review settings September 2, 2026 09:57
@mkrueger

Copy link
Copy Markdown
Collaborator Author

Addressed all four suppressed sixth-pass findings in c5a99f8: removed the no-op diagnostics copy and stale loc artifact whitelist; both converter invocations now use Release; and the converter is a library for test references, opting into executable output only for dotnet run, avoiding self-contained RID/runtime-pack overhead.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It introduces new build-time generation and pipeline enforcement for localization plus a large canonical catalog, which warrants final human verification of CI/publishing behavior.

Review details
  • Files reviewed: 12/14 changed files
  • Comments generated: 0 new
  • Review effort level: Lite
Copilot AI review requested due to automatic review settings September 2, 2026 17:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It introduces a new localization toolchain plus CI/pipeline integration and a large canonical catalog, which warrants final human verification of end-to-end build/pipeline behavior.

Review details
  • Files reviewed: 12/14 changed files
  • Comments generated: 0 new
  • Review effort level: Lite
Copilot AI review requested due to automatic review settings September 3, 2026 08:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The official pipeline YAML enables OneLocBuild@3 even though the PR description states that task is still deferred, so the implementation and stated intent need to be reconciled.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 12/14 changed files
  • Comments generated: 1
  • Review effort level: Lite
Comment thread .pipelines/CosmosDB-Shell-Official.yml Resolved
Copilot AI review requested due to automatic review settings September 8, 2026 09:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It introduces cross-cutting changes to localization tooling, build orchestration, embedded resources, and CI pipelines that warrant a final human validation pass (especially around end-to-end build/package behavior).

Review details
  • Files reviewed: 13/15 changed files
  • Comments generated: 0 new
  • Review effort level: Lite
@mkrueger
Mike Krüger (mkrueger) merged commit edf54d7 into main Sep 8, 2026
17 checks passed
@mkrueger
Mike Krüger (mkrueger) deleted the dev/mkrueger/localization-oneloc-foundation branch September 8, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants