Skip to content

Commit bf76b98

Browse files
committed
fix(editor2): i18nDefer not working for lazy-loaded pages
1 parent 99047af commit bf76b98

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/i18n/i18n.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { atom, getDefaultStore, useAtomValue } from 'jotai'
22
import { atomWithStorage } from 'jotai/utils'
3-
import { isObject, isString } from 'lodash-es'
3+
import { get, isObject, isString } from 'lodash-es'
44
import mitt from 'mitt'
55
import { Fragment, ReactElement, ReactNode, createElement } from 'react'
66
import { ValueOf } from 'type-fest'
@@ -126,7 +126,9 @@ function createDeferredProxy(path: string) {
126126
if (Object.prototype.hasOwnProperty.call(target, prop)) {
127127
return target[prop]
128128
}
129-
target[prop] = createDeferredProxy(path + '.' + String(prop))
129+
target[prop] = createDeferredProxy(
130+
(path ? path + '.' : '') + String(prop),
131+
)
130132
return target[prop]
131133
},
132134
apply(target, _this, args) {
@@ -136,6 +138,12 @@ function createDeferredProxy(path: string) {
136138
}
137139
return updatedValue
138140
}
141+
if (currentTranslations) {
142+
const translated = get(currentTranslations, path)
143+
if (translated) {
144+
return translated
145+
}
146+
}
139147
return toString()
140148
},
141149
})

0 commit comments

Comments
 (0)