このコミットが含まれているのは:
+18
-15
@@ -1,13 +1,6 @@
|
||||
import { createInstance } from 'i18next'
|
||||
import { initReactI18next } from 'react-i18next'
|
||||
|
||||
import ainuNavigation from '@/locales/ain-Kana/navigation.json'
|
||||
import ainuCommon from '@/locales/ain-Kana/common.json'
|
||||
import ainuTags from '@/locales/ain-Kana/tags.json'
|
||||
import nipponeseNavigation from '@/locales/ja/navigation.json'
|
||||
import nipponeseCommon from '@/locales/ja/common.json'
|
||||
import nipponeseTags from '@/locales/ja/tags.json'
|
||||
|
||||
import type { LocaleCode } from '@/lib/locales'
|
||||
|
||||
export const i18n = createInstance ()
|
||||
@@ -17,6 +10,8 @@ export const i18n = createInstance ()
|
||||
const translatedResource = (resource: Record<string, unknown>): Record<string, unknown> => {
|
||||
const untranslated = new Set (
|
||||
Array.isArray (resource._untranslated) ? resource._untranslated : [])
|
||||
if (untranslated.has ('*'))
|
||||
return { }
|
||||
const select = (entries: Record<string, unknown>, prefix = ''): Record<string, unknown> =>
|
||||
Object.fromEntries (Object.entries (entries).flatMap (([key, value]) => {
|
||||
const path = prefix ? `${ prefix }.${ key }` : key
|
||||
@@ -32,6 +27,19 @@ const translatedResource = (resource: Record<string, unknown>): Record<string, u
|
||||
}
|
||||
|
||||
|
||||
const dictionaries = import.meta.glob<Record<string, unknown>> ('../locales/*/*.json', {
|
||||
eager: true, import: 'default' })
|
||||
const resources: Record<string, Record<string, Record<string, unknown>>> = { }
|
||||
for (const [path, dictionary] of Object.entries (dictionaries))
|
||||
{
|
||||
const [, , locale, filename] = path.split ('/')
|
||||
resources[locale] ??= { }
|
||||
resources[locale][filename.slice (0, -5)] =
|
||||
locale === 'ain-Kana' ? translatedResource (dictionary) : dictionary
|
||||
}
|
||||
const namespaces = Object.keys (resources.ja ?? { })
|
||||
|
||||
|
||||
void i18n.use (initReactI18next).init ({
|
||||
lng: 'ja',
|
||||
fallbackLng: 'ja',
|
||||
@@ -39,13 +47,8 @@ void i18n.use (initReactI18next).init ({
|
||||
load: 'currentOnly',
|
||||
initAsync: false,
|
||||
defaultNS: 'navigation',
|
||||
ns: ['navigation', 'common', 'tags'],
|
||||
resources: {
|
||||
ja: { navigation: nipponeseNavigation, common: nipponeseCommon, tags: nipponeseTags },
|
||||
'ain-Kana': {
|
||||
navigation: ainuNavigation,
|
||||
common: translatedResource (ainuCommon),
|
||||
tags: translatedResource (ainuTags) } },
|
||||
ns: namespaces,
|
||||
resources,
|
||||
interpolation: { escapeValue: false },
|
||||
returnNull: false,
|
||||
returnEmptyString: false,
|
||||
@@ -77,7 +80,7 @@ export const untranslatedKeys = (
|
||||
|
||||
if (import.meta.env.DEV)
|
||||
{
|
||||
for (const namespace of ['navigation', 'common', 'tags'])
|
||||
for (const namespace of namespaces)
|
||||
{
|
||||
const missing = untranslatedKeys ('ain-Kana', namespace)
|
||||
if (missing.length > 0)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { createElement } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import LocalisedText from '@/components/LocalisedText'
|
||||
import { useLocale } from '@/lib/useLocale'
|
||||
|
||||
|
||||
@@ -12,5 +14,11 @@ export const useUITranslation = (namespace = 'common') => {
|
||||
return { text: result.res, language: result.usedLng }
|
||||
}
|
||||
|
||||
return { message }
|
||||
const label = (key: string, values?: Record<string, string | number>) => {
|
||||
const result = message (key, values)
|
||||
return createElement (LocalisedText, {
|
||||
language: result.language, children: result.text })
|
||||
}
|
||||
|
||||
return { message, label }
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする