0.1.4 • Published 6 years ago

da-translate v0.1.4

Weekly downloads
15
License
-
Repository
-
Last release
6 years ago

da-translate

Simple Vue.js library for language translations with support of masks.

Project setup

npm install --save da-translate 

Initialization

import Vue from 'vue'
import DaTranslate from 'da-translate'

Vue.use(DaTranslate, {
  locale: 'en',
  langs: {
    'en': {
      'simple': 'Simple message',
      'hello': 'Hello, :user'
    },
    'ru': {
      'simple': 'Простое сообщение',
      'hello': 'Привет, :user',
    }
  }
})

You can also change left mask and right mask.
For example you dont want to save user mask as ':user' and want to save as '<{user}>'.
For this you can send left and right mask, when you initialize library

Vue.use(DaTranslate, {
  locale: 'en',
  langs: {
    'en': {
      'simple': 'Simple message',
      'hello': 'Hello, <{user}>',
    },
    'ru': {
      'simple': 'Простое сообщение',
      'hello': 'Привет, <{user}>',
    },
  },
  masks: {
    left: '<{',
    right: '}>',
  }
})

Default values are:

masks: {
  left: ':',
  right: '',
}

Usage

Inside components:
<template>
  <div>
    <h1>dat('simple')</h1>
    <h1>dat('hello', {user: 'John Doe'})</h1>
  </div>
</template>
Inside script
this.dat('simple') 

or

this.$_daTranslate.t('hello', {user: 'User name'})
Usage as imported file:
import daTranslate from 'da-translate'

daTranslate.t('simple')
Language Change

Only inside components

this.$_daTranslate.set('ru')
0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago