• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

sebastian-software/vue-locale: [UNMAINTAINED] Advanced localization support for ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

sebastian-software/vue-locale

开源软件地址(OpenSource Url):

https://github.com/sebastian-software/vue-locale

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

VueJS Logo

VueJS Locale
Sponsored by Version Downloads Build Status Dependencies

VueJS Plugin for advanced localization of web applications.

Links

Installation

Should be installed locally in your project source code:

Installation via JSPM:

jspm install npm:vue-locale

Alternatively you can also use plain old NPM:

npm install vue-locale --save

Integration

Inside your VueJS application you have to register the VueLocale plugin:

import VueLocale from "vue-locale";

Vue.use(VueLocale,
{
  language: SELECTED_LANGUAGE,
  currency: SELECTED_CURRENCY,
  messages: MESSAGE_TEXTS
})

While these are typical examples of values:

  • SELECTED_LANGUAGE: "de", "en", "fr", ... (any valid language identifier)
  • SELECTED_CURRENCY: "EUR", "USD", ... (any valid currency from CLDR data)
  • MESSAGE_TEXTS: { key : value, ...}

Loading required locale data

Depending on whether your clients support the Intl API + all relevant locales (prominent exceptions right now are NodeJS, Safari on Mac and Safari on iOS) the amount of data and polyfills to load differs.

Loading Intl-Polyfill + Data for 4 Locales

import intl_en from "intl/locale-data/json/en.json"
import intl_de from "intl/locale-data/json/de.json"
import intl_fr from "intl/locale-data/json/fr.json"
import intl_es from "intl/locale-data/json/es.json"

IntlPolyfill.__addLocaleData(intl_en)
IntlPolyfill.__addLocaleData(intl_de)
IntlPolyfill.__addLocaleData(intl_fr)
IntlPolyfill.__addLocaleData(intl_es)

The data loaded here contains information on how to format dates (+ calendar data) and numbers (+ currencies).

Loading FormatJS Data for 4 Locales

Because of an incompatible JSONP-like approach of the data delivered through FormatJS, we have integrated the data in some ES2015/JSPM compatible way in the vue-locale project. To load the data to the following:

import IntlRelativeFormat from "intl-relativeformat"

import relative_en from "./data/en.js"
import relative_de from "./data/de.js"
import relative_fr from "./data/fr.js"
import relative_es from "./data/es.js"

IntlRelativeFormat.__addLocaleData(relative_en)
IntlRelativeFormat.__addLocaleData(relative_de)
IntlRelativeFormat.__addLocaleData(relative_fr)
IntlRelativeFormat.__addLocaleData(relative_es)

The data loaded here contains formatting instructions for relative formats + the required plural function for figuring out the required plural wording for message formatting.

Usage

Adding Messages

You should pass the matching locale data structure with relevant messages e.g. German.

let messages =
{
  "my-message-identifier": "Hallo Welt!",
  "my-html-identifier": "Hallo <b>Welt</b>!",
  "my-personal-identifier": "Hallo {name}!",
  ...
}

Translating messages using VueJS filter

  • Plain Text: {{ "my-message-identifier" | format-message }}
  • HTML Output: {{{ "my-html-identifier" | format-message }}}
  • Personal: Not possible because we can't pass the required additional data structure to the filter

Translating using function calls

  • Plain Text: {{ $formatMessage("my-message-identifier") }}
  • HTML Output: {{{ $formatMessage("my-html-identifier") }}}
  • Personal: {{{ $formatMessage("my-personal-identifier", { name : screenName }) }}}

Formatting Numbers

  • Number Formatting #1: {{ 3.14159 | format-number }} => "3,14159"
  • Number Formatting #2: {{ 3.14159 | format-number 2 }} => "3,14"
  • Number Formatting #3: {{ 3.14159 | format-number 0 }} => "3"
  • Percent Formatting #1: {{ 0.641322 | format-percent }} => "64%"
  • Percent Formatting #2: {{ 0.641322 | format-percent 2 }} => "64,13%"
  • Currency Formatting #1: {{ 21.37 | format-currency }} => "21 €"
  • Currency Formatting #2: {{ 21.37 | format-currency-precise }} => "21,37 €"

Formatting Dates/Times

  • Date Formatting: {{ new Date | format-date }} => 12.2.2016
  • Time Formatting: {{ new Date | format-time }} => 14:23 Uhr

Formatting Relative Dates

  • Relative Formatting: {{ new Date - (1000 * 60 * 10) | format-relative }} => vor 10 Minuten

Copyright

Sebastian Software GmbH Logo

Copyright 2015-2016
Sebastian Software GmbH




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap