Skip to content

Conversation

@maxprilutskiy
Copy link
Contributor

Summary

Fixes the validation error "Unsupported locale: fil" by replacing the hardcoded ISO 639-1 (2-letter) language code list with the comprehensive iso-639-3 package.

This enables validation of all ISO 639 standards:

  • ✅ 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)

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-3 npm package to validate against all ~8,000 official language codes while maintaining strict validation (rejects invalid codes like xyz, fake).

Changes

Modified:

  • packages/locales/src/validation.ts - Use iso-639-3 package instead of hardcoded list
  • packages/locales/src/validation.spec.ts - Added 5 new tests for 3-letter codes
  • packages/locales/package.json - Added iso-639-3 dependency
  • pnpm-lock.yaml - Lock file update
  • .changeset/add-iso-639-3-validation.md - Changeset for minor version bump

Testing

✅ 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, test

New Tests

Added comprehensive tests for 3-letter language code validation:

  1. Validates ISO 639-2/3 codes (fil, bar, nap, zgh)
  2. Validates common 3-letter codes (eng, spa, fra, deu, jpn)
  3. Validates 3-letter codes in full locales (fil-PH, bar-DE, etc.)
  4. Validates complex locales with script (fil-Latn-PH)
  5. Rejects invalid 3-letter codes

Implementation Details

The implementation is both BCP 47 compliant (syntax) and ISO 639 compliant (semantics):

  • Syntax validation via LOCALE_REGEX (BCP 47 format)
  • Semantic validation via iso-639-3 package (official language codes)
  • Maintains existing validation for scripts (ISO 15924) and regions (ISO 3166 + UN M.49)

Impact

  • 🎯 Fixes immediate issue with fil locale
  • 📈 Increases supported languages from ~184 to ~8,000
  • 🔒 Maintains strict validation (no fake codes accepted)
  • ✅ BCP 47 and ISO 639 standards compliant
  • 📦 Adds lightweight, well-maintained dependency

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.
Copy link
Contributor

Copilot AI left a 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-3 package 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.

Comment on lines 11 to 13
"openrouter",
"ollama",
"mistral",
Copy link

Copilot AI Nov 17, 2025

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.

Copilot uses AI. Check for mistakes.
@maxprilutskiy maxprilutskiy merged commit 0f6ffbf into main Nov 17, 2025
2 of 3 checks passed
@maxprilutskiy maxprilutskiy deleted the fix/add-iso-639-3-language-validation branch November 17, 2025 18:35
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