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-translated

v0.4.1

Published

Internationalization (i18n) and localization (l10n) plugin for Vue.js v2.

Downloads

51

Readme

NPM Version Dependency Status

vue-translated

Internationalization (i18n) and localization (l10n) library for Vue.js v2.

This plugin integrates the translated.js library into your Vue.js application.

This is a light weight open source package for Vue.js. The source code is available on GitHub where you can also find our issue tracker.

Related Projects

  • translated.js: Internationalization and localization for JavaScript and Node.js

Installation

Run the command below to install the package.

$ npm install --save vue-translated translated

When used with a module system, you must explicitly install vue-translated via Vue.use().

import Vue from 'vue';
import VueTranslated from 'vue-translated';

Vue.use(VueTranslated);

Getting Started

Initialize translated.js and define a user model.

import {I18n} from 'translated';

const i18n = new I18n({
  locale: 'en-US',
  messages: {
    hello: 'Hello, {name}.'
  }
});

Attach the i18n instance to your Vue.js application.

const app = new Vue({
  i18n, // injecting i18n into child components
  ...
});

By passing the i18n instance to the root Vue instance as the i18n option, the $i18n property is injected into every child component.

Usage Example

This plugin registers i18n methods so you can use them directly.

<template>
  <div>
    <p>{{ $formatMessage('hello', {name: 'John'}) }}</p>
    <p>{{ $formatNumber(1000.13, {format: 'integer'}) }}</p>
    <p>{{ $formatDate(Date.now(), {format: 'long'}) }}</p>
    <p>{{ $formatTime(Date.now(), {format: 'medium'}) }}</p>
    <p>{{ $formatRelativeTime(Date.now() - 10000) }}</p>
  </div>
</template>

API

Please check translated.js API for details.

mv.$formatDate(value, options)

Converts a value into formatted date string.

| Name | Type | Required | Default | Description |------|------|----------|---------|------------ | value | Date, Integer | Yes | - | Date object. | options | Object | No | - | Options which are passed directly into the Intl.DateTimeFormat constructor.

<p>{{ $formatDate(Date.now(), {month: 'numeric', year: 'numeric'}) }</p>

mv.$formatMessage(key, vars)

Compiles a message into a formatted string.

| Name | Type | Required | Default | Description |------|------|----------|---------|------------ | key | String | Yes | - | ICU message (supports number, date, plural, and select). | vars | Object | No | - | Data object.

You can use a plural argument to select sub-messages based on a numeric value, together with the plural rules for the specified language.

<p>{{ $formatMessage(`Hey {name}!`, {name: 'John'}) }</p>

mv.$formatNumber(value, options)

Converts a value into formatted string.

| Name | Type | Required | Default | Description |------|------|----------|---------|------------ | value | Number | Yes | - | Integer or decimal number. | options | Object | No | - | Options which are passed directly into the Intl.NumberFormat constructor.

<p>{{ $formatNumber(1234.56, {maximumFractionDigits: 0}) }</p>

mv.$formatRelativeTime(value, options)

Converts a value into relative time (e.g. 3 days ago).

| Name | Type | Required | Default | Description |------|------|----------|---------|------------ | value | Date, Integer | Yes | - | Date object. | options | Object | No | - | Options for customizing the output (units and style).

<p>{{ $formatRelativeTime(Date.now()) }</p>

mv.$formatTime(value, options)

Converts a value into formatted time string.

| Name | Type | Required | Default | Description |------|------|----------|---------|------------ | value | Date, Integer | Yes | - | Date object. | options | Object | No | - | Options which are passed directly into the Intl.DateTimeFormat constructor.

<p>{{ $formatTime(Date.now(), {hour: 'numeric'}) }</p>

License (MIT)

Copyright (c) 2016 Kristijan Sedlak <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.