Gathering detailed insights and metrics for @intlify/vue-i18n-extensions
Gathering detailed insights and metrics for @intlify/vue-i18n-extensions
Gathering detailed insights and metrics for @intlify/vue-i18n-extensions
Gathering detailed insights and metrics for @intlify/vue-i18n-extensions
npm install @intlify/vue-i18n-extensions
25
Supply Chain
90.3
Quality
84.3
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
93 Stars
286 Commits
11 Forks
6 Watching
11 Branches
13 Contributors
Updated on 26 Nov 2024
TypeScript (95.7%)
JavaScript (2.79%)
Shell (0.78%)
Vue (0.38%)
HTML (0.35%)
Cumulative downloads
Total Downloads
Last day
3.1%
25,294
Compared to previous day
Last week
12.1%
125,287
Compared to previous week
Last month
39.9%
468,242
Compared to previous month
Last year
-25.1%
4,066,431
Compared to previous year
29
Extensions for vue-i18n
[!IMPORTANT] This
next
branch is development branch for Vue 3! The version for Vue 2 is now inmaster
branch!
This library exports the following extensions:
v-t
custom directive1# npm 2npm i --save-dev @intlify/vue-i18n-extensions@next 3 4# pnpm 5pnpm add -D @intlify/vue-i18n-extensions@next 6 7# yarn 8yarn add -D @intlify/vue-i18n-extensions@next
v-t
custom directiveYou can use transform offered with this package, to support Server-side rendering for v-t
custom directives.
In order to use this feature, you need to specify to Vue compiler option.
The following example that use compile
of @vue/compiler-ssr
:
1import * as runtimeDom from '@vue/runtime-dom' 2import { compile } from '@vue/compiler-ssr' 3import { defineComponent, createSSRApp } from 'vue' 4import { renderToString } from '@vue/server-renderer' 5import { createI18n, useI18n } from 'vue-i18n' 6import { transformVTDirective } from '@intlify/vue-i18n-extensions' 7 8// create i18n instance 9const i18n = createI18n({ 10 locale: 'ja', 11 messages: {} 12}) 13 14// get transform from `transformVTDirective` function 15const transformVT = transformVTDirective() 16 17// compile your source 18const source = `<div v-t="{ path: 'dessert', locale: 'en', plural: 2, args: { name: 'banana' } }"/>` 19const { code } = compile(source, { 20 mode: 'function', 21 directiveTransforms: { t: transformVT } // <- you need to specify to `directiveTransforms` option! 22}) 23 24// render functionalization 25const render = Function('require', 'Vue', code)(require, runtimeDom) 26 27// e.g. set render function to App component 28const App = defineComponent({ 29 setup() { 30 return useI18n({ 31 locale: 'en', 32 inheritLocale: false, 33 messages: { 34 en: { 35 apple: 'no apples | one apple | {count} apples', 36 banana: 'no bananas | {n} banana | {n} bananas', 37 dessert: 'I eat @:{name}!' 38 } 39 } 40 }) 41 }, 42 ssrRender: render 43}) 44 45// create SSR app 46const app = createSSRApp(App) 47 48// install vue-i18n 49app.use(i18n) 50 51console.log(await renderToString(app)) 52// output -> <div>I eat 2 bananas!</div>`
v-t
custom directiveYou can pre-translation i18n locale messages of vue-i18n.
[!WARNING] Only the global scope i18n locale messages can be pre-translated !!
[!WARNING] only
v-t
custom directive is supported !!
In order to use this feature, you need to specify to Vue compiler option.
The following example that use compile
of @vue/compiler-dom
:
1import { compile } from '@vue/compiler-dom' 2import { createI18n } from 'vue-i18n' 3import { transformVTDirective } from '@intlify/vue-i18n-extensions' 4 5// create i18n instance 6const i18n = createI18n({ 7 locale: 'ja', 8 messages: { 9 en: { 10 hello: 'hello' 11 }, 12 ja: { 13 hello: 'こんにちは' 14 } 15 } 16}) 17 18// get transform from `transformVTDirective` function, with `i18n` option 19const transformVT = transformVTDirective({ i18n }) 20 21const { code } = compile(`<p v-t="'hello'"></p>`, { 22 mode: 'function', 23 hoistStatic: true, 24 prefixIdentifiers: true, 25 directiveTransforms: { t: transformVT } // <- you need to specify to `directiveTransforms` option! 26}) 27console.log(code) 28/* 29 output -> 30 const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = Vue 31 32 return function render(_ctx, _cache) { 33 return (_openBlock(), _createBlock(\\"div\\", null, \\"こんにちは!\\")) 34 } 35*/
The following configuration example of vue-loader
:
1const { VueLoaderPlugin } = require('vue-loader') 2const { createI18n } = require('vue-i18n') 3const { transformVTDirective } = require('@intlify/vue-i18n-extensions') 4 5const i18n = createI18n({ 6 locale: 'ja', 7 messages: { 8 en: { 9 hello: 'hello' 10 }, 11 ja: { 12 hello: 'こんにちは' 13 } 14 } 15}) 16const transformVT = transformVTDirective(i18n) 17 18module.exports = { 19 module: { 20 // ... 21 rules: [ 22 { 23 test: /\.vue$/, 24 use: [ 25 { 26 loader: 'vue-loader', 27 options: { 28 compilerOptions: { 29 directiveTransforms: { t: transformVT } 30 } 31 } 32 } 33 ] 34 } 35 // ... 36 ] 37 }, 38 plugins: [new VueLoaderPlugin()], 39 parallel: false // the compilerOptions.directiveTransforms are not serializable 40}
You can specify the transform resulting from transformVTDirective
in the compiler options for each package offered by vue-next, and tool chains:
@vue/compiler-core
(options
at baseCompile
function)@vue/compiler-dom
(options
at compile
function)@vue/compiler-ssr
(options
at compile
function)@vue/compiler-sfc
(compilerOptions
at compileTemplate
function)vue-loader
(compilerOptions
at options
)rollup-plugin-vue
(compilerOptions
at Options
)vite
(vueCompilerOptions
at CoreOptions
)About details, See docs
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
29 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
6 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More