Skip to content

Commit d72c67c

Browse files
feat: allow any valid ISO locale code in validation (#1583)
* feat: allow any valid ISO locale code in validation 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 * docs: add changeset requirements to CLAUDE.md and create changeset
1 parent 4e4e9b3 commit d72c67c

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@lingo.dev/_spec": minor
3+
---
4+
5+
Allow any valid ISO locale code in validation instead of hardcoded list. Validation now accepts any locale conforming to ISO 639-1, ISO 15924, ISO 3166-1, and UN M.49 standards.

CLAUDE.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@
1010

1111
## Testing
1212

13-
- When you add tests - make sure they pass
13+
- When you add tests - make sure they pass
14+
15+
## Changesets
16+
17+
- Every PR must include a changeset
18+
- Create changeset: `pnpm new` from repo root
19+
- For changes that don't need a release (e.g., README updates): `pnpm new:empty`

packages/spec/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"author": "",
2626
"license": "Apache-2.0",
2727
"dependencies": {
28+
"@lingo.dev/_locales": "workspace:*",
2829
"zod": "^3.25.76",
2930
"zod-to-json-schema": "^3.24.5"
3031
},

packages/spec/src/locales.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Z from "zod";
2+
import { isValidLocale } from "@lingo.dev/_locales";
23

34
const localeMap = {
45
// Urdu (Pakistan)
@@ -246,7 +247,11 @@ export const localeCodes = [
246247
] as LocaleCode[];
247248

248249
export const localeCodeSchema = Z.string().refine(
249-
(value) => localeCodes.includes(value as any),
250+
(value) => {
251+
// Normalize locale before validation
252+
const normalized = normalizeLocale(value);
253+
return isValidLocale(normalized);
254+
},
250255
{
251256
message: "Invalid locale code",
252257
},

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)