1
Fork 0
mirror of https://github.com/Steffo99/todocolors.git synced 2024-11-22 00:04:18 +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"
async function init(lng: string, ns: string): Promise<i18n> {
async function init(lang: string, ns: string): Promise<i18n> {
const instance = createInstance()
await instance
.use(resourcesToBackend((language: string, namespace: string) => import(`./(locales)/(${namespace})/${language}.json`)))
.init({
supportedLngs: ["en-US"],
fallbackLng: "en-US",
lng,
lng: lang,
fallbackNS: "common",
defaultNS: "common",
ns,
@ -20,22 +20,22 @@ async function init(lng: string, ns: string): Promise<i18n> {
return instance
}
export function useClientTranslation(lng: string, ns: string) {
export function useClientTranslation(lang: string, ns: string) {
const [instance, setInstance] = useState<i18n | undefined>(undefined);
useEffect(
() => {
console.debug("[useTranslation] Initializing translation with:", lng, ":", ns)
init(lng, ns).then((v: i18n) => {
console.debug("[useTranslation] Initializing translation with:", lang, ":", ns)
init(lang, ns).then((v: i18n) => {
console.debug("[useTranslation] Initialized i18n:", v)
return setInstance(v)
})
},
[lng, ns]
[lang, ns]
)
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,
}
}

View file

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

View file

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

View file

@ -7,8 +7,8 @@ import classNames from "classnames"
import {useRouter} from "next/navigation"
import {default as React, SyntheticEvent, useCallback, useEffect, useState} from "react"
export function CreatePrivateBoardPanel({lng}: {lng: string}) {
const {t} = useClientTranslation(lng, "root")
export function CreatePrivateBoardPanel({lang}: {lang: string}) {
const {t} = useClientTranslation(lang, "root")
const router = useRouter();
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"
export function CreatePublicBoardPanel({lng}: {lng: string}) {
const {t} = useClientTranslation(lng, "root")
export function CreatePublicBoardPanel({lang}: {lang: string}) {
const {t} = useClientTranslation(lang, "root")
const [code, setCode] = useLowerKebabState("")
const router = useRouter();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,11 +5,11 @@ import {default as React} from "react";
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 (
<div className={style.pageRoot}>
<RootHeader lng={lng}/>
<RootMain lng={lng}/>
<RootHeader lang={lang}/>
<RootMain lang={lang}/>
<RootFooter/>
</div>
)