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-multilanguage-legacy

v3.0.6

Published

Multilanguage easy support to Vue.js 2

Downloads

4

Readme

Multi-Language plugin for Vue.js

A very easy-to-use Vue.js plugin that provides multi-language support

Dependencies

  • Vue.js 2.0+

Installation

We have two methods of installation; you can use npm or a standalone.

To install with NPM

Use the following command to install as a dependency:

npm install vue-multilanguage --save

For standalone installation

To install, just copy the file src/vue-multilanguage.js to your plugins directory.

Get Started

Import MultiLanguage plugin and register it in the Vue globally:

import MultiLanguage from 'vue-multilanguage'

Vue.use(MultiLanguage, {
	default: 'en',
	en: {
		hi: 'Hello',
		welcome: 'Welcome, {name}'
	},
	pt: {
		hi: 'Olá',
		welcome: 'Bem-vindo, {name}'
	},
})

NOTE: the plugin receives an object with the supported languages and its messages.

Using in Components

In your components use the v-lang directive to request a translation, sending as modifiers the path of the text you want to display.

<p v-lang.hi></p>

If the message to be displayed has parameters like {name}, send its values as the policy value.

<p v-lang.welcome="{name: 'Vue.JS'}"></p>

We can also define unnamed parameters, using {0}, so in the directive we would pass only the value to be exchanged, and no longer an object.

Embedding messages in components

Sometimes it's easier to use the component model of Vue to manage your languages. You can set local messages in your .vue file like:

<template>
	<p v-lang.hi></p>
</template>
<script>
	export default {
		data() { return {} }
		messages: {
			en: {
				hi: 'Hello'
			},
			pt: {
				hi: 'Olá'
			}
		}
	}
</script>

The vue-multilanguage plugin will first look at the messages option in the local component before looking at globally-defined messages.

Programmatic Usage

There is a translate method that you can use to retrieve a translation. For example:

computed: {
	welcome()  {
		return this.translate('welcome', 'Vue.JS')
	}
}

Change the current language

To change the language currently used by the system, change the language option value to any of its components, for example:

this.language = 'en'

If you don't set a default language on the language object, the default language will be automatically picked up in the client browser. If no language can still be found or you're in a JavaScript environment outside the browser (such as Node.js), then the default language becomes the first language listed.

this.language = 'en'

LocalStorage

As of version 2.2.3 of vue-multilanguage, we are writing the current language in the vue-lang variable of the localStorage, causing even the page refresh language to remain active.

Contributing

To help in the development and expansion of this repository take a FORK to your account, after you have made your modifications do a PULL REQUEST, it will be parsed and included here since it helps the plugin.

Before your PR, run npm run build to transpile ES6 to ES5 file.

You can still contribute to the documentation, although your little one, support new languages, if you see something wrong in English correct it :)

Thank you for contributing!