![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@intlify/vue-i18n-extensions
Advanced tools
Extensions for vue-i18n
NOTE: :warning: This next
branch is development branch for Vue 3! The stable version is now in master
branch!
This library exports the following extensions:
v-t
custom directive$ npm i --save-dev @intlify/vue-i18n-extensions@alpha
v-t
custom directiveYou can use tnrasform 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
:
import * as runtimeDom from '@vue/runtime-dom'
import { compile } from '@vue/compiler-ssr'
import { defineComponent, createSSRApp } from 'vue'
import { renderToString } from '@vue/server-renderer'
import { createI18n, useI18n } from 'vue-i18n'
import { transformVTDirective } from '@intlify/vue-i18n-extensions'
// create i18n instance
const i18n = createI18n({
locale: 'ja',
messages: {}
})
// get transform from `transformVTDirective` function
const transformVT = transformVTDirective()
// compile your source
const source = `<div v-t="{ path: 'dessert', locale: 'en', plural: 2, args: { name: 'banana' } }"/>`
const { code } = compile(source, {
mode: 'function',
directiveTransforms: { t: transformVT } // <- you need to specify to `directiveTransforms` option!
})
// render functionalization
const render = Function('require', 'Vue', code)(require, runtimeDom)
// e.g. set render function to App component
const App = defineComponent({
setup() {
return useI18n({
locale: 'en',
inheritLocale: false,
messages: {
en: {
apple: 'no apples | one apple | {count} apples',
banana: 'no bananas | {n} banana | {n} bananas',
dessert: 'I eat @:{name}!'
}
}
})
},
ssrRender: render
})
// create SSR app
const app = createSSRApp(App)
// install vue-i18n
app.use(i18n)
console.log(await renderToString(app))
// output -> <div>I eat 2 bananas!</div>`
v-t
custom directiveYou can pre-translation i18n locale messsages of vue-i18n.
:warning: NOTE: Only the scope of global i18n locale messages can be pre-translated !!
:warning: NOTE: Currently 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
:
import { compile } from '@vue/compiler-dom'
import { createI18n } from 'vue-i18n'
import { transformVTDirective } from '@intlify/vue-i18n-extensions'
// create i18n instance
const i18n = createI18n({
locale: 'ja',
messages: {
en: {
hello: 'hello'
},
ja: {
hello: 'こんにちは'
}
}
})
// get transform from `transformVTDirective` function, with `i18n` option
const transformVT = transformVTDirective({ i18n })
const { code } = compile(`<p v-t="'hello'"></p>`, {
mode: 'function',
hoistStatic: true,
prefixIdentifiers: true,
directiveTransforms: { t: transformVT } // <- you need to specify to `directiveTransforms` option!
})
console.log(code)
/*
output ->
const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = Vue
return function render(_ctx, _cache) {
return (_openBlock(), _createBlock(\\"div\\", null, \\"こんにちは!\\"))
}
*/
The following configration example of vue-loader
:
const { VueLoaderPlugin } = require('vue-loader')
const { createI18n } = require('vue-i18n')
const { transformVTDirective } = require('@intlify/vue-i18n-extensions')
const i18n = createI18n({
locale: 'ja',
messages: {
en: {
hello: 'hello'
},
ja: {
hello: 'こんにちは'
}
}
})
const transformVT = transformVTDirective(i18n)
module.exports = {
module: {
// ...
rules: [
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
options: {
compilerOptions: {
directiveTransforms: { t: transformVT }
}
}
}
]
},
// ...
]
},
plugins: [new VueLoaderPlugin()]
}
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
About details, See docs
FAQs
vue-i18n extensions
The npm package @intlify/vue-i18n-extensions receives a total of 105,598 weekly downloads. As such, @intlify/vue-i18n-extensions popularity was classified as popular.
We found that @intlify/vue-i18n-extensions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.