Skip to content

Commit 55ad752

Browse files
committed
Update documentation about i18n component
1 parent 4a51c17 commit 55ad752

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

docs/api/i18n-component.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,63 @@
1+
---
2+
description: i18n component allows localizing text that contains HTML elements or Vue.js components | fluent-vue - Vue.js internationalization plugin
3+
---
4+
15
# `i18n` component
26

3-
Allows to use Vue components and html elements inside translation messages.
7+
Very common problem of localizing web apps is localizing text that needs to include HTML elements or components. Consider the example:
8+
9+
```html
10+
<p>
11+
<router-link :to="{ name: 'login' }">Sign in</router-link>
12+
or
13+
<router-link :to="{ name: 'register' }">sign up</router-link>
14+
to add comments on this article.
15+
</p>
16+
```
17+
18+
One solution for this could be to translate each part of the message separatelly like this:
19+
20+
```html
21+
<p>
22+
<router-link :to="{ name: 'login' }">{{ $t('sign-in') }}</router-link>
23+
{{ $t('or') }}
24+
<router-link :to="{ name: 'register' }">{{ $t('sign-up') }}</router-link>
25+
{{ $t('to-comment') }}
26+
</p>
27+
```
28+
29+
But this is cumbersome and could lead to confusion and errors, as it is hard to see that these messages are actually just one sentence.
30+
31+
Another solution is using v-html directive. But that only works for simpler static HTML. And it could lead to accidentaly breaking a page if the message is not properly formatted.
32+
33+
`i18n` component allows to use Vue components and HTML elements inside translation messages.
34+
35+
Previous example would look like this when using `i18n` component:
36+
37+
```html
38+
<i18n path="sign-in-up-to-add-comments" tag="p">
39+
<template #signInLink="{ signInLabel }">
40+
<router-link :to="{ name: 'login' }">{{ signInLabel }}</router-link>
41+
</template>
42+
<template #signUpLink="{ signUpLabel }">
43+
<router-link :to="{ name: 'register' }">{{ signUpLabel }}</router-link>
44+
</template>
45+
</i18n>
46+
```
47+
48+
Localization message:
49+
```ftl
50+
# $signInLink - will be replaced with link to login page
51+
# .sign-in-label - text for login link
52+
sign-in-up-to-add-comments =
53+
{$signInLink} or {$signUpLink} to add comments on this article.
54+
.sign-in-label = Sign in
55+
.sign-up-label = sign up
56+
```
57+
58+
As you can see entire sentence uses just one translation key. It does not use v-html directive. And we can even add comments, so translators know what they are dealing with.
59+
60+
### API
461

562
* Props:
663
* `path {string}` localization message key

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy