Package Exports
- fluent-vue
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fluent-vue) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
fluent-vue
fluent-vue is Vue.js plugin that adds bindings for Project Fluent
Instalation
Add fluent-vue and @fluent/bundle to your project:
For npm users:
npm install fluent-vue @fluent/bundleFor yarn users:
yarn add fluent-vue @fluent/bundleNote:
If you are using vue version 2 you need to install @vue/composition-api too
yarn add @vue/composition-apiInstall and configure plugin
import Vue from 'vue';
import { FluentBundle, FluentResource } from '@fluent/bundle';
import { createFluentVue } from 'fluent-vue'
// Create bundle
const bundle = new FluentBundle('en')
// Add resources to the bundle
bundle.addResource(new FluentResource('key = World'))
bundle.addResource(new FluentResource('another-key = Hello, {$name}'))
// Create fluent istance
const fluent = createFluentVue({
locale: 'en',
bundles: [bundle]
})
// Add Vue plugin
Vue.use(fluent)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 valueTemplate:
<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 valueTemplate:
<div v-t: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>