fix: i18n in app router (#496)

This commit is contained in:
enpitsulin
2023-05-06 17:47:00 +01:00
committed by GitHub
parent 62d201f088
commit 091c11847b
12 changed files with 274 additions and 244 deletions
+8 -11
View File
@@ -1,12 +1,18 @@
"use client"
import { useRouter } from "next/navigation"
import React from "react"
import { useAccountState } from "@crossbell/connect-kit"
import { Button } from "~/components/ui/Button"
export default function EntranceButton() {
interface Props {
connectedContent: React.ReactNode
unconnectedContent: React.ReactNode
}
export default function EntranceButton(props: Props) {
const router = useRouter()
const isConnected = useAccountState((s) => !!s.computed.account)
@@ -17,16 +23,7 @@ export default function EntranceButton() {
size="2xl"
variantColor="black"
>
{isConnected ? (
<>
<span className="icon-[mingcute--grid-line] text-xl mr-2 inline-block"></span>
{/* <span>{t("Dashboard")}</span> */}
Dashboard
</>
) : (
// t("Get my xLog in 5 minutes")
<>Get my xLog in 5 minutes</>
)}
{isConnected ? props.connectedContent : props.unconnectedContent}
</Button>
)
}
+9 -8
View File
@@ -1,13 +1,10 @@
"use client"
import { usePathname } from "next/navigation"
import { useTranslation } from "react-i18next"
import { ConnectButton } from "~/components/common/ConnectButton"
import { Logo } from "~/components/common/Logo"
import { Image } from "~/components/ui/Image"
import { UniLink } from "~/components/ui/UniLink"
import { useAcceptLang } from "~/hooks/useAcceptLang"
import { GITHUB_LINK } from "~/lib/env"
import { useTranslation } from "~/lib/i18n"
import { cn } from "~/lib/utils"
const tabs = [
@@ -31,9 +28,13 @@ const tabs = [
},
]
export function Header() {
const { t } = useTranslation("index")
const pathname = usePathname()
export async function Header() {
const lang = useAcceptLang()
const { t } = await useTranslation(lang, "index")
// const pathname = usePathname()
// TODO how to set active state for Link in RSC,
// make <UniLink> be client component and add activeClass props or some way else
const pathname = "/"
return (
<header className="py-5 fixed w-full top-0 bg-white z-10">
<div className="max-w-screen-lg px-5 mx-auto flex justify-between items-center">
+142
View File
@@ -0,0 +1,142 @@
"use client"
import {
CrossbellChainLogo,
XCharLogo,
XFeedLogo,
XShopLogo,
XSyncLogo,
} from "@crossbell/ui"
import { RssIcon } from "@heroicons/react/24/outline"
import { Image } from "~/components/ui/Image"
import { Tooltip } from "~/components/ui/Tooltip"
import { UniLink } from "~/components/ui/UniLink"
import { getSiteLink } from "~/lib/helpers"
export function Integration() {
const integrations = [
{
name: "RSS",
icon: <RssIcon className="w-full h-full text-orange-500" />,
url:
getSiteLink({
subdomain: "xlog",
}) + "/feed?format=xml",
},
{
name: "JSON Feed",
icon: <Image src="/assets/json-feed.png" alt="JSON Feed" />,
url:
getSiteLink({
subdomain: "xlog",
}) + "/feed",
},
{
name: "xChar",
icon: <XCharLogo className="w-full h-full" />,
url: "https://xchar.app/",
},
{
name: "xFeed",
icon: <XFeedLogo className="w-full h-full" />,
url: "https://crossbell.io/feed",
},
{
name: "xSync",
icon: <XSyncLogo className="w-full h-full" />,
url: "https://xsync.app/",
},
{
name: "xShop",
icon: <XShopLogo className="w-full h-full" />,
text: "Coming soon",
},
{
name: "Crossbell Scan",
icon: <CrossbellChainLogo className="w-full h-full text-[#E7B75B]" />,
url: "https://scan.crossbell.io/",
},
{
name: "Crossbell Faucet",
icon: <CrossbellChainLogo className="w-full h-full text-[#E7B75B]" />,
url: "https://faucet.crossbell.io/",
},
{
name: "Crossbell Export",
icon: <CrossbellChainLogo className="w-full h-full text-[#E7B75B]" />,
url: "https://export.crossbell.io/",
},
{
name: "Crossbell SDK",
icon: <CrossbellChainLogo className="w-full h-full text-[#E7B75B]" />,
url: "https://crossbell-box.github.io/crossbell.js/",
},
{
name: "RSS3",
icon: (
<Image alt="RSS3" src="/assets/rss3.svg" className="rounded" fill />
),
url: "https://rss3.io/",
},
{
name: "Hoot It",
icon: (
<Image alt="Hoot It" src="/assets/hoot.svg" className="rounded" fill />
),
url: "https://hoot.it/search/xLog",
},
{
name: "Raycast",
icon: <Image src="/assets/raycast.png" alt="Raycast" />,
url: "https://www.raycast.com/Songkeys/crossbell",
},
{
name: "Obsidian",
icon: (
<Image
src="/assets/obsidian.svg"
alt="Obsidian"
className="rounded"
fill
/>
),
text: "Coming soon",
},
]
return (
<>
{integrations.map((item, index) => (
<li
className="hover:scale-105 transition-transform duration-300"
key={index}
>
{item.url ? (
<UniLink
href={item.url}
className="w-full flex items-center flex-col justify-center"
>
<div className="w-12 h-12 rounded-md overflow-hidden">
{item.icon}
</div>
<div className="font-medium sm:text-lg mt-2 text-center">
{item.name}
</div>
</UniLink>
) : (
<Tooltip label={item.text!}>
<div className="w-full h-full flex items-center flex-col justify-center">
<div className="w-12 h-12 rounded-md overflow-hidden">
{item.icon}
</div>
<div className="font-medium sm:text-lg mt-2 text-center">
{item.name}
</div>
</div>
</Tooltip>
)}
</li>
))}
</>
)
}
+24
View File
@@ -0,0 +1,24 @@
"use client"
import { FollowAllButton } from "~/components/common/FollowAllButton"
import { useGetShowcase } from "~/queries/home"
import ShowcaseList from "./ShowcaseList"
export function ShowCase() {
const showcaseSites = useGetShowcase()
return (
<>
<FollowAllButton
className="mt-5"
size="xl"
characterIds={showcaseSites.data
?.map((s: { characterId?: string }) => s.characterId)
.filter(Boolean)
.map(Number)}
siteIds={showcaseSites.data?.map((s: { handle: string }) => s.handle)}
/>
<ShowcaseList sites={showcaseSites.data} />
</>
)
}
+1
View File
@@ -12,6 +12,7 @@ export default async function HomeLayout({
}) {
return (
<>
{/* @ts-expect-error RSC */}
<Header />
{children}
<footer className="mt-10 font-medium border-t">
+65 -212
View File
@@ -1,39 +1,36 @@
"use client"
import Link from "next/link"
import { memo } from "react"
import { Trans } from "react-i18next/TransWithoutContext"
import { Trans, useTranslation } from "next-i18next"
import { useRouter } from "next/navigation"
import { Element, Link } from "react-scroll"
import {
CrossbellChainLogo,
XCharLogo,
XFeedLogo,
XShopLogo,
XSyncLogo,
} from "@crossbell/ui"
import { RssIcon } from "@heroicons/react/24/outline"
import { FollowAllButton } from "~/components/common/FollowAllButton"
import { Logo } from "~/components/common/Logo"
import { Button } from "~/components/ui/Button"
import { Image } from "~/components/ui/Image"
import { Tooltip } from "~/components/ui/Tooltip"
import { UniLink } from "~/components/ui/UniLink"
import { useAcceptLang } from "~/hooks/useAcceptLang"
import { CSB_SCAN, GITHUB_LINK } from "~/lib/env"
import { getSiteLink } from "~/lib/helpers"
import { useGetShowcase } from "~/queries/home"
import { useTranslation } from "~/lib/i18n"
import ShowcaseList from "./ShowcaseList"
import EntranceButton from "./components/EntranceButton"
import { default as OriginEntranceButton } from "./components/EntranceButton"
import { Integration } from "./components/Integrations"
import { ShowCase } from "./components/Showcase"
function Home() {
const router = useRouter()
const showcaseSites = useGetShowcase()
const { t } = useTranslation("index")
async function Home() {
const lang = useAcceptLang()
const { t, i18n } = await useTranslation(lang, "index")
const tryNow = () => {
router.push("/dashboard")
}
const EntranceButton = memo(function Button() {
return (
<OriginEntranceButton
connectedContent={
<>
<span className="icon-[mingcute--grid-line] text-xl mr-2 inline-block"></span>
<span>{t("Dashboard")}</span>
</>
}
unconnectedContent={t("Get my xLog in 5 minutes")}
/>
)
})
const features: {
title: string
@@ -114,96 +111,6 @@ function Home() {
},
]
const integrations = [
{
name: "RSS",
icon: <RssIcon className="w-full h-full text-orange-500" />,
url:
getSiteLink({
subdomain: "xlog",
}) + "/feed?format=xml",
},
{
name: "JSON Feed",
icon: <Image src="/assets/json-feed.png" alt="JSON Feed" />,
url:
getSiteLink({
subdomain: "xlog",
}) + "/feed",
},
{
name: "xChar",
icon: <XCharLogo className="w-full h-full" />,
url: "https://xchar.app/",
},
{
name: "xFeed",
icon: <XFeedLogo className="w-full h-full" />,
url: "https://crossbell.io/feed",
},
{
name: "xSync",
icon: <XSyncLogo className="w-full h-full" />,
url: "https://xsync.app/",
},
{
name: "xShop",
icon: <XShopLogo className="w-full h-full" />,
text: "Coming soon",
},
{
name: "Crossbell Scan",
icon: <CrossbellChainLogo className="w-full h-full text-[#E7B75B]" />,
url: "https://scan.crossbell.io/",
},
{
name: "Crossbell Faucet",
icon: <CrossbellChainLogo className="w-full h-full text-[#E7B75B]" />,
url: "https://faucet.crossbell.io/",
},
{
name: "Crossbell Export",
icon: <CrossbellChainLogo className="w-full h-full text-[#E7B75B]" />,
url: "https://export.crossbell.io/",
},
{
name: "Crossbell SDK",
icon: <CrossbellChainLogo className="w-full h-full text-[#E7B75B]" />,
url: "https://crossbell-box.github.io/crossbell.js/",
},
{
name: "RSS3",
icon: (
<Image alt="RSS3" src="/assets/rss3.svg" className="rounded" fill />
),
url: "https://rss3.io/",
},
{
name: "Hoot It",
icon: (
<Image alt="Hoot It" src="/assets/hoot.svg" className="rounded" fill />
),
url: "https://hoot.it/search/xLog",
},
{
name: "Raycast",
icon: <Image src="/assets/raycast.png" alt="Raycast" />,
url: "https://www.raycast.com/Songkeys/crossbell",
},
{
name: "Obsidian",
icon: (
<Image
src="/assets/obsidian.svg"
alt="Obsidian"
className="rounded"
fill
/>
),
text: "Coming soon",
},
]
return (
<div className="max-w-screen-lg px-5 mx-auto">
<div className="h-screen w-full flex justify-center flex-col relative text-center">
@@ -219,21 +126,25 @@ function Home() {
))}
</h2>
<h3 className="mt-3 sm:mt-5 text-zinc-800 text-2xl sm:text-4xl font-light">
<Trans i18nKey="description" ns="index">
<Trans i18n={i18n} i18nKey="description" ns="index">
<strong className="font-medium">xLog</strong> is the best{" "}
<UniLink
<a
target="_blank"
rel="nofollow noreferrer"
className="underline decoration-2 text-yellow-400 font-medium"
href={CSB_SCAN}
>
on-chain
</UniLink>{" "}
</a>{" "}
and{" "}
<UniLink
<a
target="_blank"
rel="nofollow noreferrer"
className="underline decoration-2 text-green-400 font-medium"
href={GITHUB_LINK}
>
open-source
</UniLink>{" "}
</a>{" "}
blogging community for everyone.
</Trans>
</h3>
@@ -246,25 +157,20 @@ function Home() {
variantColor="gradient"
>
<span>
<UniLink href="/activities">{t("Look at others'")}</UniLink>
<Link href="/activities">{t("Look at others'")}</Link>
</span>
</Button>
</div>
<div className="text-center absolute bottom-4 sm:bottom-14 w-full flex items-center justify-center flex-col">
<span className="mb-1 sm:mb-3">{t("Explore the xLog way")}</span>
{/* @ts-expect-error: TODO fix or replace this lib */}
<Link
to="Features"
spy={true}
smooth={true}
duration={500}
<a
href="#features"
className="cursor-pointer inline-block icon-[mingcute--down-line] text-3xl"
></Link>
></a>
</div>
</div>
<div>
{/* @ts-expect-error: TODO fix or replace this lib */}
<Element name="Features">
<div id="features">
{features.map((feature, index) => (
<div className="text-center mt-28" key={feature.title}>
<div className="">
@@ -291,15 +197,18 @@ function Home() {
</h4>
<p className="mt-6 text-zinc-500">
<Trans
i18n={i18n}
i18nKey={`features.${feature.title}.description`}
components={{
aown: (
<UniLink
<a
target="_blank"
rel="nofollow noreferrer"
className="underline"
href="https://github.com/Crossbell-Box/Crossbell-Contracts/wiki"
>
.
</UniLink>
</a>
),
}}
ns="index"
@@ -332,28 +241,33 @@ function Home() {
</p>
<p className="text-base font-light mt-3 mb-4 leading-normal px-5 text-left">
<Trans
i18n={i18n}
i18nKey={`${item.title} text`}
components={{
strong: <strong className="font-bold" />,
axfm: (
<UniLink
<a
target="_blank"
rel="nofollow noreferrer"
className="underline"
href={`${getSiteLink({
subdomain: "xlog",
})}/xfm`}
>
.
</UniLink>
</a>
),
aincentive: (
<UniLink
<a
target="_blank"
rel="nofollow noreferrer"
className="underline"
href={`${getSiteLink({
subdomain: "xlog",
})}/creator-incentive-plan`}
>
.
</UniLink>
</a>
),
}}
ns="index"
@@ -373,25 +287,20 @@ function Home() {
</span>
</div>
<div>{t(`features.${feature.title}.extra.description`)}</div>
<Button
variantColor="black"
onClick={() =>
window.open(
getSiteLink({
subdomain: "xlog",
}),
)
}
<a
target="_blank"
href={getSiteLink({ subdomain: "xlog" })}
role="button"
className="button is-black rounded-lg"
>
{t(`features.${feature.title}.extra.button`)}
</Button>
</a>
</div>
)}
</div>
))}
</Element>
{/* @ts-expect-error: TODO fix or replace this lib */}
<Element name="Showcase" className="text-center">
</div>
<div id="showcase" className="text-center">
<div className="pt-32 text-5xl sm:text-6xl font-bold">
{t("Showcase")}
</div>
@@ -401,22 +310,10 @@ function Home() {
"Discover these awesome teams and creators on xLog (sorted by update time)",
)}
</p>
<FollowAllButton
className="mt-5"
size="xl"
characterIds={showcaseSites.data
?.map((s: { characterId?: string }) => s.characterId)
.filter(Boolean)
.map(Number)}
siteIds={showcaseSites.data?.map(
(s: { handle: string }) => s.handle,
)}
/>
<ShowcaseList sites={showcaseSites.data} />
<ShowCase />
</div>
</Element>
{/* @ts-expect-error: TODO fix or replace this lib */}
<Element name="Integration" className="text-center">
</div>
<div id="integration" className="text-center">
<div className="pt-32 text-5xl sm:text-6xl font-bold">
{t("Integration")}
</div>
@@ -427,62 +324,18 @@ function Home() {
)}
</p>
<ul className="mt-14 grid grid-cols-3 sm:grid-cols-5 gap-y-14 gap-x-2">
{integrations.map((item, index) => (
<li
className="hover:scale-105 transition-transform duration-300"
key={index}
>
{item.url ? (
<UniLink
href={item.url}
className="w-full flex items-center flex-col justify-center"
>
<div className="w-12 h-12 rounded-md overflow-hidden">
{item.icon}
</div>
<div className="font-medium sm:text-lg mt-2 text-center">
{item.name}
</div>
</UniLink>
) : (
<Tooltip label={item.text!}>
<div className="w-full h-full flex items-center flex-col justify-center">
<div className="w-12 h-12 rounded-md overflow-hidden">
{item.icon}
</div>
<div className="font-medium sm:text-lg mt-2 text-center">
{item.name}
</div>
</div>
</Tooltip>
)}
</li>
))}
<Integration />
<li className="flex items-center justify-center">
<i className="icon-[mingcute--more-1-line] text-5xl" />
</li>
</ul>
</div>
</Element>
</div>
</div>
<div className="my-20 text-center">
<div className="w-[100px] h-[100px] mx-auto mb-10">
<Logo type="lottie" width={100} height={100} loop={true} />
</div>
{/* {isConnected ? (
<UniLink
href="/dashboard"
className="text-accent inline-flex items-center space-x-2"
>
<Button size="2xl" variantColor="black">
{t("Get my xLog in 5 minutes")}
</Button>
</UniLink>
) : (
<Button onClick={tryNow} size="2xl" variantColor="black">
{t("Get my xLog in 5 minutes")}
</Button>
)} */}
<EntranceButton />
</div>
</div>
+2 -13
View File
@@ -1,10 +1,9 @@
import { dir } from "i18next"
import { Metadata } from "next"
import { headers } from "next/headers"
import "~/css/main.css"
import { useAcceptLang } from "~/hooks/useAcceptLang"
import { APP_DESCRIPTION, APP_NAME, SITE_URL } from "~/lib/env"
import { fallbackLng } from "~/lib/i18n/settings"
import Providers from "./providers"
@@ -28,17 +27,7 @@ export default function RootLayout({
}: {
children: React.ReactNode
}) {
let lng = fallbackLng
let acceptLang = headers().get("accept-language")?.split(",")[0]
if (acceptLang === "zh-HK" || acceptLang === "zh-TW") {
acceptLang = "zh-TW"
} else {
acceptLang = acceptLang?.split("-")[0]
}
if (acceptLang) {
lng = acceptLang
}
const lng = useAcceptLang()
return (
<html lang={lng} dir={dir(lng)}>
@@ -1,3 +1,5 @@
"use client"
import { useTranslation } from "next-i18next"
import { useState } from "react"
+2
View File
@@ -1,3 +1,5 @@
"use client"
import { useState } from "react"
import {
+19
View File
@@ -0,0 +1,19 @@
import { headers } from "next/headers"
import { fallbackLng } from "~/lib/i18n/settings"
export function useAcceptLang() {
let lng = fallbackLng
let acceptLang = headers().get("accept-language")?.split(",")[0]
if (acceptLang === "zh-HK" || acceptLang === "zh-TW") {
acceptLang = "zh-TW"
} else {
acceptLang = acceptLang?.split("-")[0]
}
if (acceptLang) {
lng = acceptLang
}
return lng
}