Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
41378748
"...git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "595ebd11acb79d54b38d27e6e8fb5d71a76773ed"
Commit
41378748
authored
Mar 07, 2024
by
Ased Mammad
Browse files
refac: Move store to i18n index
parent
6a271a16
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
38 deletions
+37
-38
src/lib/i18n/index.ts
src/lib/i18n/index.ts
+37
-4
src/lib/i18n/store.ts
src/lib/i18n/store.ts
+0
-34
No files found.
src/lib/i18n/index.ts
View file @
41378748
import
i18next
from
'
i18next
'
;
import
i18next
from
'
i18next
'
;
import
resourcesToBackend
from
'
i18next-resources-to-backend
'
;
import
resourcesToBackend
from
'
i18next-resources-to-backend
'
;
import
LanguageDetector
from
'
i18next-browser-languagedetector
'
;
import
LanguageDetector
from
'
i18next-browser-languagedetector
'
;
import
{
createI18nStore
,
isLoading
as
isLoadingStore
}
from
'
./store
'
;
import
type
{
i18n
as
i18nType
}
from
'
i18next
'
;
import
{
writable
}
from
'
svelte/store
'
;
const
createI18nStore
=
(
i18n
:
i18n
)
=>
{
const
i18nWritable
=
writable
(
i18n
);
i18n
.
on
(
'
initialized
'
,
()
=>
{
i18nWritable
.
set
(
i18n
);
});
i18n
.
on
(
'
loaded
'
,
()
=>
{
i18nWritable
.
set
(
i18n
);
});
i18n
.
on
(
'
added
'
,
()
=>
i18nWritable
.
set
(
i18n
));
i18n
.
on
(
'
languageChanged
'
,
()
=>
{
i18nWritable
.
set
(
i18n
);
});
return
i18nWritable
;
};
const
createIsLoadingStore
=
(
i18n
:
i18n
)
=>
{
const
isLoading
=
writable
(
false
);
// if loaded resources are empty || {}, set loading to true
i18n
.
on
(
'
loaded
'
,
(
resources
)
=>
{
// console.log('loaded:', resources);
Object
.
keys
(
resources
).
length
!==
0
&&
isLoading
.
set
(
false
);
});
// if resources failed loading, set loading to true
i18n
.
on
(
'
failedLoading
'
,
()
=>
{
isLoading
.
set
(
true
);
});
return
isLoading
;
};
i18next
i18next
.
use
(
.
use
(
...
@@ -18,13 +52,12 @@ i18next
...
@@ -18,13 +52,12 @@ i18next
},
},
fallbackLng
:
'
en
'
,
fallbackLng
:
'
en
'
,
ns
:
'
common
'
,
ns
:
'
common
'
,
// backend: {
// loadPath: '/locales/{{lng}}/{{ns}}.json'
// }
interpolation
:
{
interpolation
:
{
escapeValue
:
false
// not needed for svelte as it escapes by default
escapeValue
:
false
// not needed for svelte as it escapes by default
}
}
});
});
const
i18n
=
createI18nStore
(
i18next
);
const
i18n
=
createI18nStore
(
i18next
);
const
isLoadingStore
=
createIsLoadingStore
(
i18next
);
export
default
i18n
;
export
default
i18n
;
export
const
isLoading
=
isLoadingStore
;
export
const
isLoading
=
isLoadingStore
;
src/lib/i18n/store.ts
deleted
100644 → 0
View file @
6a271a16
import
type
{
i18n
}
from
'
i18next
'
;
import
{
writable
}
from
'
svelte/store
'
;
export
const
createI18nStore
=
(
i18n
:
i18n
)
=>
{
const
i18nWritable
=
writable
(
i18n
);
i18n
.
on
(
'
initialized
'
,
()
=>
{
i18nWritable
.
set
(
i18n
);
});
i18n
.
on
(
'
loaded
'
,
()
=>
{
i18nWritable
.
set
(
i18n
);
});
i18n
.
on
(
'
added
'
,
()
=>
i18nWritable
.
set
(
i18n
));
i18n
.
on
(
'
languageChanged
'
,
()
=>
{
i18nWritable
.
set
(
i18n
);
});
return
i18nWritable
;
};
export
const
isLoading
=
(
i18n
:
i18n
)
=>
{
const
isLoading
=
writable
(
false
);
// if loaded resources are empty || {}, set loading to true
i18n
.
on
(
'
loaded
'
,
(
resources
)
=>
{
Object
.
keys
(
resources
).
length
!==
0
&&
isLoading
.
set
(
false
);
});
// if resources failed loading, set loading to true
i18n
.
on
(
'
failedLoading
'
,
()
=>
{
isLoading
.
set
(
true
);
});
return
isLoading
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment