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
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 70 additions & 1 deletion vuepress/zh/guide/hot-reload.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# 热重载

您可以使用Webpack的 [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/) (HMR) 功能来监视本地化文件中的更改以及将热更改重新加载到您的应用程序中。
lucasferreiralimax marked this conversation as resolved.
Show resolved Hide resolved

你可以监视本地化文件中的更改,并将更改热重载到应用程序中。

## 基本例子

如果仅使用静态语言环境集,则可以显式热加载这些语言环境:

```js
import Vue from "vue"
import VueI18n from "vue-i18n"
import en from './en'
import ja from './ja'

// 语言环境信息
const messages = {
// ...
en,
ja
}

// VueI18n 实例
Expand All @@ -31,3 +43,60 @@ if (module.hot) {
})
}
```

## 进阶范例

如果您想支持一组不断变化的语言环境,则可以使用 `require.context` 动态地重新加载这些语言环境:

```js
import Vue from "vue";
import VueI18n from "vue-i18n";

Vue.use(VueI18n);

// 加载所有语言环境并记住上下文
function loadMessages() {
const context = require.context("./locales", true, /[a-z0-9-_]+\.json$/i);

const messages = context
.keys()
.map((key) => ({ key, locale: key.match(/[a-z0-9-_]+/i)[0] }))
.reduce(
(messages, { key, locale }) => ({
...messages,
[locale]: context(key),
}),
{}
);

return { context, messages };
}

const { context, messages } = loadMessages();

// VueI18n 实例
const i18n = new VueI18n({
locale: "en",
messages,
});

// 运行程序
const app = new Vue({
i18n,
// ...
}).$mount('#app');

// 热更新
if (module.hot) {
module.hot.accept(context.id, () => {
const { messages: newMessages } = loadMessages();

Object.keys(newMessages)
.filter((locale) => messages[locale] !== newMessages[locale])
.forEach((locale) => {
messages[locale] = newMessages[locale];
i18n.setLocaleMessage(locale, messages[locale]);
});
});
}
```