vue-inter
Install
yarn add vue-inter
CDN: UNPKG | jsDevlir (available as window.VueInter
)
Usage
App entry index.js
:
Vue const inter = locale: 'en' // Define messages for other locales messages: {} inter
Root component App.vue
:
<template> <div id="app"> <format-message path="app.home.greeting" defaultMessage="Hello {name}!" :data="{name: 'egoist'}" /> </div></template>
First, we find message from messages
at given path
, then we fallback to defaultMessage
if not found.
Plural support
You can use intl-messageformat instead of our default template
option to add plural support:
const inter = { const tpl = message thiscurrentLocale return tpl }
Components
<FormatMessage>
Props
path
Type: string
Required: true
Find locale message at given path, or fallback to defaultMessage
below.
defaultMessage
Type: string
data
Type: object
tag
Type: string
object
Default: span
An HTML tag or Vue component.
API
Instance API
Create Instance
const inter = // Current locale locale: 'en' // Messages for each locale messages: en: LocaleMessages zh: LocaleMessages // Message templating template: Template
A LocaleMessages
type is:
While a Template
type is:
inter.formatMessage({ path, defaultMessage }, [data])
Format a message from given path in messages
for current locale:
inter // Or fallback to `defaultMessage` when message was not found// at given pathinter
inter.setCurrentLocale(locale)
Set current locale, e.g.:
inter
inter.currentLocale
Return current locale, e.g.:
intercurrentLocale//=> 'fr'
inter.setLocaleData(locale, localeData)
Set localeData for a locale, e.g.:
inter
inter.availableLocales
Return a list of available locales, e.g.:
interavailableLocales//=> ['fr', 'es']
Component injection
$inter
The Inter instance.
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Author
vue-inter © EGOIST, Released under the MIT License.
Authored and maintained by EGOIST with help from contributors (list).
egoist.moe · GitHub @EGOIST · Twitter @_egoistlily