All Projects → egoist → Vue Inter

egoist / Vue Inter

Licence: mit
Simple yet powerful 1kB i18n library for Vue.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Inter

Pseudo Localization
Dynamic pseudo-localization in the browser and nodejs
Stars: ✭ 109 (-44.95%)
Mutual labels:  i18n, internationalization
Vue I18n Extract
Manage vue-i18n localization with static analysis
Stars: ✭ 123 (-37.88%)
Mutual labels:  i18n, internationalization
Traduora
Ever® Traduora - Open-Source Translation Management Platform
Stars: ✭ 1,580 (+697.98%)
Mutual labels:  internationalization, i18n
Node Gettext
A JavaScript implementation of gettext, a localization framework.
Stars: ✭ 175 (-11.62%)
Mutual labels:  i18n, internationalization
Jquery.ime
jQuery based input methods library
Stars: ✭ 145 (-26.77%)
Mutual labels:  i18n, internationalization
Android Gradle Localization Plugin
Gradle plugin for generating localized string resources
Stars: ✭ 100 (-49.49%)
Mutual labels:  i18n, internationalization
React Native Localize
🌍 A toolbox for your React Native app localization
Stars: ✭ 1,682 (+749.49%)
Mutual labels:  i18n, internationalization
Keys Translations Manager
KTM, a locale management web app built on MERN stack, lets you manage and control locales in one place. It's particularly useful for someone who needs to manage multiple internationalization/localization projects.
Stars: ✭ 81 (-59.09%)
Mutual labels:  i18n, internationalization
Date
🗓 A library to help you work with dates in multiple languages, based on Carbon.
Stars: ✭ 1,773 (+795.45%)
Mutual labels:  i18n, internationalization
Jquery I18next
i18next plugin for jquery usage
Stars: ✭ 143 (-27.78%)
Mutual labels:  i18n, internationalization
React Translated
A dead simple way to add complex translations (i18n) in a React (DOM/Native) project 🌎🌍🌏
Stars: ✭ 176 (-11.11%)
Mutual labels:  i18n, internationalization
I18next Express Middleware
[deprecated] can be replaced with i18next-http-middleware
Stars: ✭ 195 (-1.52%)
Mutual labels:  i18n, internationalization
Ajv I18n
Internationalised error messages for Ajv JSON-Schema validator
Stars: ✭ 98 (-50.51%)
Mutual labels:  i18n, internationalization
Eslint Plugin I18n Json
Fully extendable eslint plugin for JSON i18n translation files.
Stars: ✭ 101 (-48.99%)
Mutual labels:  i18n, internationalization
Babel Plugin I18next Extract
Babel plugin that statically extracts i18next and react-i18next translation keys.
Stars: ✭ 93 (-53.03%)
Mutual labels:  i18n, internationalization
Phabricator zh hans
Phabricator zh-Hans Translation & Tools.
Stars: ✭ 113 (-42.93%)
Mutual labels:  i18n, internationalization
Gatsby Starter Prismic I18n
Based on gatsby-starter-prismic with Internationalization (i18n) support
Stars: ✭ 77 (-61.11%)
Mutual labels:  i18n, internationalization
Nativescript Localize
Internationalization plugin for NativeScript using native capabilities of each platform
Stars: ✭ 78 (-60.61%)
Mutual labels:  i18n, internationalization
Dom I18n
Provides a very basic HTML multilingual support using JavaScript
Stars: ✭ 125 (-36.87%)
Mutual labels:  i18n, internationalization
Formatjs
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Stars: ✭ 12,869 (+6399.49%)
Mutual labels:  i18n, internationalization

vue-inter

NPM version NPM downloads CircleCI codecov donate chat

Edit vue-inter example

Install

yarn add vue-inter

CDN: UNPKG | jsDevlir (available as window.VueInter)

Usage

App entry index.js:

import Inter from 'vue-inter'
import App from './App.vue'

Vue.use(Inter)

const inter = new Inter({
  locale: 'en',
  // Define messages for other locales
  messages: {}
})

new Vue({
  inter,
  render: h => h(App)
})

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:

import IntlMessageFormat from 'intl-messageformat'

const inter = new Inter({
  template(message, data) {
    if (!data) return message
    const tpl = new IntlMessageFormat(message, this.currentLocale)
    return tpl.format(data)
  }
})

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 = new Inter({
  // Current locale
  locale: 'en',

  // Messages for each locale
  messages: {
    en: LocaleMessages,
    zh: LocaleMessages
  },

  // Message templating
  template: Template
})

A LocaleMessages type is:

interface LocaleMessages {
  /** The value is a string or a function that returns a string */
  [path: string]: string | (...data: any[]) => string
}

While a Template type is:

type Template = (this: Inter, message: string, ...data: any[]) => string

inter.formatMessage({ path, defaultMessage }, [data])

Format a message from given path in messages for current locale:

inter.formatMessage({ path: 'app.hello' }, { name: 'egoist' })

// Or fallback to `defaultMessage` when message was not found
// at given path
inter.formatMessage(
  {
    path: 'not.exists.path',
    defaultMessage: 'Hello {name}'
  },
  { name: 'egoist' }
)

inter.setCurrentLocale(locale)

Set current locale, e.g.:

inter.setCurrentLocale('fr')

inter.currentLocale

Return current locale, e.g.:

inter.currentLocale
//=> 'fr'

inter.setLocaleData(locale, localeData)

Set localeData for a locale, e.g.:

inter.setLocaleData('es', espanaLocaleData)

inter.availableLocales

Return a list of available locales, e.g.:

inter.availableLocales
//=> ['fr', 'es']

Component injection

$inter

The Inter instance.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].