npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-inter

v3.0.0

Published

Simple i18n for Vue.js

Downloads

208

Readme

vue-inter

NPM version NPM downloads CircleCI 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) {
		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