mirror of
https://github.com/spliit-app/spliit.git
synced 2025-12-06 01:19:29 +01:00
Merge branch 'bug-missing-translation' of github.com:Uli-Z/spliit-room into Uli-Z-bug-missing-translation
This commit is contained in:
23
src/i18n.ts
23
src/i18n.ts
@@ -1,6 +1,19 @@
|
||||
import { getRequestConfig } from 'next-intl/server'
|
||||
import { getUserLocale } from './lib/locale'
|
||||
|
||||
function mergeDeep<T>(target: T, source: Partial<T>): T {
|
||||
for (const key in source) {
|
||||
const value = (source as any)[key]
|
||||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
;(target as any)[key] = mergeDeep((target as any)[key] || {}, value)
|
||||
} else {
|
||||
;(target as any)[key] = value
|
||||
}
|
||||
}
|
||||
return target
|
||||
}
|
||||
|
||||
|
||||
export const localeLabels = {
|
||||
'en-US': 'English',
|
||||
fi: 'Suomi',
|
||||
@@ -32,8 +45,14 @@ export const defaultLocale: Locale = 'en-US'
|
||||
export default getRequestConfig(async () => {
|
||||
const locale = await getUserLocale()
|
||||
|
||||
const defaultMessages = (await import('../messages/en-US.json')).default
|
||||
const localeMessages = (await import(`../messages/${locale}.json`)).default
|
||||
|
||||
const messages = mergeDeep(structuredClone(defaultMessages), localeMessages)
|
||||
|
||||
|
||||
return {
|
||||
locale,
|
||||
messages: (await import(`../messages/${locale}.json`)).default,
|
||||
locale,
|
||||
messages,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user