Skip to content

Commit

Permalink
Merge pull request #43 from aiji42/omitable-interpolation-skipOnVaria…
Browse files Browse the repository at this point in the history
…bles

feat: make the specification of `interpolation.skipOnVariables` omissible
  • Loading branch information
aiji42 authored Dec 19, 2022
2 parents 704114a + 8e47dbc commit bbf1307
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 219 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ i18next.init({
resources: {
ja: { zod: translation },
},
interpolation: {
// https://www.i18next.com/translation-function/nesting#passing-nesting-to-interpolated
skipOnVariables: false
}
});
z.setErrorMap(zodI18nMap)

Expand Down
4 changes: 0 additions & 4 deletions examples/with-next-i18next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ module.exports = {
},
// https://github.com/i18next/next-i18next#notes
localePath: path.resolve("./public/locales"),
interpolation: {
// https://www.i18next.com/translation-function/nesting#passing-nesting-to-interpolated
skipOnVariables: false,
},
};
```

Expand Down
3 changes: 0 additions & 3 deletions examples/with-next-i18next/next-i18next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ module.exports = {
locales: ["en", "ja", "fr", "ar", "pt", "zh-CN", "is", "es"],
},
localePath: path.resolve("./public/locales"),
interpolation: {
skipOnVariables: false,
},
reloadOnPrerender: true,
};
14 changes: 7 additions & 7 deletions examples/with-next-i18next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
"lint": "next lint"
},
"dependencies": {
"@chakra-ui/react": "^2.4.3",
"@chakra-ui/react": "^2.4.4",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@hookform/resolvers": "^2.9.10",
"framer-motion": "^7.7.3",
"i18next": "^22.4.5",
"next": "13.0.6",
"i18next": "^22.4.6",
"next": "13.0.7",
"next-i18next": "^13.0.1",
"nookies": "^2.5.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "7.40.0",
"react-hook-form": "7.41.0",
"react-i18next": "^12.1.1",
"zod": "3.20.2",
"zod-i18n-map": "*"
},
"devDependencies": {
"@types/node": "18.11.14",
"@types/node": "18.11.17",
"@types/react": "18.0.26",
"@types/react-dom": "18.0.9",
"eslint": "8.29.0",
"eslint-config-next": "13.0.6",
"eslint": "8.30.0",
"eslint-config-next": "13.0.7",
"typescript": "4.9.4"
}
}
7 changes: 2 additions & 5 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ i18next.init({
resources: {
ja: { zod: translation },
},
interpolation: {
// https://www.i18next.com/translation-function/nesting#passing-nesting-to-interpolated
skipOnVariables: false
}
});
z.setErrorMap(zodI18nMap)

Expand Down Expand Up @@ -69,7 +65,7 @@ This project is licensed under the MIT License - see the [LICENSE](https://githu
## Contributors ✨

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand All @@ -86,6 +82,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://github.com/montedonioluiz"><img src="https://avatars.githubusercontent.com/u/36773088?v=4?s=100" width="100px;" alt="Luiz Oliveira Montedonio"/><br /><sub><b>Luiz Oliveira Montedonio</b></sub></a><br /><a href="#translation-montedonioluiz" title="Translation">🌍</a> <a href="https://github.com/aiji42/zod-i18n/commits?author=montedonioluiz" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/izayoi-hibiki"><img src="https://avatars.githubusercontent.com/u/23469365?v=4?s=100" width="100px;" alt="Izayoi Hibiki"/><br /><sub><b>Izayoi Hibiki</b></sub></a><br /><a href="#translation-izayoi-hibiki" title="Translation">🌍</a> <a href="https://github.com/aiji42/zod-i18n/commits?author=izayoi-hibiki" title="Tests">⚠️</a></td>
<td align="center"><a href="https://hrafnkellbaldurs.com/"><img src="https://avatars.githubusercontent.com/u/5609118?v=4?s=100" width="100px;" alt="Hrafnkell Baldursson"/><br /><sub><b>Hrafnkell Baldursson</b></sub></a><br /><a href="#translation-hrafnkellbaldurs" title="Translation">🌍</a> <a href="https://github.com/aiji42/zod-i18n/commits?author=hrafnkellbaldurs" title="Tests">⚠️</a></td>
<td align="center"><a href="http://arturolopez.co"><img src="https://avatars.githubusercontent.com/u/35613775?v=4?s=100" width="100px;" alt="Arturo"/><br /><sub><b>Arturo</b></sub></a><br /><a href="#translation-Arturo-Lopez" title="Translation">🌍</a> <a href="https://github.com/aiji42/zod-i18n/commits?author=Arturo-Lopez" title="Tests">⚠️</a></td>
</tr>
</tbody>
</table>
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
},
"devDependencies": {
"@tsconfig/node16": "^1.0.3",
"@types/node": "^18.11.14",
"@vitest/coverage-c8": "^0.25.8",
"@types/node": "^18.11.17",
"@vitest/coverage-c8": "^0.26.0",
"c8": "^7.12.0",
"i18next": "^22.4.5",
"i18next": "^22.4.6",
"rimraf": "^3.0.2",
"tsup": "^6.5.0",
"typescript": "^4.9.4",
"vite": "^4.0.1",
"vitest": "^0.25.8",
"vite": "^4.0.2",
"vitest": "^0.26.0",
"zod": "^3.20.2"
}
}
6 changes: 6 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const makeZodI18nMap =
expected: `$t(zod:types.${issue.expected})`,
received: `$t(zod:types.${issue.received})`,
defaultValue: message,
interpolation: {
skipOnVariables: false,
},
});
}
break;
Expand Down Expand Up @@ -96,6 +99,9 @@ export const makeZodI18nMap =
message = t(`zod:errors.invalid_string.${issue.validation}`, {
validation: `$t(zod:validations.${issue.validation})`,
defaultValue: message,
interpolation: {
skipOnVariables: false,
},
});
}
break;
Expand Down
5 changes: 1 addition & 4 deletions packages/core/tests/integrations/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import { zodI18nMap } from "../../src";

export const init = async (lng: string) => {
const translation = await import(`../../locales/${lng}/zod.json`);
i18next.init({
await i18next.init({
lng,
resources: {
[lng]: { zod: translation },
},
interpolation: {
skipOnVariables: false,
},
});
z.setErrorMap(zodI18nMap);
};
Expand Down
Loading

1 comment on commit bbf1307

@vercel
Copy link

@vercel vercel bot commented on bbf1307 Dec 19, 2022

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.vercel.app
zod-i18n-git-main-aiji42.vercel.app
zod-i18n-aiji42.vercel.app

Please sign in to comment.