Skip to content

fix(sdk): normalize Android and underscore locales to BCP 47 before API calls#2103

Merged
AndreyHirsa merged 1 commit into
mainfrom
fix/sdk-normalize-android-locales
Jun 5, 2026
Merged

fix(sdk): normalize Android and underscore locales to BCP 47 before API calls#2103
AndreyHirsa merged 1 commit into
mainfrom
fix/sdk-normalize-android-locales

Conversation

@AndreyHirsa
Copy link
Copy Markdown
Contributor

@AndreyHirsa AndreyHirsa commented Jun 5, 2026

Summary

Normalize Android-format (pt-rPT) and underscore (pt_PT) locale codes to canonical BCP 47 before sending them to the API, so locales that pass config validation are no longer rejected with a 400.

Changes

  • Add a normalizedLocaleCodeSchema (localeCodeSchema.transform(normalizeLocale)) in the SDK and apply it to sourceLocale, targetLocale, and reference keys, so every locale that crosses the wire is canonical BCP 47.
  • Send the normalized finalParams.reference (instead of the raw params.reference) in _localizeRaw, so reference keys are canonicalized along with the locales they pair with.
  • File paths are untouched: the CLI still uses the original code for resource directories (e.g. values-pt-rPT/).

Testing

Business logic tests added:

  • Android -r locale (pt-rPT) is normalized to pt-PT in the request body
  • Underscore locales (en_US, pt_PT) are normalized to en-US / pt-PT in the request body
  • Locale codes used as reference keys are normalized (pt-rPTpt-PT)
  • Already-canonical locales (pt-PT) pass through unchanged
  • All tests pass locally

Visuals

N/A

Checklist

  • Changeset added (if version bump needed) — @lingo.dev/_sdk patch; the CLI (lingo.dev) is auto-bumped as a dependent
  • Tests cover business logic (not just happy path) — Android, underscore, reference-key, and canonical-passthrough cases
  • No breaking changes (or documented below)

Closes N/A

Summary by CodeRabbit

  • Bug Fixes
    • Fixed locale handling in localization requests. Android-format (pt-rPT) and underscore-delimited locales (pt_PT) are now automatically normalized to canonical BCP 47 format (pt-PT) before being sent to the API, preventing rejection errors.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f64aaf62-bd14-4179-aa65-423a8692f8a2

📥 Commits

Reviewing files that changed from the base of the PR and between fd11342 and 49faf2e.

📒 Files selected for processing (3)
  • .changeset/blue-crews-shake.md
  • packages/sdk/src/index.spec.ts
  • packages/sdk/src/index.ts

📝 Walkthrough

Walkthrough

The PR normalizes non-canonical locale codes (Android-format pt-rPT, underscore-delimited pt_PT) to canonical BCP 47 form before sending to the API. Schema transforms apply normalization to sourceLocale, targetLocale, and reference keys. Implementation uses the normalized reference in chunk processing, with comprehensive tests and a changeset documenting the fix.

Changes

Locale Normalization

Layer / File(s) Summary
Locale normalization schema and imports
packages/sdk/src/index.ts
Import reformatting includes locale schema helpers. normalizedLocaleCodeSchema applies normalizeLocale transform to validated codes. referenceSchema and localizationParamsSchema updated to use normalized schema for sourceLocale, targetLocale, and reference object keys.
Apply normalized reference in chunk processing
packages/sdk/src/index.ts
In _localizeRaw loop, per-chunk request now passes finalParams.reference (parsed and normalized) instead of original params.reference.
Locale normalization test suite
packages/sdk/src/index.spec.ts
Vitest suite verifies Android-style (pt-rPTpt-PT), underscore-delimited (en_USen-US), and reference key normalization in JSON request body via global.fetch. Already-canonical forms remain unchanged.
Changeset documentation
.changeset/blue-crews-shake.md
Documents that sourceLocale, targetLocale, and reference are normalized to canonical BCP 47 on the wire to prevent API 400 errors; Android resource directory paths unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • vrcprl

Poem

🐰 Locales hopping far and wide,
Android formats normalized with pride,
Underscores turned to dashes clean,
BCP 47, now canonical seen!
No more 400s, the API's content!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately describes the main change: normalizing Android-format and underscore locales to BCP 47 before API calls to prevent 400 rejections.
Description check ✅ Passed The pull request description comprehensively covers all required template sections with clear explanations, specific test cases, and proper checklist completion.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sdk-normalize-android-locales

Comment @coderabbitai help to get the list of available commands and usage tips.

@AndreyHirsa AndreyHirsa merged commit 7893f5b into main Jun 5, 2026
10 checks passed
@AndreyHirsa AndreyHirsa deleted the fix/sdk-normalize-android-locales branch June 5, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants