Skip to content

Commit

Permalink
Merge pull request #106 from xianyunleo/dev
Browse files Browse the repository at this point in the history
代码优化
  • Loading branch information
xianyunleo authored Apr 3, 2024
2 parents d36c58a + 878dc03 commit b5ba359
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 9 additions & 6 deletions src/main/i18n/I18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export default class I18n {
messages: {
'zh': zh,
'en': en
},
}
}
this._instance.t = this._loadMessages()
this._instance.translate = this._loadMessages()
}

static getInstance() {
Expand All @@ -24,16 +24,19 @@ export default class I18n {

static setLocale(locale) {
this._instance.locale = locale
this._instance.t = this._loadMessages()
this._instance.translate = this._loadMessages()
}

static _loadMessages() {
console.log('this._instance',this._instance)
const message = this._instance.messages[this._instance.locale]
const localize = nls.loadMessages(message)

return (key, args) => {
return localize(key, '', args)
return (key, ...args) => {
return localize(key, '', ...args)
}
}

static t(...args) {
return this._instance.translate(...args)
}
}
5 changes: 2 additions & 3 deletions src/main/utils/i18n.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import I18n from '@/main/i18n/I18n'

export function t(...arg) {
const { t: originT } = I18n.getInstance()
return originT(...arg)
export function t(...args) {
return I18n.t(...args)
}

0 comments on commit b5ba359

Please sign in to comment.