Skip to content

Commit

Permalink
fix: resolve issue with language packs not reloading in development e…
Browse files Browse the repository at this point in the history
…nvironment

Fixes #553
  • Loading branch information
LIlGG committed Aug 26, 2024
1 parent 94c9a96 commit 39c624d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
47 changes: 25 additions & 22 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,33 +273,36 @@ export class SakuraApp implements Sakura {

// 挂载 i18n
if (!Object.getOwnPropertyDescriptor(sakura, "$t")) {
const backends: Array<any> = [
{
type: "backend",
read<Namespace>(
// @ts-ignore
language: LocaleCode,
// @ts-ignore
namespace: Namespace,
callback: (errorValue: unknown, translations: null | [Namespace]) => void
) {
import(`./languages/${language}.json`)
.then((resources) => {
callback(null, resources.default);
})
.catch((error) => {
callback(error, null);
});
},
init: () => {},
},
];
if (import.meta.env.MODE !== "development") {
backends.unshift(LocalStorageBackend)
}
i18next
.use(LanguageDetector)
.use(Backend)
.init({
backend: {
backends: [
LocalStorageBackend,
{
type: "backend",
read<Namespace>(
// @ts-ignore
language: LocaleCode,
// @ts-ignore
namespace: Namespace,
callback: (errorValue: unknown, translations: null | [Namespace]) => void
) {
import(`./languages/${language}.json`)
.then((resources) => {
callback(null, resources.default);
})
.catch((error) => {
callback(error, null);
});
},
init: () => {},
},
],
backends,
backendOptions: [
{
prefix: "i18next_sakura_",
Expand Down
Loading

0 comments on commit 39c624d

Please sign in to comment.