このコミットが含まれているのは:
@@ -0,0 +1,56 @@
|
||||
import { createInstance } from 'i18next'
|
||||
import { initReactI18next } from 'react-i18next'
|
||||
|
||||
import ainuNavigation from '@/locales/ain-Kana/navigation.json'
|
||||
import nipponeseNavigation from '@/locales/ja/navigation.json'
|
||||
|
||||
import type { LocaleCode } from '@/lib/locales'
|
||||
|
||||
export const i18n = createInstance ()
|
||||
|
||||
void i18n.use (initReactI18next).init ({
|
||||
lng: 'ja',
|
||||
fallbackLng: 'ja',
|
||||
supportedLngs: ['ja', 'ain-Kana'],
|
||||
load: 'currentOnly',
|
||||
initAsync: false,
|
||||
defaultNS: 'navigation',
|
||||
ns: ['navigation'],
|
||||
resources: {
|
||||
ja: { navigation: nipponeseNavigation },
|
||||
'ain-Kana': { navigation: ainuNavigation } },
|
||||
interpolation: { escapeValue: false },
|
||||
returnNull: false,
|
||||
returnEmptyString: false,
|
||||
saveMissing: import.meta.env.DEV,
|
||||
missingKeyHandler: (languages, namespace, key) => {
|
||||
console.warn ('[i18n] missing key', { languages, namespace, key })
|
||||
},
|
||||
react: { useSuspense: false } })
|
||||
|
||||
|
||||
export const untranslatedKeys = (
|
||||
locale: LocaleCode,
|
||||
namespace = 'navigation',
|
||||
): string[] => {
|
||||
const collect = (resource: Record<string, unknown>, prefix = ''): string[] =>
|
||||
Object.entries (resource).flatMap (([key, value]) => {
|
||||
const path = prefix ? `${ prefix }.${ key }` : key
|
||||
return (value != null && typeof value === 'object')
|
||||
? collect (value as Record<string, unknown>, path)
|
||||
: [path]
|
||||
})
|
||||
const baseline = i18n.getResourceBundle ('ja', namespace) ?? { }
|
||||
return collect (baseline).filter (key => {
|
||||
const value = i18n.getResource (locale, namespace, key)
|
||||
return typeof value !== 'string' || value.length === 0
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if (import.meta.env.DEV)
|
||||
{
|
||||
const missing = untranslatedKeys ('ain-Kana')
|
||||
if (missing.length > 0)
|
||||
console.warn ('[i18n] ain-Kana: untranslated navigation keys', missing)
|
||||
}
|
||||
+12
-31
@@ -1,38 +1,19 @@
|
||||
import { i18n } from '@/lib/i18n'
|
||||
|
||||
import type navigation from '@/locales/ja/navigation.json'
|
||||
import type { LocaleCode } from '@/lib/locales'
|
||||
|
||||
const japanese = {
|
||||
square: '広場',
|
||||
list: '一覧',
|
||||
search: '検索',
|
||||
add: '追加',
|
||||
history: '履歴',
|
||||
allHistory: '全体履歴',
|
||||
help: 'ヘルプ',
|
||||
tags: 'タグ',
|
||||
master: 'マスタ',
|
||||
nicoLinks: 'ニコニコ連携',
|
||||
materials: '素材',
|
||||
suppressions: '抑止',
|
||||
wiki: 'Wiki',
|
||||
create: '新規',
|
||||
edit: '編輯',
|
||||
entertainment: 'おたのしみ',
|
||||
theatre: '上映会 (β)',
|
||||
gekanator: 'グカネータ (β)',
|
||||
users: 'ユーザ',
|
||||
currentUser: 'お前',
|
||||
settings: '設定',
|
||||
legal: '法規',
|
||||
terms: '利用規約' }
|
||||
|
||||
export type UIMessageKey = keyof typeof japanese
|
||||
|
||||
const ainu: Partial<Record<UIMessageKey, string>> = { }
|
||||
export type UIMessageKey = keyof typeof navigation
|
||||
|
||||
|
||||
export const uiMessage = (locale: LocaleCode, key: UIMessageKey): string =>
|
||||
(locale === 'ain-Kana' ? ainu[key] : null) ?? japanese[key]
|
||||
export const uiMessage = (
|
||||
locale: LocaleCode,
|
||||
key: UIMessageKey,
|
||||
values: Record<string, string | number> = { },
|
||||
): string => i18n.t (key, { ...values, lng: locale, ns: 'navigation' })
|
||||
|
||||
|
||||
export const uiMessageLanguage = (locale: LocaleCode, key: UIMessageKey): 'ja' | 'ain' =>
|
||||
(locale === 'ain-Kana' && ainu[key] != null) ? 'ain' : 'ja'
|
||||
i18n.t (key, { lng: locale, ns: 'navigation', returnDetails: true }).usedLng === 'ain-Kana'
|
||||
? 'ain'
|
||||
: 'ja'
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { matchPath } from 'react-router-dom'
|
||||
|
||||
import { unlocalisedPath } from '@/lib/locales'
|
||||
|
||||
import type { LocaleCode } from '@/lib/locales'
|
||||
|
||||
const PAGE_LOCALES: { path: string; locale: LocaleCode }[] = [
|
||||
{ path: '/gekanator', locale: 'ja' }]
|
||||
|
||||
|
||||
export const requiredPageLocale = (pathname: string): LocaleCode | null =>
|
||||
PAGE_LOCALES.find (page =>
|
||||
matchPath ({ path: page.path, end: true }, unlocalisedPath (pathname)))?.locale ?? null
|
||||
新しいイシューから参照
ユーザーをブロックする