Skip to content

Commit

Permalink
Merge pull request #157 from aiji42/next-release
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
aiji42 authored Jul 23, 2023
2 parents 79903c5 + 4caa537 commit 05c1297
Show file tree
Hide file tree
Showing 15 changed files with 1,352 additions and 5 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export type ZodI18nMapOption = {

### Namespace (`ns`)

You can switch between translation files by specifying a namespace.
You can switch between translation files by specifying a namespace.
This is useful in cases where the application handles validation messages for different purposes, e.g., validation messages for forms are for end users, while input value checks for API schemas are for developers.

The default namespace is `zod`.
Expand Down Expand Up @@ -183,7 +183,7 @@ z.string()

### Handling object schema keys (`handlePath`)

When dealing with structured data, such as when using Zod as a validator for form input values, it is common to generate a schema with `z.object`.
When dealing with structured data, such as when using Zod as a validator for form input values, it is common to generate a schema with `z.object`.
You can handle the object's key in the message by preparing messages with the key in the `with_path` context.

```ts
Expand Down Expand Up @@ -217,11 +217,11 @@ const schema = z.object({
schema.parse({ userName: 1 }); // => User's name is expected string, received number
```

If `_with_path` is suffixed to the key of the message, that message will be adopted in the case of an object type schema.
If `_with_path` is suffixed to the key of the message, that message will be adopted in the case of an object type schema.
If there is no message key with `_with_path`, fall back to the normal error message.

Object schema keys can be handled in the message with `{{path}}`.
By preparing the translated data for the same key as the key in the object schema, the translated value will be output in `{{path}}`, otherwise the key will be output as is.
Object schema keys can be handled in the message with `{{path}}`.
By preparing the translated data for the same key as the key in the object schema, the translated value will be output in `{{path}}`, otherwise the key will be output as is.
It is possible to access nested translation data by specifying `handlePath.keyPrefix`.

```ts
Expand Down Expand Up @@ -268,11 +268,14 @@ z.setErrorMap(
- [Icelandic(is)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/is/zod.json)
- [Italian(it)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/it/zod.json)
- [Japanese(ja)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/ja/zod.json)
- [Lithuanian(lt)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/lt/zod.json)
- [Norwegian(nb)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/nb/zod.json)
- [Dutch(nl)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/nl/zod.json)
- [Polish(pl)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/pl/zod.json)
- [Portuguese(pt)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/pt/zod.json)
- [Russian(ru)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/ru/zod.json)
- [Romanian(ro)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/ro/zod.json)
- [Swedish(sv)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/sv/zod.json)
- [Turkish(tr)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/tr/zod.json)
- Chinese
- [Simplified Chinese(zh-CN)](https://github.com/aiji42/zod-i18n/blob/main/packages/core/locales/zh-CN/zod.json)
Expand Down
3 changes: 3 additions & 0 deletions examples/with-next-i18next/next-i18next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ module.exports = {
"is",
"es",
"nl",
"sv",
"nb",
"de",
"it",
"tr",
"pl",
"lt",
"ru",
"ro",
],
},
localePath: path.resolve("./public/locales"),
Expand Down
3 changes: 3 additions & 0 deletions examples/with-next-i18next/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ export default function HookForm() {
<option value="fr">Français</option>
<option value="is">íslenskur</option>
<option value="ja">日本語</option>
<option value="lt">Lietuvių</option>
<option value="nl">Nederlands</option>
<option value="sv">Swedish</option>
<option value="nb">Norsk bokmål</option>
<option value="pt">Português</option>
<option value="pl">polski</option>
<option value="ru">Русский</option>
<option value="ro">Română</option>
<option value="tr">Türkçe</option>
<option value="zh-CN">简体中文</option>
<option value="zh-TW">繁體中文</option>
Expand Down
7 changes: 7 additions & 0 deletions examples/with-next-i18next/public/locales/lt/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"username": "Vartotojo vardas",
"username_placeholder": "Vardenis Pavardenis",
"email": "El. Paštas",
"favoriteNumber": "Mėgstamiausias skaičius",
"submit": "Pateikti"
}
112 changes: 112 additions & 0 deletions examples/with-next-i18next/public/locales/lt/zod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"errors": {
"invalid_type": "Tikėtasi {{expected}}, gauta(s) {{received}}",
"invalid_type_received_undefined": "Šis laukas yra privalomas",
"invalid_literal": "Klaidinga literalo reikšmė, tikėtasi {{expected}}",
"unrecognized_keys": "Neatpažintas(i) raktas(ai) objekte: {{- keys}}",
"invalid_union": "Klaidinga įvestis",
"invalid_union_discriminator": "Netinkama diksriminanto reikšmė. Tikėtasi {{- options}}",
"invalid_enum_value": "Klaidinga reikšmė. Tikėtasi {{- options}}, gauta '{{received}}'",
"invalid_arguments": "Klaidingi funkcijos argumentai",
"invalid_return_type": "Klaidingas funkcijos gražinamos reikšmės tipas",
"invalid_date": "Klaidinga data",
"custom": "Klaidinga įvestis",
"invalid_intersection_types": "Negalima sujungti sankirtos rezultatų",
"not_multiple_of": "Skaičius privalo būti {{multipleOf}} kartotinis",
"not_finite": "Skaičius privalo būti baigtinis",
"invalid_string": {
"email": "Klaidingas {{validation}}",
"url": "Klaidinga {{validation}}",
"uuid": "Klaidingas {{validation}}",
"cuid": "Klaidingas {{validation}}",
"regex": "Klaidingas {{validation}}",
"datetime": "Klaidinga {{validation}}",
"startsWith": "Klaidinga įvestis: privaloma pradžia \"{{startsWith}}\"",
"endsWith": "Klaidinga įvestis: privaloma pabaiga \"{{endsWith}}\""
},
"too_small": {
"array": {
"exact": "Masyvas privalo turėti {{minimum}} elementą(us)",
"inclusive": "Masyvas privalo turėti bent {{minimum}} elementą(us)",
"not_inclusive": "Masyvas privalo turėti daugiau, nei {{minimum}} elementą(us)"
},
"string": {
"exact": "Tekstas privalo būti sudarytas iš {{minimum}} simbolio(ių)",
"inclusive": "Tekstas privalo būti sudarytas, bent iš {{minimum}} simbolio(ių)",
"not_inclusive": "Tekstas privalo būti ilgesnis, nei {{minimum}} simbolis(iai)"
},
"number": {
"exact": "Skaičius privalo būti {{minimum}}",
"inclusive": "Skaičius privalo būti didesnis arba lygus {{minimum}}",
"not_inclusive": "Skaičius privalo būti didesnis, nei {{minimum}}"
},
"set": {
"exact": "Klaidinga įvestis",
"inclusive": "Klaidinga įvestis",
"not_inclusive": "Klaidinga įvestis"
},
"date": {
"exact": "Data privalo būti {{- minimum, datetime}}",
"inclusive": "Data privalo būti vėlesnė arba lygi {{- minimum, datetime}}",
"not_inclusive": "Data privalo būti vėlesnė, nei {{- minimum, datetime}}"
}
},
"too_big": {
"array": {
"exact": "Masyvas privalo turėti {{maximum}} elementą(us)",
"inclusive": "Masyvas negali turėti daugiau, nei {{maximum}} elementą(us)",
"not_inclusive": "Masyvas privalo turėti mažiau, nei {{maximum}} elementą(us)"
},
"string": {
"exact": "Tekstas privalo būti sudarytas iš {{maximum}} simbolio(ių)",
"inclusive": "Tekstas negali būti sudarytas iš daugiau, nei {{maximum}} simbolio(ių)",
"not_inclusive": "Tekstas privalo būti trumpesnis, nei {{maximum}} simbolis(iai)"
},
"number": {
"exact": "Skaičius privalo būti {{maximum}}",
"inclusive": "Skaičius privalo būti mažesnis arba lygus {{maximum}}",
"not_inclusive": "Skaičius privalo būti mažesnis, nei {{maximum}}"
},
"set": {
"exact": "Klaidinga įvestis",
"inclusive": "Klaidinga įvestis",
"not_inclusive": "Klaidinga įvestis"
},
"date": {
"exact": "Data privalo būti {{- maximum, datetime}}",
"inclusive": "Data privalo būti ankstesnė arba lygi {{- maximum, datetime}}",
"not_inclusive": "Data privalo būti ankstesnė, nei {{- maximum, datetime}}"
}
}
},
"validations": {
"email": "el. paštas",
"url": "nuoroda",
"uuid": "uuid",
"cuid": "cuid",
"regex": "reguliarus išraiškos šablonas",
"datetime": "datos ir laiko reikšmė"
},
"types": {
"function": "funkcija",
"number": "skaičius",
"string": "tekstas",
"nan": "nan",
"integer": "sveikasis skaičius",
"float": "slankusis kablelis",
"boolean": "loginė reikšmė",
"date": "data",
"bigint": "didelis sveikasis skaičius",
"undefined": "neapibrėžtas",
"symbol": "simbolis",
"null": "null",
"array": "masyvas",
"object": "objektas",
"unknown": "nežinomas",
"promise": "pažadas",
"void": "tuščias",
"never": "niekada",
"map": "rakto-reikšmių sąrašas",
"set": "rinkinys"
}
}
7 changes: 7 additions & 0 deletions examples/with-next-i18next/public/locales/ro/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"username": "Nume de utilizator",
"username_placeholder": "Ion Cutărescu",
"email": "Adresă de e-mail",
"favoriteNumber": "Număr favorit",
"submit": "Trimite"
}
112 changes: 112 additions & 0 deletions examples/with-next-i18next/public/locales/ro/zod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"errors": {
"invalid_type": "Tipul de date așteptat era {{expected}}, s-a primit {{received}}",
"invalid_type_received_undefined": "Obligatoriu",
"invalid_literal": "Valoare literală nevalidă, valoarea așteptată era {{expected}}",
"unrecognized_keys": "Chei/e nerecunoscută/e în obiect: {{- keys}}",
"invalid_union": "Intrare nevalidă",
"invalid_union_discriminator": "Valoare nevalidă pentru discriminant. Valori așteptate: {{- options}}",
"invalid_enum_value": "Valoare nevalidă pentru enum. Valori așteptate: {{- options}}, s-a primit: '{{received}}'",
"invalid_arguments": "Parametri nevalizi pentru funcție",
"invalid_return_type": "Tip de date returnat de funcție nevalid",
"invalid_date": "Dată nevalidă",
"custom": "Intrare nevalidă",
"invalid_intersection_types": "Rezultatele intersecției nu s-au putut îmbina",
"not_multiple_of": "Numărul trebuie să fie multiplu de {{multipleOf}}",
"not_finite": "Numărul trebuie să fie finit",
"invalid_string": {
"email": "{{validation}} nevalid",
"url": "{{validation}} nevalid",
"uuid": "{{validation}} nevalid",
"cuid": "{{validation}} nevalid",
"regex": "Nevalid",
"datetime": "{{validation}} nevalid",
"startsWith": "Intrare nevalidă: trebuie să înceapă cu \"{{startsWith}}\"",
"endsWith": "Intrare nevalidă: trebuie să se termine cu \"{{endsWith}}\""
},
"too_small": {
"array": {
"exact": "Lista trebuie să conțină exact {{minimum}} element(e)",
"inclusive": "Lista trebuie să conțină cel puțin {{minimum}} element(e)",
"not_inclusive": "Lista trebuie să conțină mai mult decât {{minimum}} element(e)"
},
"string": {
"exact": "Șirul trebuie să conțină exact {{minimum}} caracter(e)",
"inclusive": "Șirul trebuie să conțină cel puțin {{minimum}} caracter(e)",
"not_inclusive": "Șirul trebuie să conțină peste {{minimum}} caracter(e)"
},
"number": {
"exact": "Numărul trebuie să fie exact {{minimum}}",
"inclusive": "Numărul trebuie să fie mai mare sau egal cu {{minimum}}",
"not_inclusive": "Numărul trebuie să fie strict mai mare decât {{minimum}}"
},
"set": {
"exact": "Intrare nevalidă",
"inclusive": "Intrare nevalidă",
"not_inclusive": "Intrare nevalidă"
},
"date": {
"exact": "Data trebuie să fie exact {{- minimum, datetime}}",
"inclusive": "Data trebuie să fie mai mare sau egală cu {{- minimum, datetime}}",
"not_inclusive": "Data trebuie să fie strict mai mare decât {{- minimum, datetime}}"
}
},
"too_big": {
"array": {
"exact": "Lista trebuie să conțină exact {{maximum}} element(e)",
"inclusive": "Lista trebuie să conțină cel mult {{maximum}} element(e)",
"not_inclusive": "Lista trebuie să conțină mai puțin de {{maximum}} element(e)"
},
"string": {
"exact": "Șirul trebuie să conțină exact {{maximum}} caracter(e)",
"inclusive": "Șirul trebuie să conțină cel mult {{maximum}} caracter(e)",
"not_inclusive": "Șirul trebuie să conțină mai puțin de {{maximum}} caracter(e)"
},
"number": {
"exact": "Numărul trebuie să fie exact {{maximum}}",
"inclusive": "Numărul trebuie să fie mai mic sau egal cu {{maximum}}",
"not_inclusive": "Numărul trebuie să fie strict mai mic decât {{maximum}}"
},
"set": {
"exact": "Intrare nevalidă",
"inclusive": "Intrare nevalidă",
"not_inclusive": "Intrare nevalidă"
},
"date": {
"exact": "Data trebuie să fie exact {{- maximum, datetime}}",
"inclusive": "Data trebuie să fie mai mică sau egală cu {{- maximum, datetime}}",
"not_inclusive": "Data trebuie să fie strict mai mică decât {{- maximum, datetime}}"
}
}
},
"validations": {
"email": "E-mail",
"url": "URL",
"uuid": "UUID",
"cuid": "CUID",
"regex": "Regex",
"datetime": "Dată și timp"
},
"types": {
"function": "funcție",
"number": "număr",
"string": "șir de caractere",
"nan": "NaN",
"integer": "număr întreg",
"float": "număr zecimal",
"boolean": "boolean",
"date": "dată",
"bigint": "număr întreg mare",
"undefined": "nedefinit",
"symbol": "simbol",
"null": "nul",
"array": "listă",
"object": "obiect",
"unknown": "necunoscut",
"promise": "promisiune",
"void": "vid",
"never": "never",
"map": "map",
"set": "mulțime"
}
}
7 changes: 7 additions & 0 deletions examples/with-next-i18next/public/locales/sv/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"username": "Användarnamn",
"username_placeholder": "William Andersson",
"email": "E-post",
"favoriteNumber": "Favoritnummer",
"submit": "Skicka"
}
Loading

1 comment on commit 05c1297

@vercel
Copy link

@vercel vercel bot commented on 05c1297 Jul 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

zod-i18n – ./

zod-i18n-git-main-aiji42.vercel.app
zod-i18n.vercel.app
zod-i18n-aiji42.vercel.app

Please sign in to comment.