GithubHelp home page GithubHelp logo

fluent-vue's Introduction

fluent-vue

styled with prettier Greenkeeper badge Travis Coveralls Dev Dependencies

Vue.js integration for Project Fluent.

Project is in beta state. I don't recommend using it in production just yet, but would greatly appreciate any feedback.

Features

$t method - simple way of adding translations

Resources:

aria-key = Aria value
greeting = Hello, {$name}

Template:

<div :aria-label="$t('aria-key')">{{ $t('greeting', { name: 'World' }) }}</div>

Result:

<div aria-label="Aria value">Hello, ⁨World⁩</div>

$ta method - gets all attributes for translation key

Useful for binding translations to custom components

Resources:

greeting = Hello, {$name}
  .aria-label = Label value

Template:

<div v-bind="$ta('greeting')">{{ $t('greeting', { name: 'World' }) }}</div>

Result:

<div aria-label="Aria value">Hello, ⁨World⁩</div>

v-t directive - binds all whitelisted attributes

Resources:

greeting = Hello, {$name}
  .aria-label = Label value

Template:

<div v:greeting="{ name: 'World' }"></div>

Result:

<div aria-label="Label value">Hello, ⁨World⁩</div>

i18n component - allows using components inside translations

Resources:

greeting = Hello, {$name}

Template:

<i18n path="greeting" tag="div">
  <template #name>
    <b>World</b>
  </template>
</i18n>

Result:

<div>Hello, ⁨<b>World</b></div>

Instalation

Add fluent-vue and @fluent/bundle to your project:

For npm users:

npm install fluent-vue @fluent/bundle

For yarn users:

yarn add fluent-vue @fluent/bundle

Install Vue plugin

import Vue from 'vue';
import FluentVue from 'fluent-vue';

Vue.use(FluentVue)

Configure fluent-vue

import { FluentBundle, FluentResource } from '@fluent/bundle';

// Create bundle
const bundle = new FluentBundle({
  locales: 'en'
})

// Add resources to the bundle 
bundle.addResource(new FluentResource('key = World'))
bundle.addResource(new FluentResource('another-key = Hello, {$name}'))

// Create `FluentVue` instance with options
const fluent = new FluentVue({
  bundles: [bundle]
})

// Add `fluent` option to your Vue instance
new Vue({
  el: "#root",
  fluent,
  render: h => h(App)
})

fluent-vue's People

Contributors

demivan avatar greenkeeper[bot] avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.