vue-i18next
Internationalization for vue using the i18next i18n ecosystem.
Installation
Source can be loaded via
# npm package
$ npm install @panter/vue-i18next
- If you don't use a module loader it will be added to
window.VueI18next
Requirements
- vue >= 2.0.0
- i18next >= 6.0.1
Usage
Check the DEMO to see vue-i18next
in action.
Init
Init direct in Browser
$t
The $t
function is a wrapper for i18next.t
.
Check i18next documentation for more informations.
find i18n in the context
Change Language
Component interpolation
Directive
Full Featured properties:
path
: stringlanguage
: language, optionalargs
: object
i18nOptions
The namespace will be loaded with (loadNamespaces)[http://i18next.com/docs/api/#load-namespaces],so one can lazy load namespaces for components.
There is also the possibility to prefix what key the component is using.
Translations can not only be defined in translation files but also in the i18nOptions
.
Single file components
by @kazupon
To be able to use the <i18>
you need to use the vue-loader:
npm install @kazupon/vue-i18n-loader --save-dev
module.exports = {
// ...
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// you need to specify `i18n` loaders key with `vue-i18n-loader` (https://github.com/kazupon/vue-i18n-loader)
i18n: '@kazupon/vue-i18n-loader'
}
}
},
// ...
]
},
// ...
}
Use it with YAML:
npm install yaml-loader --save-dev
Use Vue.Filter to deal with empty keys
by: @Fohlen
Usage:
{{ $t('some_text') }}
{{ 'some text' | t }}