From ce1bbfc4a943b565d28beb27f2e2cec0a7134d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Sun, 2 Jul 2023 22:00:51 +0200 Subject: [PATCH] feat: add i18n support (#2) * feat: add i18n support * chore: typo in favourite i18n message * chore: remove async * chore: refactor i18n conf and plugin * chore: remove `vueI18n` from nuxt i18n entry * chore: include single and multiple locale files * chore: single es-* json files with wrong content * chore(docs): add i18n support section * chore(docs): add emoji to i18n support section * chore: update `createProvideFunction` * chore: cleanup --- .eslintignore | 1 - .npmrc | 3 +- README.md | 13 + package.json | 19 +- patches/@nuxtjs__i18n@8.0.0-beta.12.patch | 13 + playground/config/i18n.config.mts | 12 + playground/config/i18n.ts | 89 +++++ playground/layouts/default.vue | 16 +- playground/locales/multiple/en-GB.json | 3 + playground/locales/multiple/en-US.json | 3 + playground/locales/multiple/en.json | 3 + playground/locales/multiple/es-419.json | 1 + playground/locales/multiple/es-ES.json | 1 + playground/locales/multiple/es.json | 3 + playground/locales/single/en-GB.json | 3 + playground/locales/single/en-US.json | 3 + playground/locales/single/es-419.json | 3 + playground/locales/single/es-ES.json | 3 + .../{nuxt.config.ts => nuxt.config.mts} | 19 +- playground/package.json | 3 + playground/pages/index.vue | 31 +- pnpm-lock.yaml | 342 ++++++++++++++++++ src/module.ts | 22 +- src/runtime/plugins/i18n.ts | 198 ++++++++++ src/runtime/plugins/vuetify-i18n.mts | 9 + .../plugin.mts => plugins/vuetify.mts} | 2 +- src/types.ts | 3 +- 27 files changed, 790 insertions(+), 31 deletions(-) create mode 100644 patches/@nuxtjs__i18n@8.0.0-beta.12.patch create mode 100644 playground/config/i18n.config.mts create mode 100644 playground/config/i18n.ts create mode 100644 playground/locales/multiple/en-GB.json create mode 100644 playground/locales/multiple/en-US.json create mode 100644 playground/locales/multiple/en.json create mode 100644 playground/locales/multiple/es-419.json create mode 100644 playground/locales/multiple/es-ES.json create mode 100644 playground/locales/multiple/es.json create mode 100644 playground/locales/single/en-GB.json create mode 100644 playground/locales/single/en-US.json create mode 100644 playground/locales/single/es-419.json create mode 100644 playground/locales/single/es-ES.json rename playground/{nuxt.config.ts => nuxt.config.mts} (70%) create mode 100644 src/runtime/plugins/i18n.ts create mode 100644 src/runtime/plugins/vuetify-i18n.mts rename src/runtime/{templates/plugin.mts => plugins/vuetify.mts} (92%) diff --git a/.eslintignore b/.eslintignore index 381cb01..de4d1f0 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,2 @@ dist node_modules -templates diff --git a/.npmrc b/.npmrc index c483022..8fb0b90 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ -shamefully-hoist=true \ No newline at end of file +shamefully-hoist=true +shell-emulator=true diff --git a/README.md b/README.md index 03d2596..0b50b1c 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Zero-config Nuxt module for Vuetify - 🛠️ **Versatile**: custom Vuetify [directives](https://vuetifyjs.com/en/getting-started/installation/#manual-steps) and [labs components](https://vuetifyjs.com/en/labs/introduction/) registration - ✨ **Configurable styles**: configure your variables using [Vuetify SASS Variables](https://vuetifyjs.com/en/features/sass-variables/) - 💥 **SSR**: automatic SSR detection and configuration +- 🌍 **I18n ready**: install [@nuxtjs/i18n](https://v8.i18n.nuxtjs.org/) Nuxt module, and you're ready to use Vuetify [internationalization](https://vuetifyjs.com/en/features/internationalization/) features - 🦾 **Type Strong**: written in [TypeScript](https://www.typescriptlang.org/) ## 📦 Install @@ -73,6 +74,18 @@ export default defineNuxtConfig({ }) ``` +## 🌍 I18n support + +> Requires latest [@nuxtjs/i18n](https://v8.i18n.nuxtjs.org/) Nuxt module: `8.0.0.beta.12`. + +There is a [bug](https://github.com/nuxt-modules/i18n/pull/2193) in the current version that prevents `@nuxtjs/i18n` module to work properly when using `lazy` i18n files. + +If you're using `lazy` i18n files per locale, apply [this patch](./patches/@nuxtjs__i18n@8.0.0-beta.12.patch) to your project: check how to apply it when using `pnpm` in the root `package.json` file in this repo: [./package.json#L25-L26](./package.json#L97-L101). + +You can check the playground folder, you can run it using single or multiple json files per locale: +- for single file per locale: run from root folder `pnpm install && nr dev:prepare && nr dev` +- for multiple files per locale: run from root folder `pnpm install && nr dev:prepare:multiple-json && nr dev:multiple-json` +