Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs #564

Merged
merged 4 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ module.exports = {
sidebar: [
'introduction',
'instalation',
'api',
{
title: 'Api',
children: ['/api/instance-methods', '/api/v-t-directive', '/api/i18n-component'],
collapsable: false,
},
{
title: 'HOWTO',
children: ['/howto/date-time', '/howto/access-outside-of-component'],
Expand Down
9 changes: 9 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
home: true
meta:
- name: keywords
content: vue i18n l10n vue.js fluent.js translation localization
tagline: Vue.js integration for Project Fluent
actionText: Get Started →
actionLink: /introduction.html
Expand All @@ -12,3 +15,9 @@ features:
details: With fluent-vue-loader you can include localization messages with rest of your single file component code.
footer: MIT Licensed | Copyright © 2020-present Ivan Demchuk
---

## Example

<<< @/components/Simple.vue#snippet

<simple-input />
116 changes: 0 additions & 116 deletions docs/api.md

This file was deleted.

56 changes: 56 additions & 0 deletions docs/api/i18n-component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# `i18n` component

Allows to use Vue components and html elements inside translation messages.

* Props:
* `path {string}` localization message key
* `tag {string}` html tag to generate. Default is span
* `args {object}` message parameters

Message:
```
greeting = Hello, {$userName}!
```

Template:
```html
<i18n path="greeting" tag="div">
<template #userName>
<b>World</b>
</template>
</i18n>
```

Result:
```html
<div>Hello, <b>World</b>!</div>
```

### Scoped slots

Message attributes are passed as scoped slot parameters. This allows to not split translation into multiple messages. And attributes have access to same parameters entire message has access to.

Message:
```
sign-in-or-sign-up =
{$signInLink} or {$signUpLink} to the site.
.sign-in-label = Sign in
.sign-up-label = sign up
```

Template:
```html
<i18n path="sign-in-or-sign-up" tag="p">
<template #signInLink="{ signInLabel }">
<a href="/login">{{ signInLabel }}</a>
</template>
<template #signUpLink="{ signUpLabel }">
<a href="/sign-up">{{ signUpLabel }}</a>
</template>
</i18n>
```

Result:
```html
<p>⁨<a href="/login">Sign in</a>⁩ or ⁨<a href="/sign-up">sign up</a>⁩ to the site.</p>
```
56 changes: 56 additions & 0 deletions docs/api/instance-methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# `$t` and `$ta` instance methods

### `$t` method

Formats message with `key` identifier. `args` will be used to resolve references to variables passed as arguments to the translation.

* Arguments
* `{string} key`: required
* `{object} args`: optional

* Returns: `{string}`

Template:
```html
<p>{{ $t('greeting', { name: 'World' }) }}</p>
```

Message:
```
greating = Hello, {$name}
```

Result:
```html
<p>Hello, World</p>
```

### `$ta` method

Formats message with `key` identifier, but only returns message attributes. `args` will be used to resolve references to variables passed as arguments to the translation.

This method should be used mostly for passing parameters to custom components. For localization of regular html elements [v-t](/api/v-t-directive) directive is more convenient.

* Arguments
* `{string} key`: required
* `{object} args`: optional

* Returns: `{object}`

Template:
```html
<input v-bind="$ta('login-input')" type="email">
```

Message:
```
login-input =
.placeholder = email@example.com
.aria-label = Login input value
.title = Type your login email
```

Result:
```html
<input placeholder="email@example.com" aria-label="Login input value" title="Type your login email" type="email">
```
32 changes: 32 additions & 0 deletions docs/api/v-t-directive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# `v-t` directive

Combines `$t` and `$ta` methods binding message and its attributes to `innerText` and html attributes of a html element.

::: tip Note
By default only localizable html attributes are bound (aria-label, title, alt, etc). Directive modifiers allow specifying additional attributes to bind.
:::

Usage: `v-t:key="values"`.

* Argument:
* `key {string}`: required
* Value:
* `values {object}`: optional
* Modifiers:
* `{string}`: optional

Template:
```html
<a v-t:link="{ userName }" href="/login"></a>
```

Message:
```
link = Hello, {$userName}!
.aria-label = Welcome message for {$userName}
```

Result:
```html
<a href="/login" aria-label="Welcome message for ⁨Jonh Doe⁩">Hello, ⁨Jonh Doe⁩</a>
```
4 changes: 0 additions & 4 deletions docs/integrations/webpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

`fluent-vue-loader` allows to use custom blocks in your single file componens.

Example:

<<< @/components/Simple.vue#snippet

1. Install `fluent-vue-loader` package

<code-group>
Expand Down
20 changes: 15 additions & 5 deletions docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@

Project Fluent keeps simple things simple and makes complex things possible. The syntax used for describing translations is easy to read and understand. At the same time it allows, when necessary, to represent complex concepts from natural languages like gender, plurals, conjugations, and others.

## Example

<<< @/components/Simple.vue#snippet

<simple-input />
```
# Simple things are simple.
hello-user = Hello, {$userName}!

# Complex things are possible.
shared-photos =
{$userName} {$photoCount ->
[one] added one photo
*[other] added {$photoCount} new photos
} to {$userGender ->
[male] his stream
[female] her stream
*[other] their stream
}.
```

## FTL syntax

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist",
"sourceMap": false,
"sourceMap": true,
"target": "ES2019",
"module": "esnext",
"moduleResolution": "node",
Expand Down