1
Fork 0
mirror of https://github.com/Steffo99/todocolors.git synced 2024-11-22 16:24:19 +00:00

Rename useTranslation to useServerTranslation and useClientTranslation for easier autocompletion

This commit is contained in:
Steffo 2023-08-08 16:30:02 +02:00
parent 002473bf1a
commit 53478aaf27
Signed by: steffo
GPG key ID: 2A24051445686895
9 changed files with 16 additions and 16 deletions

View file

@ -20,7 +20,7 @@ async function init(lng: string, ns: string): Promise<i18n> {
return instance return instance
} }
export function useTranslation(lng: string, ns: string) { export function useClientTranslation(lng: string, ns: string) {
const [instance, setInstance] = useState<i18n | undefined>(undefined); const [instance, setInstance] = useState<i18n | undefined>(undefined);
useEffect( useEffect(

View file

@ -18,7 +18,7 @@ async function init(lng: string, ns: string): Promise<i18n> {
return instance return instance
} }
export async function useTranslation(lng: string, ns: string) { export async function useServerTranslation(lng: string, ns: string) {
const instance = await init(lng, ns) const instance = await init(lng, ns)
return { return {
t: instance.getFixedT(lng, Array.isArray(ns) ? ns[0] : ns), t: instance.getFixedT(lng, Array.isArray(ns) ? ns[0] : ns),

View file

@ -1,11 +1,11 @@
import {useTranslation} from "@/app/(i18n)/server" import {useServerTranslation} from "@/app/(i18n)/server"
import {CreatePrivateBoardPanel} from "@/app/[lang]/(page)/CreatePrivateBoardPanel" import {CreatePrivateBoardPanel} from "@/app/[lang]/(page)/CreatePrivateBoardPanel"
import {CreatePublicBoardPanel} from "@/app/[lang]/(page)/CreatePublicBoardPanel" import {CreatePublicBoardPanel} from "@/app/[lang]/(page)/CreatePublicBoardPanel"
import {default as React} from "react" import {default as React} from "react"
export async function CreateBoardChapter({lng}: {lng: string}) { export async function CreateBoardChapter({lng}: {lng: string}) {
const {t} = await useTranslation(lng, "root") const {t} = await useServerTranslation(lng, "root")
return ( return (
<div className={"chapter-2"}> <div className={"chapter-2"}>

View file

@ -1,6 +1,6 @@
"use client"; "use client";
import {useTranslation} from "@/app/(i18n)/client" import {useClientTranslation} from "@/app/(i18n)/client"
import {faLock} from "@fortawesome/free-solid-svg-icons" import {faLock} from "@fortawesome/free-solid-svg-icons"
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome" import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
import classNames from "classnames" import classNames from "classnames"
@ -8,7 +8,7 @@ import {useRouter} from "next/navigation"
import {default as React, SyntheticEvent, useCallback, useEffect, useState} from "react" import {default as React, SyntheticEvent, useCallback, useEffect, useState} from "react"
export function CreatePrivateBoardPanel({lng}: {lng: string}) { export function CreatePrivateBoardPanel({lng}: {lng: string}) {
const {t} = useTranslation(lng, "root") const {t} = useClientTranslation(lng, "root")
const router = useRouter(); const router = useRouter();
const [canCreate, setCanCreate] = useState<boolean | null>(null); const [canCreate, setCanCreate] = useState<boolean | null>(null);

View file

@ -1,6 +1,6 @@
"use client"; "use client";
import {useTranslation} from "@/app/(i18n)/client" import {useClientTranslation} from "@/app/(i18n)/client"
import {useLowerKebabState} from "@/app/[lang]/useKebabState" import {useLowerKebabState} from "@/app/[lang]/useKebabState"
import {faGlobe} from "@fortawesome/free-solid-svg-icons" import {faGlobe} from "@fortawesome/free-solid-svg-icons"
import cn from "classnames" import cn from "classnames"
@ -10,7 +10,7 @@ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
export function CreatePublicBoardPanel({lng}: {lng: string}) { export function CreatePublicBoardPanel({lng}: {lng: string}) {
const {t} = useTranslation(lng, "root") const {t} = useClientTranslation(lng, "root")
const [code, setCode] = useLowerKebabState("") const [code, setCode] = useLowerKebabState("")
const router = useRouter(); const router = useRouter();

View file

@ -1,11 +1,11 @@
import {useTranslation} from "@/app/(i18n)/server" import {useServerTranslation} from "@/app/(i18n)/server"
import {KnownBoardsPanel} from "@/app/[lang]/(page)/KnownBoardsPanel" import {KnownBoardsPanel} from "@/app/[lang]/(page)/KnownBoardsPanel"
import {StarredBoardsPanel} from "@/app/[lang]/(page)/StarredBoardsPanel" import {StarredBoardsPanel} from "@/app/[lang]/(page)/StarredBoardsPanel"
import {default as React} from "react" import {default as React} from "react"
export async function ExistingBoardChapter({lng}: {lng: string}) { export async function ExistingBoardChapter({lng}: {lng: string}) {
const {t} = await useTranslation(lng, "root") const {t} = await useServerTranslation(lng, "root")
return ( return (
<div className={"chapter-2"}> <div className={"chapter-2"}>

View file

@ -1,6 +1,6 @@
"use client"; "use client";
import {useTranslation} from "@/app/(i18n)/client" import {useClientTranslation} from "@/app/(i18n)/client"
import {useLowerKebabState} from "@/app/[lang]/useKebabState" import {useLowerKebabState} from "@/app/[lang]/useKebabState"
import {faKey} from "@fortawesome/free-solid-svg-icons" import {faKey} from "@fortawesome/free-solid-svg-icons"
import cn from "classnames" import cn from "classnames"
@ -10,7 +10,7 @@ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
export function KnownBoardsPanel({lng}: {lng: string}) { export function KnownBoardsPanel({lng}: {lng: string}) {
const {t} = useTranslation(lng, "root") const {t} = useClientTranslation(lng, "root")
const [code, setCode] = useLowerKebabState("") const [code, setCode] = useLowerKebabState("")
const router = useRouter(); const router = useRouter();

View file

@ -1,10 +1,10 @@
import {useTranslation} from "@/app/(i18n)/server" import {useServerTranslation} from "@/app/(i18n)/server"
import style from "./RootHeader.module.css" import style from "./RootHeader.module.css"
import {default as React} from "react" import {default as React} from "react"
export async function RootHeader({lng}: {lng: string}) { export async function RootHeader({lng}: {lng: string}) {
const {t} = await useTranslation(lng, "root") const {t} = await useServerTranslation(lng, "root")
return ( return (
<header className={style.pageHeader}> <header className={style.pageHeader}>

View file

@ -1,6 +1,6 @@
"use client"; "use client";
import {useTranslation} from "@/app/(i18n)/client" import {useClientTranslation} from "@/app/(i18n)/client"
import {useManagedStarred} from "@/app/[lang]/StarContext" import {useManagedStarred} from "@/app/[lang]/StarContext"
import {faStar} from "@fortawesome/free-solid-svg-icons" import {faStar} from "@fortawesome/free-solid-svg-icons"
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome" import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
@ -10,7 +10,7 @@ import {useEffect, useState} from "react"
export function StarredBoardsPanel({lng}: {lng: string}) { export function StarredBoardsPanel({lng}: {lng: string}) {
const {t} = useTranslation(lng, "root") const {t} = useClientTranslation(lng, "root")
const [isClient, setIsClient] = useState<true | null>(null); const [isClient, setIsClient] = useState<true | null>(null);
const {starred} = useManagedStarred() const {starred} = useManagedStarred()