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
86341403
Unverified
Commit
86341403
authored
Jul 01, 2024
by
bannert
Committed by
GitHub
Jul 01, 2024
Browse files
refactor: Remove changes to i18n/index.ts
parent
586de1f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
26 deletions
+30
-26
src/lib/i18n/index.ts
src/lib/i18n/index.ts
+30
-26
No files found.
src/lib/i18n/index.ts
View file @
86341403
import
i18next
from
'
i18next
'
;
import
LanguageDetector
from
'
i18next-browser-languagedetector
'
;
import
resourcesToBackend
from
'
i18next-resources-to-backend
'
;
import
LanguageDetector
from
'
i18next-browser-languagedetector
'
;
import
type
{
i18n
as
i18nType
}
from
'
i18next
'
;
import
{
writable
}
from
'
svelte/store
'
;
...
...
@@ -37,32 +37,36 @@ const createIsLoadingStore = (i18n: i18nType) => {
return
isLoading
;
};
export
const
initI18n
=
(
defaultLocale
?
:
string
)
=>
{
// Use object destructuring for cleaner cod
e
const
[
defaultDetection
,
fallbackDetection
]
=
defaultLocale
?
[
'
querystring
'
,
'
localStorage
'
]
:
[
'
querystring
'
,
'
localStorage
'
,
'
navigator
'
];
// Use nullish coalescing operator to simplify the ternary expression
const
fallbackDefaultLocale
=
defaultLocale
??
'
en-US
'
;
const
loadResource
=
(
language
:
string
,
namespace
:
string
)
=>
import
(
`./locales/
${
language
}
/
${
namespace
}
.json`
);
export
const
initI18n
=
(
defaultLocale
:
string
|
undefined
)
=>
{
let
detectionOrder
=
defaultLocal
e
?
[
'
querystring
'
,
'
localStorage
'
]
:
[
'
querystring
'
,
'
localStorage
'
,
'
navigator
'
];
let
fallbackDefaultLocale
=
defaultLocale
?
[
defaultLocale
]
:
[
'
en-US
'
];
const
loadResource
=
(
language
:
string
,
namespace
:
string
)
=>
import
(
`./locales/
${
language
}
/
${
namespace
}
.json`
);
i18next
.
use
(
resourcesToBackend
(
loadResource
))
.
use
(
LanguageDetector
)
.
init
({
debug
:
false
,
detection
:
{
order
:
[
defaultDetection
,
fallbackDetection
],
caches
:
[
'
localStorage
'
],
lookupQuerystring
:
'
lang
'
,
lookupLocalStorage
:
'
locale
'
},
fallbackLng
:
fallbackDefaultLocale
,
ns
:
'
translation
'
,
returnEmptyString
:
false
,
interpolation
:
{
escapeValue
:
false
}
});
};
.
use
(
resourcesToBackend
(
loadResource
))
.
use
(
LanguageDetector
)
.
init
({
debug
:
false
,
detection
:
{
order
:
detectionOrder
,
caches
:
[
'
localStorage
'
],
lookupQuerystring
:
'
lang
'
,
lookupLocalStorage
:
'
locale
'
},
fallbackLng
:
{
default
:
fallbackDefaultLocale
},
ns
:
'
translation
'
,
returnEmptyString
:
false
,
interpolation
:
{
escapeValue
:
false
// not needed for svelte as it escapes by default
}
});
};
const
i18n
=
createI18nStore
(
i18next
);
const
isLoadingStore
=
createIsLoadingStore
(
i18next
);
...
...
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