diff --git a/src/app/auth/components/AuthNavButtons.tsx b/src/app/auth/components/AuthNavButtons.tsx index f3161f4..c646888 100644 --- a/src/app/auth/components/AuthNavButtons.tsx +++ b/src/app/auth/components/AuthNavButtons.tsx @@ -1,7 +1,7 @@ import { useUser } from '../../user/user.ts' import NavButton from '../../../components/buttons/NavButton.tsx' import { useLocation } from 'react-router-dom' -import { useTranslations } from '../../i18n/useTranslations.ts' +import { useTranslations } from '../../i18n/translations.ts' export default function AuthNavButtons() { const { t } = useTranslations() diff --git a/src/app/auth/pages/LoginPage.tsx b/src/app/auth/pages/LoginPage.tsx index 215d8da..3838a88 100644 --- a/src/app/auth/pages/LoginPage.tsx +++ b/src/app/auth/pages/LoginPage.tsx @@ -8,7 +8,7 @@ import { useUser } from '../../user/user.ts' import NavBar from '../../../components/NavBar.tsx' import NavButton from '../../../components/buttons/NavButton.tsx' import LinkButton from '../../../components/buttons/LinkButton.tsx' -import { useTranslations } from '../../i18n/useTranslations.ts' +import { useTranslations } from '../../i18n/translations.ts' interface LoginPageProps { authService: AuthService diff --git a/src/app/auth/pages/SignupPage.tsx b/src/app/auth/pages/SignupPage.tsx index ec3adba..2e3a200 100644 --- a/src/app/auth/pages/SignupPage.tsx +++ b/src/app/auth/pages/SignupPage.tsx @@ -8,7 +8,7 @@ import { AuthService } from '../authService.ts' import LinkButton from '../../../components/buttons/LinkButton.tsx' import NavBar from '../../../components/NavBar.tsx' import NavButton from '../../../components/buttons/NavButton.tsx' -import { useTranslations } from '../../i18n/useTranslations.ts' +import { useTranslations } from '../../i18n/translations.ts' const SignupCodeKey = 'signupCode' diff --git a/src/app/i18n/translationKeys.ts b/src/app/i18n/translationKeys.ts deleted file mode 100644 index de1c52a..0000000 --- a/src/app/i18n/translationKeys.ts +++ /dev/null @@ -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 diff --git a/src/app/i18n/translations.ts b/src/app/i18n/translations.ts new file mode 100644 index 0000000..519fc55 --- /dev/null +++ b/src/app/i18n/translations.ts @@ -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: (key: K) => Translation[K] +} + +export function useTranslations(): UseTranslations { + // TODO somehow handle other languages (reactively) + const texts = en as Translation + + function getText(key: K): Translation[K] { + return texts[key] ?? key + } + + return { t: getText } +} diff --git a/src/app/i18n/en.json b/src/app/i18n/translations/en.json similarity index 100% rename from src/app/i18n/en.json rename to src/app/i18n/translations/en.json diff --git a/src/app/i18n/useTranslations.ts b/src/app/i18n/useTranslations.ts deleted file mode 100644 index c403be1..0000000 --- a/src/app/i18n/useTranslations.ts +++ /dev/null @@ -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(key: K): Translations[K] { - return texts[key] ?? key - } - - return { t: getText } -} diff --git a/src/components/NewPostWidget.tsx b/src/components/NewPostWidget.tsx index d7b4828..c943577 100644 --- a/src/components/NewPostWidget.tsx +++ b/src/components/NewPostWidget.tsx @@ -3,7 +3,7 @@ import FancyTextEditor, { TextInputKeyDownEvent } from './inputs/FancyTextEditor import Button from './buttons/Button.tsx' import { openFileDialog } from '../utils/openFileDialog.ts' import makePica from 'pica' -import { useTranslations } from '../app/i18n/useTranslations.ts' +import { useTranslations } from '../app/i18n/translations.ts' interface NewPostWidgetProps { onSubmit: (