Skip to content

Commit

Permalink
fxied:i18n config change not refresh bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cczw2010 committed Feb 14, 2024
1 parent 5c46ac7 commit 5766acb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions packages/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* silentFallbackWarn:true, // 静默回滚错误
*/
import VueI18n from 'vue-i18n'
<%const dir = option.dir||'i18n'%>
const langsImporter = import.meta.glob("@/<%=dir||'i18n'%>/*.json")
const langsImporter = import.meta.glob("@/<%=(option.dir||'i18n')%>/*.json")
// console.log(langsImporter)
// i18n操作类
class LocaleOperator{
Expand All @@ -19,9 +18,6 @@ class LocaleOperator{
const regs = k.match(/\W([a-zA-Z]+\w+)\.json$/i)
if(regs&&regs.length>1){
const lang = regs[1]
// if(!options.messages[lang]){
// options.messages[lang] = {}
// }
this.dymicImporters[lang] = [langsImporter[k]]
}
}
Expand All @@ -32,10 +28,14 @@ class LocaleOperator{
}
// 获取当前语言
getLocale(){
let locale = this.i18n.locale
if(window&&window.localStorage){
return localStorage.getItem(this.localeKey)
const localLang = localStorage.getItem(this.localeKey)
if(localLang && locale!=localLang){
locale = localLang
}
}
return this.i18n.locale
return locale
}
// 设置当前语言
setLocale(lang){
Expand Down Expand Up @@ -137,7 +137,9 @@ export default async function(option,Context){
})
Context.hook("APP:CREATED",function(){
// 初始化默认语言
localeOperator.loadLocaleMessage(localeOperator.getLocale())
const locale = localeOperator.getLocale()
localeOperator.loadLocaleMessage(locale)
localeOperator.setLocale(locale)
// 注册router钩子函数来判断语言
Context.router.beforeEach((to,from,next)=>{
localeOperator.loadLocaleMessage(localeOperator.i18n.locale).then(next())
Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vitescv/i18n",
"version": "2.0.1",
"version": "2.0.2",
"type": "module",
"main": "index.js",
"description": "i18n module for vitescv",
Expand Down

0 comments on commit 5766acb

Please sign in to comment.