@intlify/vue-i18n-bridge
Advanced tools
Comparing version 0.0.0-f84f443 to 0.1.0-0cf3395
{ | ||
"name": "@intlify/vue-i18n-bridge", | ||
"version": "0.0.0-f84f443", | ||
"description": "The vue-i18n bridging for Vue 2 & Vue 3", | ||
"version": "0.1.0-0cf3395", | ||
"description": "Vue I18n bridging for Vue 2 & Vue 3", | ||
"peerDependencies": { | ||
@@ -51,10 +51,10 @@ "@vue/composition-api": "^1.0.0-rc.1", | ||
}, | ||
"homepage": "https://github.com/intlify/routing/tree/main/packages/vue-i18n-bridge#readme", | ||
"homepage": "https://github.com/intlify/bridging/tree/main/packages/vue-i18n-bridge#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/intlify/routing.git", | ||
"url": "git+https://github.com/intlify/bridging.git", | ||
"directory": "packages/vue-i18n-bridge" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/intlify/routing/issues" | ||
"url": "https://github.com/intlify/bridging/issues" | ||
}, | ||
@@ -61,0 +61,0 @@ "engines": { |
143
README.md
# @intlify/vue-i18n-bridge | ||
The vue-i18n bridging for Vue 2 & Vue 3 | ||
Vue I18n bridging for Vue 2 & Vue 3 | ||
> This library is inspired by [vue-demi](https://github.com/vueuse/vue-demi) | ||
## đ Features | ||
- Vue I18n composable APIs available on Vue 2 & Vue 3 (e.g `createI18n`, `useI18n`) | ||
- Auto detect Vue Router version on bundling | ||
- Manual switch versions | ||
## đŋ Installation | ||
```sh | ||
# npm | ||
npm install @intlify/vue-i18n-bridge | ||
# yarn | ||
yarn add @intlify/vue-i18n-bridge | ||
# pnpm | ||
pnpm add @intlify/vue-i18n-bridge | ||
``` | ||
## âī¸ Dependencies | ||
You need to add `vue-i18n` and `@vue/composition-api` to your plugin's peer dependencies to specify what versions you support. | ||
```js | ||
{ | ||
"dependencies": { | ||
"@intlify/vue-i18n-bridge": "latest" | ||
}, | ||
"peerDependencies": { | ||
"@vue/composition-api": "^1.0.0-rc.1", | ||
"vue-i18n": "^8.26.1" // or "^9.2.0-beta.25" or later base on your preferred working environment | ||
"vue-i18n-bridge": "^9.2.0-beta.25" // if you use `vue-i18n@v8.26.1` or later, you need to configure deps | ||
}, | ||
"peerDependenciesMeta": { | ||
"@vue/composition-api": { | ||
"optional": true | ||
} | ||
}, | ||
"devDependencies": { | ||
"vue-i18n": "^8.26.1", // or "^9.2.0-beta.25" or later base on your preferred working environment | ||
"vue-i18n-bridge": "^9.2.0-beta.25" // if you use `vue-i18n@v8.26.1` or later, you need to configure deps | ||
}, | ||
} | ||
``` | ||
Import everything related to Vue Router from it, it will redirect to `vue-i18n@8.26` + `@vue/composition-api` or `vue-i18n@9.2` based on users' environments. | ||
```js | ||
import { createI18n, useI18n } from '@intlify/vue-i18n-bridge' | ||
``` | ||
When using with [Vite](https://vitejs.dev), you will need to opt-out the pre-bundling to get `@intlify/vue-i18n-bridge` work properly by | ||
```js | ||
// vite.config.js | ||
export default defineConfig({ | ||
optimizeDeps: { | ||
exclude: ['@intlify/vue-i18n-bridge'] | ||
} | ||
}) | ||
``` | ||
## đ¤ Extra APIs | ||
`@intlify/vue-i18n-bridge` provides extra APIs to help distinguish users' environments and to do some version-specific logic. | ||
### `isVueI18n8` / `isVueI18n9` | ||
```js | ||
import { isVueI18n8, isVueI18n9 } from '@intlify/vue-i18n-bridge' | ||
if (isVueI18n8) { | ||
// Vue I18n 8 only | ||
} else { | ||
// Vue I18n 9 only | ||
} | ||
``` | ||
## đē CLI | ||
To explicitly switch the redirecting version, you can use these commands in your project's root: | ||
### đ¤ Manually Switch Versions | ||
```sh | ||
npx vue-i18n-switch 2 | ||
# or | ||
npx vue-i18n-switch 3 | ||
``` | ||
### đĻ Package Aliasing | ||
If you would like to import `vue-i18n` under an alias, you can use the following command: | ||
```sh | ||
npx vue-i18n-switch 2 vue2 | ||
# or | ||
npx vue-i18n-switch 3 vue3 | ||
``` | ||
### 𩹠Auto Fix | ||
If the postinstall hook doesn't get triggered or you have updated the Vue Router version, try to run the following command to resolve the redirecting: | ||
```sh | ||
npx vue-i18n-fix | ||
``` | ||
### âŗī¸ Isomorphic Testings | ||
You can support testing for both versions by adding npm alias in your dev dependencies. For example: | ||
```js | ||
{ | ||
"scripts": { | ||
"test:8": "vue-i18n-switch 8 vue-i18n-8 && jest", | ||
"test:9": "vue-i18n-switch 9 && jest", | ||
}, | ||
"devDependencies": { | ||
"vue-i18n-8": "^8.26.1", | ||
"vue-i18n-bridge": "^9.2.0-beta.25", | ||
"vue-i18n": "npm:vue-i18n@9.2.0-beta.25" | ||
}, | ||
} | ||
``` | ||
or | ||
```js | ||
{ | ||
"scripts": { | ||
"test:8": "vue-i18n-switch 8 && jest", | ||
"test:9": "vue-i18n-switch 9 vue-i18n-9 && jest", | ||
}, | ||
"devDependencies": { | ||
"vue-i18n": "^8.26.1", | ||
"vue-i18n-9": "npm:vue-i18n@9.2.0-beta.25" | ||
}, | ||
} | ||
``` | ||
## đ Thanks | ||
This package idea was inspired from [vue-demi](https://github.com/vueuse/vue-demi), [@antfu](https://github.com/antfu)'s great work! | ||
## Šī¸ License | ||
[MIT](http://opensource.org/licenses/MIT) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
10459
1
149