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

Rename lng parameter to lang

This commit is contained in:
Steffo 2023-08-09 04:14:05 +02:00
parent 98bcca2fe8
commit e27ace8d13
Signed by: steffo
GPG key ID: 2A24051445686895
12 changed files with 39 additions and 36 deletions

View file

@ -0,0 +1,3 @@
{
"headerToggleEditingTitle": "Toggle editing board settings"
}

View file

@ -5,14 +5,14 @@ import resourcesToBackend from "i18next-resources-to-backend"
import {useEffect, useState} from "react" import {useEffect, useState} from "react"
async function init(lng: string, ns: string): Promise<i18n> { async function init(lang: string, ns: string): Promise<i18n> {
const instance = createInstance() const instance = createInstance()
await instance await instance
.use(resourcesToBackend((language: string, namespace: string) => import(`./(locales)/(${namespace})/${language}.json`))) .use(resourcesToBackend((language: string, namespace: string) => import(`./(locales)/(${namespace})/${language}.json`)))
.init({ .init({
supportedLngs: ["en-US"], supportedLngs: ["en-US"],
fallbackLng: "en-US", fallbackLng: "en-US",
lng, lng: lang,
fallbackNS: "common", fallbackNS: "common",
defaultNS: "common", defaultNS: "common",
ns, ns,
@ -20,22 +20,22 @@ async function init(lng: string, ns: string): Promise<i18n> {
return instance return instance
} }
export function useClientTranslation(lng: string, ns: string) { export function useClientTranslation(lang: string, ns: string) {
const [instance, setInstance] = useState<i18n | undefined>(undefined); const [instance, setInstance] = useState<i18n | undefined>(undefined);
useEffect( useEffect(
() => { () => {
console.debug("[useTranslation] Initializing translation with:", lng, ":", ns) console.debug("[useTranslation] Initializing translation with:", lang, ":", ns)
init(lng, ns).then((v: i18n) => { init(lang, ns).then((v: i18n) => {
console.debug("[useTranslation] Initialized i18n:", v) console.debug("[useTranslation] Initialized i18n:", v)
return setInstance(v) return setInstance(v)
}) })
}, },
[lng, ns] [lang, ns]
) )
return { return {
t: instance?.getFixedT(lng, Array.isArray(ns) ? ns[0] : ns) ?? ((...args) => `${args}`), t: instance?.getFixedT(lang, Array.isArray(ns) ? ns[0] : ns) ?? ((...args) => `${args}`),
i18n: instance, i18n: instance,
} }
} }

View file

@ -3,14 +3,14 @@ import {createInstance, i18n} from "i18next"
import resourcesToBackend from "i18next-resources-to-backend" import resourcesToBackend from "i18next-resources-to-backend"
async function init(lng: string, ns: string): Promise<i18n> { async function init(lang: string, ns: string): Promise<i18n> {
const instance = createInstance() const instance = createInstance()
await instance await instance
.use(resourcesToBackend((language: string, namespace: string) => import(`./(locales)/(${namespace})/${language}.json`))) .use(resourcesToBackend((language: string, namespace: string) => import(`./(locales)/(${namespace})/${language}.json`)))
.init({ .init({
supportedLngs: ["en-US"], supportedLngs: ["en-US"],
fallbackLng: "en-US", fallbackLng: "en-US",
lng, lng: lang,
fallbackNS: "common", fallbackNS: "common",
defaultNS: "common", defaultNS: "common",
ns, ns,
@ -18,10 +18,10 @@ async function init(lng: string, ns: string): Promise<i18n> {
return instance return instance
} }
export async function useServerTranslation(lng: string, ns: string) { export async function useServerTranslation(lang: string, ns: string) {
const instance = await init(lng, ns) const instance = await init(lang, ns)
return { return {
t: instance.getFixedT(lng, Array.isArray(ns) ? ns[0] : ns), t: instance.getFixedT(lang, Array.isArray(ns) ? ns[0] : ns),
i18n: instance i18n: instance
} }
} }

View file

@ -4,16 +4,16 @@ 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({lang}: {lang: string}) {
const {t} = await useServerTranslation(lng, "root") const {t} = await useServerTranslation(lang, "root")
return ( return (
<div className={"chapter-2"}> <div className={"chapter-2"}>
<h2> <h2>
{t("createBoardTitle")} {t("createBoardTitle")}
</h2> </h2>
<CreatePublicBoardPanel lng={lng}/> <CreatePublicBoardPanel lang={lang}/>
<CreatePrivateBoardPanel lng={lng}/> <CreatePrivateBoardPanel lang={lang}/>
</div> </div>
) )
} }

View file

@ -7,8 +7,8 @@ import classNames from "classnames"
import {useRouter} from "next/navigation" 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({lang}: {lang: string}) {
const {t} = useClientTranslation(lng, "root") const {t} = useClientTranslation(lang, "root")
const router = useRouter(); const router = useRouter();
const [canCreate, setCanCreate] = useState<boolean | null>(null); const [canCreate, setCanCreate] = useState<boolean | null>(null);

View file

@ -9,8 +9,8 @@ import {default as React, SyntheticEvent, useCallback} from "react"
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome" import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
export function CreatePublicBoardPanel({lng}: {lng: string}) { export function CreatePublicBoardPanel({lang}: {lang: string}) {
const {t} = useClientTranslation(lng, "root") const {t} = useClientTranslation(lang, "root")
const [code, setCode] = useLowerKebabState("") const [code, setCode] = useLowerKebabState("")
const router = useRouter(); const router = useRouter();

View file

@ -4,16 +4,16 @@ 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({lang}: {lang: string}) {
const {t} = await useServerTranslation(lng, "root") const {t} = await useServerTranslation(lang, "root")
return ( return (
<div className={"chapter-2"}> <div className={"chapter-2"}>
<h2> <h2>
{t("existingBoardTitle")} {t("existingBoardTitle")}
</h2> </h2>
<KnownBoardsPanel lng={lng}/> <KnownBoardsPanel lang={lang}/>
<StarredBoardsPanel lng={lng}/> <StarredBoardsPanel lang={lang}/>
</div> </div>
) )
} }

View file

@ -9,8 +9,8 @@ import {default as React, SyntheticEvent, useCallback} from "react"
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome" import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
export function KnownBoardsPanel({lng}: {lng: string}) { export function KnownBoardsPanel({lang}: {lang: string}) {
const {t} = useClientTranslation(lng, "root") const {t} = useClientTranslation(lang, "root")
const [code, setCode] = useLowerKebabState("") const [code, setCode] = useLowerKebabState("")
const router = useRouter(); const router = useRouter();

View file

@ -3,8 +3,8 @@ 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({lang}: {lang: string}) {
const {t} = await useServerTranslation(lng, "root") const {t} = await useServerTranslation(lang, "root")
return ( return (
<header className={style.pageHeader}> <header className={style.pageHeader}>

View file

@ -4,11 +4,11 @@ import style from "./RootMain.module.css"
import {default as React} from "react" import {default as React} from "react"
export async function RootMain({lng}: {lng: string}) { export async function RootMain({lang}: {lang: string}) {
return ( return (
<main className={style.rootMain}> <main className={style.rootMain}>
<CreateBoardChapter lng={lng}/> <CreateBoardChapter lang={lang}/>
<ExistingBoardChapter lng={lng}/> <ExistingBoardChapter lang={lang}/>
</main> </main>
) )
} }

View file

@ -9,8 +9,8 @@ import Link from "next/link"
import {useEffect, useState} from "react" import {useEffect, useState} from "react"
export function StarredBoardsPanel({lng}: {lng: string}) { export function StarredBoardsPanel({lang}: {lang: string}) {
const {t} = useClientTranslation(lng, "root") const {t} = useClientTranslation(lang, "root")
const [isClient, setIsClient] = useState<true | null>(null); const [isClient, setIsClient] = useState<true | null>(null);
const {starred} = useStarredConsumer() const {starred} = useStarredConsumer()

View file

@ -5,11 +5,11 @@ import {default as React} from "react";
import style from "./page.module.css" import style from "./page.module.css"
export default async function page({params: {lng}}: {params: {lng: string}}) { export default async function page({params: {lang}}: {params: {lang: string}}) {
return ( return (
<div className={style.pageRoot}> <div className={style.pageRoot}>
<RootHeader lng={lng}/> <RootHeader lang={lang}/>
<RootMain lng={lng}/> <RootMain lang={lang}/>
<RootFooter/> <RootFooter/>
</div> </div>
) )