diff --git a/docs/reference/plugin/plugins/locale.md b/docs/reference/plugin/plugins/locale.md index c5253b9e..2e23d073 100644 --- a/docs/reference/plugin/plugins/locale.md +++ b/docs/reference/plugin/plugins/locale.md @@ -45,7 +45,7 @@ export default { }; ``` ```js -// src/locales/zh-CN.js +// src/locales/en-US.js export default { menu: { interface: 'interface' @@ -76,7 +76,7 @@ export default { locale: 'zh-CN', // default locale fallbackLocale: 'zh-CN', // set fallback locale baseNavigator: true, // 开启浏览器语言检测 - share: true, // 用户是否需要手动改变语言 + legacy: true, // 用户是否需要 Legacy API 模式 } } ``` @@ -105,18 +105,12 @@ export default { 默认情况下,当前语言环境的识别按照:`localStorage` 中 `fes_locale` 值 > 浏览器检测 > `default` 设置的默认语言 > `zh-CN` 中文。 -#### share +#### legacy - **类型**:`Boolean` - **默认值**:`true` -- **详情**:是否共享API,共享语言选择器 `{ SelectLang } `,其他插件可以获取到共享内容。 - -比如: -```js -import { plugin } from "@@/core/coreExports"; -const localeShared = plugin.getShared("locale"); -``` +- **详情**:用户是否需要 Legacy API 模式 ### 运行时配置 @@ -199,4 +193,4 @@ export default { ``` -`useI18n()`返回结果是 [Composer](https://vue-i18n.intlify.dev/api/composition.html#composer),提供类似 `t`、`n`、`d` 等转换函数,在模板中使用。 \ No newline at end of file +`useI18n()`返回结果是 [Composer](https://vue-i18n.intlify.dev/api/composition.html#composer),提供类似 `t`、`n`、`d` 等转换函数,在模板中使用。 diff --git a/docs/zh/reference/plugin/plugins/locale.md b/docs/zh/reference/plugin/plugins/locale.md index 4eaab726..2e23d073 100644 --- a/docs/zh/reference/plugin/plugins/locale.md +++ b/docs/zh/reference/plugin/plugins/locale.md @@ -76,7 +76,7 @@ export default { locale: 'zh-CN', // default locale fallbackLocale: 'zh-CN', // set fallback locale baseNavigator: true, // 开启浏览器语言检测 - share: true, // 用户是否需要手动改变语言 + legacy: true, // 用户是否需要 Legacy API 模式 } } ``` @@ -105,18 +105,12 @@ export default { 默认情况下,当前语言环境的识别按照:`localStorage` 中 `fes_locale` 值 > 浏览器检测 > `default` 设置的默认语言 > `zh-CN` 中文。 -#### share +#### legacy - **类型**:`Boolean` - **默认值**:`true` -- **详情**:是否共享API,共享语言选择器 `{ SelectLang } `,其他插件可以获取到共享内容。 - -比如: -```js -import { plugin } from "@@/core/coreExports"; -const localeShared = plugin.getShared("locale"); -``` +- **详情**:用户是否需要 Legacy API 模式 ### 运行时配置 diff --git a/packages/fes-plugin-locale/src/index.js b/packages/fes-plugin-locale/src/index.js index d7714596..8040883d 100644 --- a/packages/fes-plugin-locale/src/index.js +++ b/packages/fes-plugin-locale/src/index.js @@ -41,7 +41,6 @@ export default (api) => { fallbackLocale: 'zh-CN', // set fallback locale legacy: true, baseNavigator: true, // 开启浏览器语言检测 - share: true, // 用户是否需要手动改变语言 ...api.config.locale }; @@ -61,7 +60,6 @@ export default (api) => { legacy: userConfig.legacy }, null, 2), BASE_NAVIGATOR: userConfig.baseNavigator, - SHARE: userConfig.share, VUE_I18N_PATH: resolvePkg('vue-i18n') } ) diff --git a/packages/fes-plugin-locale/src/runtime/core.tpl b/packages/fes-plugin-locale/src/runtime/core.tpl index f07929bc..eb7b10f6 100644 --- a/packages/fes-plugin-locale/src/runtime/core.tpl +++ b/packages/fes-plugin-locale/src/runtime/core.tpl @@ -10,10 +10,8 @@ import { createI18n, useI18n } from '{{{ VUE_I18N_PATH }}}'; import { plugin, ApplyPluginsType } from "@@/core/coreExports"; import SelectLang from "./views/SelectLang"; -{{ #SHARE }} // 共享出去 plugin.share("locale", {useI18n, SelectLang }); -{{ /SHARE }} const locales = {{{REPLACE_LOCALES}}}; diff --git a/packages/fes-plugin-locale/src/runtime/views/SelectLang.vue b/packages/fes-plugin-locale/src/runtime/views/SelectLang.vue index 7d66ad1c..f1f07b86 100644 --- a/packages/fes-plugin-locale/src/runtime/views/SelectLang.vue +++ b/packages/fes-plugin-locale/src/runtime/views/SelectLang.vue @@ -28,6 +28,7 @@ import { LanguageOutlined } from '@fesjs/fes-design/icon'; import { useI18n } from 'vue-i18n'; import { computed, ref } from 'vue'; import langUConfigMap from '../langUConfigMap'; +import { locale as _locale } from '../core'; export default { components: { @@ -50,7 +51,7 @@ export default { const handleSelect = ({ lang }) => { locale.value = lang; isOpened.value = false; - window.localStorage.setItem('fes_locale', lang); + _locale.setLocale({ locale: lang }); }; return { handleSelect,