-
Notifications
You must be signed in to change notification settings - Fork 665
feat(locales): add comprehensive ISO 639-2/3 language code validation #1614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Replaces hardcoded ISO 639-1 (2-letter) language code list with the comprehensive iso-639-3 package, which validates against all ISO 639 standards including: - ISO 639-1 codes (2-letter, ~184 languages) - ISO 639-2 codes (3-letter bibliographic and terminologic) - ISO 639-3 codes (3-letter, ~8,000 languages) This fixes validation issues with 3-letter language codes that don't have 2-letter equivalents, such as: - fil (Filipino) - bar (Bavarian) - nap (Neapolitan) - zgh (Standard Moroccan Tamazight) Changes: - Add iso-639-3 package dependency to @lingo.dev/_locales - Update validation.ts to use iso-639-3 for comprehensive validation - Remove hardcoded list of 184 language codes (now 8,000+ supported) - Add 5 new tests covering 3-letter language code validation - All 88 tests passing Fixes validation error: "Unsupported locale: fil"
The iso-639-3 package is ESM-only, which caused build failures when the spec package tried to import the locales CJS bundle. Solution: Configure tsup to bundle iso-639-3 into the output using noExternal option. This allows the CJS build to work properly. Fixes CI build error: ERR_REQUIRE_ESM
The test had duplicate entries for 'openai' and 'anthropic' which caused the test to fail. Removed the duplicates to match the actual provider list. This was an existing bug unrelated to the locale validation changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances locale validation by replacing a hardcoded list of ~184 ISO 639-1 (2-letter) language codes with the comprehensive iso-639-3 package, enabling validation of approximately 8,000 languages including ISO 639-1, 639-2, and 639-3 standards. This fixes validation errors for 3-letter language codes like fil (Filipino), bar (Bavarian), nap (Neapolitan), and zgh (Standard Moroccan Tamazight).
Key Changes:
- Integrated
iso-639-3package for comprehensive language code validation covering all ISO 639 standards - Added 5 new test cases specifically for 3-letter language code validation
- Configured tsup to bundle the ESM-only iso-639-3 dependency for CJS compatibility
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/locales/src/validation.ts | Replaced hardcoded ISO 639-1 language codes with dynamic set built from iso-639-3 package data |
| packages/locales/src/validation.spec.ts | Added comprehensive test coverage for 3-letter ISO 639-2/3 language codes |
| packages/locales/package.json | Added iso-639-3@^3.0.1 as a production dependency |
| packages/locales/tsup.config.ts | Configured bundling of iso-639-3 to resolve ESM/CJS compatibility |
| pnpm-lock.yaml | Updated lockfile with [email protected] package resolution |
| .changeset/add-iso-639-3-validation.md | Added changeset documenting the minor version feature addition |
| packages/compiler/src/lib/lcp/api/provider-details.spec.ts | Removed "openai" and "anthropic" from expected providers list (unrelated to locale changes) |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "openrouter", | ||
| "ollama", | ||
| "mistral", |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change appears to be unrelated to the locale validation feature. The removal of "openai" and "anthropic" from the expected provider list should be in a separate PR or explained in the PR description if it's intentional.
Co-authored-by: Copilot <[email protected]>
Summary
Fixes the validation error
"Unsupported locale: fil"by replacing the hardcoded ISO 639-1 (2-letter) language code list with the comprehensiveiso-639-3package.This enables validation of all ISO 639 standards:
Problem
The recent commit d72c67c (Nov 12, 2025) updated locale validation from a hardcoded list to ISO standards, but only included ISO 639-1 (2-letter codes). This broke validation for languages that only have 3-letter codes:
fil(Filipino)bar(Bavarian)nap(Neapolitan)zgh(Standard Moroccan Tamazight)Solution
Added the
iso-639-3npm package to validate against all ~8,000 official language codes while maintaining strict validation (rejects invalid codes likexyz,fake).Changes
Modified:
packages/locales/src/validation.ts- Use iso-639-3 package instead of hardcoded listpackages/locales/src/validation.spec.ts- Added 5 new tests for 3-letter codespackages/locales/package.json- Added iso-639-3 dependencypnpm-lock.yaml- Lock file update.changeset/add-iso-639-3-validation.md- Changeset for minor version bumpTesting
✅ All 88 tests passing (83 existing + 5 new)
✅ Validated specific failing codes:
fil,bar,nap,zgh✅ Ensures invalid codes are still rejected:
zzz,xxx,fake,testNew Tests
Added comprehensive tests for 3-letter language code validation:
Implementation Details
The implementation is both BCP 47 compliant (syntax) and ISO 639 compliant (semantics):
LOCALE_REGEX(BCP 47 format)iso-639-3package (official language codes)Impact
fillocale