Home

Awesome

<img src="https://camo.githubusercontent.com/728ce9f78c3139e76fa69925ad7cc502e32795d2/68747470733a2f2f7675656a732e6f72672f696d616765732f6c6f676f2e706e67" alt="VueJS Logo" width="200" height="200"/>

VueJS TS Locale<br/>Sponsored by Version Downloads Build Status Dependencies

VueJS Plugin for advanced localization of web applications using typescript

Links

Installation

Should be installed locally in your project source code:

npm install vue-ts-locale --save

Integration

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

import VueLocale from "vue-ts-locale";

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

While these are typical examples of values:

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";
import "intl/locale-data/jsonp/en.js";
import "intl/locale-data/jsonp/de.js";
import "intl/locale-data/jsonp/fr.js";
import "intl/locale-data/jsonp/es.js";

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

Usage

Adding Messages

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

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

Translating messages using VueJS filter

Translating using function calls

Formatting Numbers

Formatting Dates/Times

Formatting Relative Dates

Use format methods outside of Vue component

It is possible to use the format methods directly in TS code, but only after the plugin is initialised

import { formatMessage } from "vue-ts-locale";
formatMessage("my-message-identifier");

Copyright

This plugin is based on the work of Sebastian Werner https://github.com/sebastian-software/vue-locale