Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
The vue-i18n package is a Vue.js plugin for internationalization. It integrates seamlessly with Vue.js applications to enable easy localization and translation of text content within the app. It supports a variety of features including pluralization, datetime formatting, number formatting, and allows for the organization of translation messages in different locales.
Localization
This feature allows you to localize your application's content. You can define translation messages for different locales and use the $t function to display the translated message based on the current locale.
{"template": "<p>{{ $t('message.hello') }}</p>", "i18n": {"messages": {"en": {"message": {"hello": "Hello World!"}}, "fr": {"message": {"hello": "Bonjour le monde!"}}}}}
Pluralization
Pluralization support allows you to handle singular and plural forms of words depending on the count. The $tc function is used to handle this, and it automatically selects the correct form based on the provided count.
{"template": "<p>{{ $tc('message.plural', 1) }}</p><p>{{ $tc('message.plural', 10) }}</p>", "i18n": {"messages": {"en": {"message": {"plural": "{n} apple|{n} apples"}}}}}
DateTime Formatting
DateTime formatting enables you to format dates and times according to the locale's conventions. The $d function is used to format a JavaScript Date object into a readable string.
{"template": "<p>{{ $d(new Date(), 'short') }}</p>", "i18n": {"dateTimeFormats": {"en": {"short": {"year": "numeric", "month": "short", "day": "numeric"}}}}}
Number Formatting
Number formatting allows you to format numbers in a locale-sensitive manner. The $n function is used to format numbers, such as currencies, percentages, or decimal numbers, according to the locale's formatting rules.
{"template": "<p>{{ $n(1234567.89, 'currency') }}</p>", "i18n": {"numberFormats": {"en": {"currency": {"style": "currency", "currency": "USD"}}}}}
React Intl is similar to vue-i18n but is designed for React applications. It provides a set of React components and an API to format dates, numbers, and strings, including pluralization and handling translations.
i18next is a full-featured i18n library for JavaScript. It works with various frameworks, including React, Vue, and Angular. It offers features like pluralization, formatting, and supports backend loading of translation resources, making it a versatile alternative to vue-i18n.
Polyglot.js is a tiny I18n helper library written in JavaScript, influenced by the Ruby library I18n. It doesn't have direct integration with Vue.js but can be used in any JavaScript application for simple translation purposes, with a straightforward API for interpolation and pluralization.
Angular Translate is an AngularJS module for internationalization. It provides services and directives that enable translation support similar to vue-i18n but is specifically tailored for AngularJS applications.
Internationalization plugin of Vue.js
0.12.0
+$ npm install vue-i18n
When used in CommonJS, you must explicitly install the router via Vue.use():
var Vue = require('vue')
var VueI18n = require('vue-i18n')
Vue.use(VueI18n, { ... })
var Vue = require('vue')
var i18n = require('vue-i18n')
// ready translated locales
var locales = {
en: {
message: {
hello: 'the world'
}
},
ja: {
message: {
hello: 'ザ・ワールド'
}
}
}
// set plugin
Vue.use(i18n, {
lang: 'ja',
locales: locales
})
// create instance
new Vue({
el: '#test-i18n'
})
Template the following:
<div id="test-i18n" class="message">
<p>{{ $t("message.hello") }}</p>
</div>
Output the following:
<div id="test-i18n" class="message">
<p>ザ・ワールド</p>
</div>
Locale the following:
var locales = {
en: {
message: {
hello: '{msg} world'
}
}
}
Template the following:
<div class="message">
<p>{{ $t('message.hello', { msg: "hello"}) }}</p>
</div>
Output the following:
<div class="message">
<p>hello world</p>
</div>
Locale the following:
var locales = {
en: {
message: {
hello: '{0} world'
}
}
}
Template the following:
<div class="message">
<p>{{ $t('message.hello', ["hello"]) }}</p>
</div>
Output the following:
<div class="message">
<p>hello world</p>
</div>
String
requiredString
optionalArray | Object
optionalTranslate the locale of keypath
. If you specified lang
, translate the locale of lang
. If you specified keypath
of list / named formatting local, you must specify arguments
too. For arguments
more details see Formatting.
Vue.use(plugin, {
lang: 'en',
locales: {
en: {
...
},
...
ja: {
...
}
}
})
Specify translate the language code.
If you abbreviated the lang
option, translate as well as 'en' language code option (default: 'en').
Specify translate some local dictionary.
If you abbreviated the locales
option, set the empty local dictionary.
Get or set a global translation language code. Default by en
string value. You can change the language of the global level dynamic translation in your application.
When specified with lang
plugins option at Vue.use
, Vue.config.lang
is set that value.
dev
: git branch my-new-topic origin/dev
git commit -am 'Add some topic'
git push origin my-new-topic
dev
branch of kazupon/vue-i18n
repository !$ make test
FAQs
Internationalization plugin for Vue.js
The npm package vue-i18n receives a total of 985,280 weekly downloads. As such, vue-i18n popularity was classified as popular.
We found that vue-i18n demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.