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

Documentation improvemation #1104

Merged
merged 24 commits into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9c6e444
initial translate at config page
lucasferreiralimax Jan 10, 2021
eda3bec
docs translate in Portuguese
lucasferreiralimax Jan 13, 2021
38ffb98
adjustment spacing and translate save
lucasferreiralimax Jan 13, 2021
6be3422
Merge remote-tracking branch 'vue-i18n/v8.x' into v8.x
lucasferreiralimax Jan 15, 2021
0875de7
reduce svg sendcloud and improvement viewBox
lucasferreiralimax Jan 15, 2021
bb79adf
improvement img alt, size and reflect information languages
lucasferreiralimax Jan 15, 2021
1d30341
docs: installation reflect information to languages
lucasferreiralimax Jan 15, 2021
f56507b
docs: legacy, api reflect information to languages
lucasferreiralimax Jan 15, 2021
4ff034b
Merge remote-tracking branch 'vue-i18n/v8.x' into v8.x
lucasferreiralimax Jan 17, 2021
d94b193
Adjustment clean of the patreon occurrences
lucasferreiralimax Jan 17, 2021
3c91f9f
docs: guide compoment page reflect information in languages
lucasferreiralimax Jan 17, 2021
f1a0aaf
docs: guide datetime page reflect information in languages
lucasferreiralimax Jan 17, 2021
4bc9654
docs: guide directive page reflect information in languages
lucasferreiralimax Jan 17, 2021
877a0ee
docs: guide fallback page reflect information in languages
lucasferreiralimax Jan 17, 2021
6d7f0e4
docs: guide hot-reload page reflect information in languages
lucasferreiralimax Jan 17, 2021
5719519
docs: guide interpolation page reflect information in languages
lucasferreiralimax Jan 17, 2021
40d6fee
docs: guide lazy-loading page reflect information in languages
lucasferreiralimax Jan 17, 2021
41dc62e
docs: guide locale page reflect information in languages
lucasferreiralimax Jan 17, 2021
ce3f091
docs: guide messages page reflect information in languages
lucasferreiralimax Jan 17, 2021
aee8893
docs: guide number page reflect information in languages
lucasferreiralimax Jan 17, 2021
fc000a6
docs: guide pluralization page reflect information in languages
lucasferreiralimax Jan 17, 2021
b20995b
adjustment link for default pluralization
lucasferreiralimax Jan 17, 2021
3a61903
docs: guide sfc adjustment example scoped style and reflect informati…
lucasferreiralimax Jan 17, 2021
a5a0bbd
docs: guide tooling page reflect information in languages
lucasferreiralimax Jan 17, 2021
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
14 changes: 7 additions & 7 deletions vuepress/guide/component.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Sometimes you may want to import shared locale messages for certain components,
You can use `sharedMessages` options of `i18n`.

Common Locale Messages example:

```js
export default {
en: {
Expand Down Expand Up @@ -121,7 +122,9 @@ export default {
<p>This is good service</p>
</div>
<div class="footer">
<button type="button">{{ $t('buttons.save') }}</button>
<button type="button">
{{ $t('buttons.save') }}
</button>
</div>
</div>
`,
Expand All @@ -137,16 +140,13 @@ If `sharedMessages` option is specified along with the `messages` option, those

## Translation in functional component

When using a functional component, all data (including props, children, slots, parent, etc.) is passed through the `context` containing the attributes, and it doesn't recognize the `this` scope, so when using the vue-i18n on functional components, you must refer to `$t` as `parent.$t`, check the example below:
When using a functional component, all data (including `props`, `children`, `slots`, `parent`, etc.) is passed through the `context` containing the attributes, and it doesn't recognize the `this` scope, so when using the vue-i18n on functional components, you must refer to `$t` as `parent.$t`, check the example below:

```html
...
<div>
<a
href="#"
target="_blank"
rel="noopener noreferrer">
<img src="" :alt="parent.$t('message.hello')">
<a href="#" target="_blank" rel="noopener noreferrer">
<img src="./assets/example.jpg" :alt="parent.$t('message.hello')">
</a>
</div>
...
Expand Down
2 changes: 1 addition & 1 deletion vuepress/pt/guide/component.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Ao usar um componente funcional, todos os dados (incluindo `props`, `children`,
...
<div>
<a href="#" target="_blank" rel="noopener noreferrer">
<img src="" :alt="parent.$t('message.hello')" />
<img src="./assets/example.jpg" :alt="parent.$t('message.hello')" />
</a>
</div>
...
Expand Down
2 changes: 1 addition & 1 deletion vuepress/ru/guide/component.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default {
...
<div>
<a href="#" target="_blank" rel="noopener noreferrer">
<img src="" :alt="parent.$t('message.hello')" />
<img src="./assets/example.jpg" :alt="parent.$t('message.hello')" />
</a>
</div>
...
Expand Down
59 changes: 54 additions & 5 deletions vuepress/zh/guide/component.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,67 @@ new Vue({

如果你希望在组件语言环境中进行本地化,可以在 `i18n` 选项中用 `sync: false` 和 `locale`。

## 组件的共享语言环境消息
lucasferreiralimax marked this conversation as resolved.
Show resolved Hide resolved

有时您可能想为某些组件导入共享的语言环境消息,而不是从全局语言环境消息(例如,组件某些功能的常用消息)回退。

您可以使用 `i18n` 的 `sharedMessages` 选项。

通用语言环境消息示例:

```js
export default {
en: {
buttons: {
save: "Save",
// ...
}
},
ja: {
buttons: {
save: "保存",
// ...
}
}
}
```

Components:
```js
import commonMessage from './locales/common' // 导入通用语言环境消息

export default {
name: 'ServiceModal',
template: `
<div class="modal">
<div class="body">
<p>This is good service</p>
</div>
<div class="footer">
<button type="button">
{{ $t('buttons.save') }}
</button>
</div>
</div>
`,
i18n: {
messages: { ... },
sharedMessages: commonMessages
}
}
```

如果将 `sharedMessages` 选项与 `messages` 选项一起指定,则这些消息将被合并为语言环境消息,并进入目标组件的VueI18n实例。

## 函数式组件的翻译

使用函数式组件时,所有数据 (包括 prop、子内容、插槽、父级内容等) 都通过包含属性的 `context` 传递,并且它无法识别 `this` 的范围,因此在函数式组件上使用 vue-i18n 时,你必须将 `$t` 称为 `parent.$t`,请查看以下示例:

```html
...
<div>
<a
href="#"
target="_blank"
rel="noopener noreferrer">
<img src="" :alt="parent.$t('message.hello')">
<a href="#" target="_blank" rel="noopener noreferrer">
<img src="./assets/example.jpg" :alt="parent.$t('message.hello')">
</a>
</div>
...
Expand Down