Skip to content

Conversation

@maxprilutskiy
Copy link
Contributor

Summary

  • Updates locale validation to accept any valid ISO-standard locale code instead of being restricted to a hardcoded list of ~222 locales
  • Enables support for locale codes like en-NZ, de-LU, es-CO, ar-DZ, etc. that follow ISO standards but weren't previously in the hardcoded list
  • Maintains backward compatibility with all existing tests

Changes

packages/spec/src/locales.ts

  • Added import of isValidLocale from @lingo.dev/_locales package
  • Updated localeCodeSchema to use comprehensive ISO standard validation instead of hardcoded list check
  • Validation now uses normalization + ISO standards validation (184 language codes, 200+ script codes, 249 region codes)

packages/spec/package.json

  • Added @lingo.dev/_locales as a workspace dependency

Validation Coverage

The updated validation accepts locales conforming to:

  • ISO 639-1 language codes (2-letter, e.g., en, es, de)
  • ISO 15924 script codes (4-letter, optional, e.g., Hans, Latn, Cyrl)
  • ISO 3166-1 alpha-2 region codes (2-letter, optional, e.g., US, GB, CN)
  • UN M.49 numeric region codes (3-digit, optional, e.g., 419 for Latin America)

Test Results

✅ All existing tests pass:

  • packages/spec/src/locales.spec.ts - 14 tests passing
  • packages/spec/src/config.spec.ts - 5 tests passing
  • Full build succeeds across all packages

Manual Testing

Verified new locale codes are accepted:

  • en-NZ (New Zealand English)
  • de-LU (Luxembourg German)
  • es-CO (Colombian Spanish)
  • pt-AO (Angolan Portuguese)
  • ar-DZ (Algerian Arabic)
  • sr-Latn-ME (Serbian Latin Montenegro)
  • uz-Cyrl-UZ (Uzbek Cyrillic)

Invalid codes are still rejected:

  • invalid-XX
  • xx-US
  • en-ZZZZ

Benefits

  1. Broader locale support: Users can now use any valid ISO locale code, not just the hardcoded ones
  2. Standards-based: Validation follows ISO 639-1, ISO 15924, ISO 3166-1, and UN M.49 standards
  3. Reduced maintenance: No need to manually add new locales to the hardcoded list
  4. Backward compatible: All existing locale codes continue to work

Test Plan

  • Run pnpm test in packages/spec
  • Run pnpm -r build for full monorepo build
  • Verify new locale codes are accepted
  • Verify invalid locale codes are rejected
  • Confirm all pre-commit hooks pass

maxprilutskiy and others added 3 commits November 12, 2025 14:28
Previously, locale code validation was restricted to a hardcoded list
of ~222 specific locales. This change updates the validation logic to
accept any valid locale code that conforms to ISO standards:

- ISO 639-1 language codes (2-letter)
- ISO 15924 script codes (4-letter, optional)
- ISO 3166-1 alpha-2 region codes (2-letter, optional)
- UN M.49 numeric region codes (3-digit, optional)

The validation now uses the comprehensive validation functions from
the @lingo.dev/_locales package, which includes 184 language codes,
200+ script codes, and 249 region codes.

Changes:
- Add @lingo.dev/_locales dependency to packages/spec
- Update localeCodeSchema to use isValidLocale() instead of hardcoded list
- Maintain backward compatibility with existing normalization
- All existing tests continue to pass

Benefits:
- Supports locale codes like en-NZ, de-LU, es-CO that weren't in the list
- Follows standard locale format validation
- Reduces maintenance burden of hardcoded locale lists
@maxprilutskiy maxprilutskiy merged commit d72c67c into main Nov 12, 2025
2 checks passed
@maxprilutskiy maxprilutskiy deleted the feature/allow-all-valid-locale-codes branch November 12, 2025 06:41
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