@intlify/vue-i18n-bridge
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,2 +0,2 @@ | ||
declare const VueI18n: any // eslint-disable-line @typescript-eslint/no-explicit-any | ||
declare const VueI18n: undefined | ||
declare const isVueI18n8: boolean | ||
@@ -3,0 +3,0 @@ declare const isVueI18n9: boolean |
@@ -1,2 +0,2 @@ | ||
declare const VueI18n: any // eslint-disable-line @typescript-eslint/no-explicit-any | ||
declare const VueI18n: undefined | ||
declare const isVueI18n8: boolean | ||
@@ -3,0 +3,0 @@ declare const isVueI18n9: boolean |
{ | ||
"name": "@intlify/vue-i18n-bridge", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Vue I18n bridging for Vue 2 & Vue 3", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -9,3 +9,3 @@ # @intlify/vue-i18n-bridge | ||
- Vue I18n composable APIs available on Vue 2 & Vue 3 (e.g `createI18n`, `useI18n`) | ||
- Auto detect Vue Router version on bundling | ||
- Auto detect Vue I18n version on bundling | ||
- Manual switch versions | ||
@@ -51,3 +51,3 @@ ## đŋ Installation | ||
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. | ||
Import everything related to Vue I18n from it, it will redirect to `vue-i18n@8.26` + `@vue/composition-api` or `vue-i18n@9.2` based on users' environments. | ||
@@ -91,5 +91,5 @@ ```js | ||
```sh | ||
npx vue-i18n-switch 2 | ||
npx vue-i18n-switch 8 | ||
# or | ||
npx vue-i18n-switch 3 | ||
npx vue-i18n-switch 9 | ||
``` | ||
@@ -102,9 +102,9 @@ | ||
```sh | ||
npx vue-i18n-switch 2 vue2 | ||
npx vue-i18n-switch 8 vue-i18n-8 | ||
# or | ||
npx vue-i18n-switch 3 vue3 | ||
npx vue-i18n-switch 9 vue-i18n-9 | ||
``` | ||
### 𩹠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: | ||
If the postinstall hook doesn't get triggered or you have updated the Vue I18n version, try to run the following command to resolve the redirecting: | ||
@@ -121,9 +121,9 @@ ```sh | ||
"scripts": { | ||
"test:8": "vue-i18n-switch 8 vue-i18n-8 && jest", | ||
"test:8": "vue-i18n-switch 8 vue-i18n-legacy && jest", | ||
"test:9": "vue-i18n-switch 9 && jest", | ||
}, | ||
"devDependencies": { | ||
"vue-i18n-8": "^8.26.1", | ||
"vue-i18n-legacy": "npm:vue-i18n@^8.26.1", | ||
"vue-i18n-bridge": "^9.2.0-beta.25", | ||
"vue-i18n": "npm:vue-i18n@9.2.0-beta.25" | ||
"vue-i18n": "^9.2.0-beta.25" | ||
}, | ||
@@ -139,7 +139,7 @@ } | ||
"test:8": "vue-i18n-switch 8 && jest", | ||
"test:9": "vue-i18n-switch 9 vue-i18n-9 && jest", | ||
"test:9": "vue-i18n-switch 9 vue-i18n-next && jest", | ||
}, | ||
"devDependencies": { | ||
"vue-i18n": "^8.26.1", | ||
"vue-i18n-9": "npm:vue-i18n@9.2.0-beta.25" | ||
"vue-i18n-next": "npm:vue-i18n@9.2.0-beta.25" | ||
}, | ||
@@ -146,0 +146,0 @@ } |
@@ -22,7 +22,9 @@ const fs = require('fs') // eslint-disable-line @typescript-eslint/no-var-requires | ||
function copy(name, version, i18n) { | ||
function copy(name, version, i18n, esm = false) { | ||
const src = path.join(dir, `v${version}`, name) | ||
const dest = path.join(dir, name) | ||
let content = fs.readFileSync(src, 'utf-8') | ||
content = content.replace(/'i18n'/g, `'${i18n}'`) | ||
content = esm | ||
? content.replace(/from 'vue-i18n'/g, `from '${i18n}'`) | ||
: content.replace(/require\('vue-i18n'\)/g, `require('${i18n}')`) | ||
try { | ||
@@ -43,4 +45,16 @@ fs.unlinkSync(dest) | ||
function checkVueI18n(pkg) { | ||
const i18n = loadModule(pkg) | ||
if (!i18n) { | ||
warn('Vue I18n plugin is not found. Please run "npm install vue-i18n" to install.') | ||
return false | ||
} | ||
return true | ||
} | ||
function switchVersion(version, i18n) { | ||
i18n = i18n || 'vue-i18n' | ||
if (!checkVueI18n(i18n)) { | ||
return | ||
} | ||
if (version === 8 && !checkBridge()) { | ||
@@ -50,4 +64,4 @@ return | ||
copy('index.cjs', version, i18n) | ||
copy('index.mjs', version, i18n) | ||
copy('index.d.ts', version, i18n) | ||
copy('index.mjs', version, i18n, true) | ||
copy('index.d.ts', version, i18n, true) | ||
} | ||
@@ -54,0 +68,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
10651
144