some changes

This commit is contained in:
john 2025-06-16 21:28:24 +02:00
parent 5e96ab6955
commit bc5c2075f4
8 changed files with 45 additions and 41 deletions

View file

@ -1,7 +1,7 @@
import { useUser } from '../../user/user.ts' import { useUser } from '../../user/user.ts'
import NavButton from '../../../components/buttons/NavButton.tsx' import NavButton from '../../../components/buttons/NavButton.tsx'
import { useLocation } from 'react-router-dom' import { useLocation } from 'react-router-dom'
import { useTranslations } from '../../i18n/useTranslations.ts' import { useTranslations } from '../../i18n/translations.ts'
export default function AuthNavButtons() { export default function AuthNavButtons() {
const { t } = useTranslations() const { t } = useTranslations()

View file

@ -8,7 +8,7 @@ import { useUser } from '../../user/user.ts'
import NavBar from '../../../components/NavBar.tsx' import NavBar from '../../../components/NavBar.tsx'
import NavButton from '../../../components/buttons/NavButton.tsx' import NavButton from '../../../components/buttons/NavButton.tsx'
import LinkButton from '../../../components/buttons/LinkButton.tsx' import LinkButton from '../../../components/buttons/LinkButton.tsx'
import { useTranslations } from '../../i18n/useTranslations.ts' import { useTranslations } from '../../i18n/translations.ts'
interface LoginPageProps { interface LoginPageProps {
authService: AuthService authService: AuthService

View file

@ -8,7 +8,7 @@ import { AuthService } from '../authService.ts'
import LinkButton from '../../../components/buttons/LinkButton.tsx' import LinkButton from '../../../components/buttons/LinkButton.tsx'
import NavBar from '../../../components/NavBar.tsx' import NavBar from '../../../components/NavBar.tsx'
import NavButton from '../../../components/buttons/NavButton.tsx' import NavButton from '../../../components/buttons/NavButton.tsx'
import { useTranslations } from '../../i18n/useTranslations.ts' import { useTranslations } from '../../i18n/translations.ts'
const SignupCodeKey = 'signupCode' const SignupCodeKey = 'signupCode'

View file

@ -1,24 +0,0 @@
export interface Translations {
'auth.login.cta': string
'auth.login.register_instead': string
'auth.password.label': string
'auth.register.cta': string
'auth.register.login_instead': string
'auth.remember_me.label': string
'auth.username.label': string
'misc.loading': string
'nav.admin': string
'nav.home': string
'nav.login': string
'nav.logout': string
'nav.register': string
'post.add_media.cta': string
'post.editor.placeholder': string
'post.public.label': string
'post.submit.cta': string
}
export type TranslationKey = keyof Translations

View file

@ -0,0 +1,41 @@
import en from './translations/en.json' assert { type: 'json' }
interface Translation {
'auth.login.cta': string
'auth.login.register_instead': string
'auth.password.label': string
'auth.register.cta': string
'auth.register.login_instead': string
'auth.remember_me.label': string
'auth.username.label': string
'misc.loading': string
'nav.admin': string
'nav.home': string
'nav.login': string
'nav.logout': string
'nav.register': string
'post.add_media.cta': string
'post.editor.placeholder': string
'post.public.label': string
'post.submit.cta': string
}
export type TranslationKey = keyof Translation
export interface UseTranslations {
t: <K extends TranslationKey>(key: K) => Translation[K]
}
export function useTranslations(): UseTranslations {
// TODO somehow handle other languages (reactively)
const texts = en as Translation
function getText<K extends TranslationKey>(key: K): Translation[K] {
return texts[key] ?? key
}
return { t: getText }
}

View file

@ -1,13 +0,0 @@
import { TranslationKey, Translations } from './translationKeys.ts'
import en from './en.json' assert { type: 'json' }
export function useTranslations() {
// TODO somehow handle other languages (reactively)
const texts = en as Translations
function getText<K extends TranslationKey>(key: K): Translations[K] {
return texts[key] ?? key
}
return { t: getText }
}

View file

@ -3,7 +3,7 @@ import FancyTextEditor, { TextInputKeyDownEvent } from './inputs/FancyTextEditor
import Button from './buttons/Button.tsx' import Button from './buttons/Button.tsx'
import { openFileDialog } from '../utils/openFileDialog.ts' import { openFileDialog } from '../utils/openFileDialog.ts'
import makePica from 'pica' import makePica from 'pica'
import { useTranslations } from '../app/i18n/useTranslations.ts' import { useTranslations } from '../app/i18n/translations.ts'
interface NewPostWidgetProps { interface NewPostWidgetProps {
onSubmit: ( onSubmit: (