@@ -51,14 +54,14 @@ export function MainLayout({
duration={500}
key={tab}
>
- {tab}
+ {t(tab)}
))}
- Source Code
+ {t("Source Code")}
diff --git a/src/components/site/PostMeta.tsx b/src/components/site/PostMeta.tsx
index 08dffd4c..a091060f 100644
--- a/src/components/site/PostMeta.tsx
+++ b/src/components/site/PostMeta.tsx
@@ -1,4 +1,4 @@
-import { formatDate, formatToISO } from "~/lib/date"
+import { formatToISO } from "~/lib/date"
import { BlockchainIcon } from "~/components/icons/BlockchainIcon"
import { UniLink } from "~/components/ui/UniLink"
import { Note, Profile } from "~/lib/types"
@@ -9,17 +9,14 @@ import { getSiteLink } from "~/lib/helpers"
import { Avatar } from "~/components/ui/Avatar"
import { EyeIcon, PencilSquareIcon } from "@heroicons/react/24/outline"
import { useUserRole } from "~/hooks/useUserRole"
+import { useTranslation } from "next-i18next"
export const PostMeta: React.FC<{
page: Note
site?: Profile | null
author?: Profile | null
}> = ({ page, site, author }) => {
- const [isMounted, setIsMounted] = useState(false)
-
- useEffect(() => {
- setIsMounted(true)
- }, [])
+ const { t } = useTranslation("common")
const [showEdit, setShowEdit] = useState(false)
const userRole = useUserRole(site?.username)
@@ -35,11 +32,16 @@ export const PostMeta: React.FC<{
dateTime={formatToISO(page.date_published)}
className="xlog-post-date whitespace-nowrap"
>
- {formatDate(
- page.date_published,
- undefined,
- isMounted ? undefined : "America/Los_Angeles",
- )}
+ {t("intlDateTime", {
+ val: new Date(page.date_published),
+ formatParams: {
+ val: {
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ },
+ },
+ })}
{page.tags?.filter((tag) => tag !== "post" && tag !== "page").length ? (
<>
diff --git a/src/components/site/SiteHeader.tsx b/src/components/site/SiteHeader.tsx
index bd89f6ef..a4917695 100644
--- a/src/components/site/SiteHeader.tsx
+++ b/src/components/site/SiteHeader.tsx
@@ -18,10 +18,11 @@ import { FastAverageColor } from "fast-average-color"
import { useState, useRef, useEffect, RefObject } from "react"
import chroma from "chroma-js"
import { Menu } from "~/components/ui/Menu"
+import { useTranslation } from "next-i18next"
-export type HeaderLinkType = {
+type HeaderLinkType = {
icon?: React.ReactNode
- label: string | JSX.Element
+ label: string
url?: string
onClick?: () => void
}
@@ -30,6 +31,7 @@ const fac = new FastAverageColor()
const HeaderLink: React.FC<{ link: HeaderLinkType }> = ({ link }) => {
const router = useRouter()
+ const { t } = useTranslation("site")
const active = router.asPath === link.url
return (
= ({ link }) => {
)}
>
{link.icon && {link.icon}}
- {link.label}
+ {t(link.label)}
)
}
diff --git a/src/components/site/SiteHome.tsx b/src/components/site/SiteHome.tsx
index 80a5fa3f..1e9c06ae 100644
--- a/src/components/site/SiteHome.tsx
+++ b/src/components/site/SiteHome.tsx
@@ -1,12 +1,12 @@
import Link from "next/link"
-import { formatDate, formatToISO } from "~/lib/date"
+import { formatToISO } from "~/lib/date"
import { Notes } from "~/lib/types"
import { EmptyState } from "../ui/EmptyState"
import { useRouter } from "next/router"
import { Image } from "~/components/ui/Image"
import { Button } from "~/components/ui/Button"
-import { useEffect, useState } from "react"
import { EyeIcon } from "@heroicons/react/24/outline"
+import { useTranslation } from "next-i18next"
export const SiteHome: React.FC<{
postPages?: Notes[]
@@ -15,12 +15,8 @@ export const SiteHome: React.FC<{
isFetchingNextPage?: boolean
}> = ({ postPages, fetchNextPage, hasNextPage, isFetchingNextPage }) => {
const router = useRouter()
-
- const [isMounted, setIsMounted] = useState(false)
-
- useEffect(() => {
- setIsMounted(true)
- }, [])
+ const { t } = useTranslation("common")
+ const { t: siteT } = useTranslation("site")
if (!postPages?.length) return null
@@ -49,11 +45,16 @@ export const SiteHome: React.FC<{
dateTime={formatToISO(post.date_published)}
className="xlog-post-date whitespace-nowrap"
>
- {formatDate(
- post.date_published,
- undefined,
- isMounted ? undefined : "America/Los_Angeles",
- )}
+ {t("intlDateTime", {
+ val: new Date(post.date_published),
+ formatParams: {
+ val: {
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ },
+ },
+ })}
{!!post.tags?.filter(
(tag) => tag !== "post" && tag !== "page",
@@ -114,9 +115,12 @@ export const SiteHome: React.FC<{
isLoading={isFetchingNextPage}
aria-label="load more"
>
- There are {postPages[0].total - currentLength} more post
- {postPages[0].total - currentLength > 1 ? "s" : ""}, click to load
- more
+ {siteT("load more", {
+ name: t(
+ "post" + (postPages[0].total - currentLength > 1 ? "s" : ""),
+ ),
+ count: postPages[0].total - currentLength,
+ })}
)}
>
diff --git a/src/components/site/SiteLayout.server.tsx b/src/components/site/SiteLayout.server.tsx
index bdc2bcce..012b6904 100644
--- a/src/components/site/SiteLayout.server.tsx
+++ b/src/components/site/SiteLayout.server.tsx
@@ -8,6 +8,8 @@ import { PageVisibilityEnum } from "~/lib/types"
import { dehydrate, QueryClient } from "@tanstack/react-query"
import { fetchGetPage } from "~/queries/page.server"
import { notFound } from "~/lib/server-side-props"
+import { serverSideTranslations } from "next-i18next/serverSideTranslations"
+import { languageDetector } from "~/lib/language-detector"
export const getServerSideProps = async (
ctx: any,
@@ -83,7 +85,11 @@ export const getServerSideProps = async (
return {
props: {
- dehydratedState: dehydrate(queryClient),
+ ...(await serverSideTranslations(languageDetector(ctx), [
+ "common",
+ "site",
+ ])),
+ dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))),
},
}
}
diff --git a/src/lib/language-detector.ts b/src/lib/language-detector.ts
index 90080832..504a8f18 100644
--- a/src/lib/language-detector.ts
+++ b/src/lib/language-detector.ts
@@ -1,5 +1,11 @@
import type { GetServerSidePropsContext } from "next"
+import url from "url"
export const languageDetector = (ctx: GetServerSidePropsContext) => {
- return ctx.req.headers["accept-language"]?.split(",")[0].split("-")[0] || "en"
+ const queryLang = url.parse(ctx.req.url!, true).query.lang as string
+ return (
+ queryLang ||
+ ctx.req.headers["accept-language"]?.split(",")[0].split("-")[0] ||
+ "en"
+ )
}
diff --git a/src/pages/_site/[site]/[page].tsx b/src/pages/_site/[site]/[page].tsx
index 51e263a2..add1397b 100644
--- a/src/pages/_site/[site]/[page].tsx
+++ b/src/pages/_site/[site]/[page].tsx
@@ -3,7 +3,7 @@ import { SiteLayout } from "~/components/site/SiteLayout"
import { getServerSideProps as getLayoutServerSideProps } from "~/components/site/SiteLayout.server"
import { SitePage } from "~/components/site/SitePage"
import { serverSidePropsHandler } from "~/lib/server-side-props"
-import { dehydrate, QueryClient } from "@tanstack/react-query"
+import { QueryClient } from "@tanstack/react-query"
import { useGetPage } from "~/queries/page"
import { useGetSite } from "~/queries/site"
import type { ReactElement } from "react"
@@ -14,13 +14,17 @@ export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
const domainOrSubdomain = ctx.params!.site as string
const pageSlug = ctx.params!.page as string
- await getLayoutServerSideProps(ctx, queryClient, {
- useStat: true,
- })
+ const { props: layoutProps } = await getLayoutServerSideProps(
+ ctx,
+ queryClient,
+ {
+ useStat: true,
+ },
+ )
return {
props: {
- dehydratedState: dehydrate(queryClient),
+ ...layoutProps,
domainOrSubdomain,
pageSlug,
},
diff --git a/src/pages/_site/[site]/archives.tsx b/src/pages/_site/[site]/archives.tsx
index 24767cc0..ef3935ad 100644
--- a/src/pages/_site/[site]/archives.tsx
+++ b/src/pages/_site/[site]/archives.tsx
@@ -4,7 +4,7 @@ import { getServerSideProps as getLayoutServerSideProps } from "~/components/sit
import { serverSidePropsHandler } from "~/lib/server-side-props"
import { SiteArchives } from "~/components/site/SiteArchives"
import { Profile, Notes } from "~/lib/types"
-import { dehydrate, QueryClient } from "@tanstack/react-query"
+import { QueryClient } from "@tanstack/react-query"
import { useGetPagesBySiteLite } from "~/queries/page"
import { PageVisibilityEnum } from "~/lib/types"
import type { ReactElement } from "react"
@@ -13,13 +13,17 @@ export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
async (ctx) => {
const queryClient = new QueryClient()
const domainOrSubdomain = ctx.params!.site as string
- await getLayoutServerSideProps(ctx, queryClient, {
- take: 100,
- })
+ const { props: layoutProps } = await getLayoutServerSideProps(
+ ctx,
+ queryClient,
+ {
+ take: 100,
+ },
+ )
return {
props: {
- dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))),
+ ...layoutProps,
domainOrSubdomain,
},
}
diff --git a/src/pages/_site/[site]/index.tsx b/src/pages/_site/[site]/index.tsx
index e9edc777..aa872569 100644
--- a/src/pages/_site/[site]/index.tsx
+++ b/src/pages/_site/[site]/index.tsx
@@ -2,7 +2,7 @@ import { GetServerSideProps } from "next"
import { SiteHome } from "~/components/site/SiteHome"
import { SiteLayout } from "~/components/site/SiteLayout"
import { getServerSideProps as getLayoutServerSideProps } from "~/components/site/SiteLayout.server"
-import { dehydrate, QueryClient } from "@tanstack/react-query"
+import { QueryClient } from "@tanstack/react-query"
import { useGetPagesBySiteLite } from "~/queries/page"
import { PageVisibilityEnum } from "~/lib/types"
import type { ReactElement } from "react"
@@ -10,13 +10,17 @@ import type { ReactElement } from "react"
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const queryClient = new QueryClient()
const domainOrSubdomain = ctx.params!.site as string
- await getLayoutServerSideProps(ctx, queryClient, {
- useStat: true,
- })
+ const { props: layoutProps } = await getLayoutServerSideProps(
+ ctx,
+ queryClient,
+ {
+ useStat: true,
+ },
+ )
return {
props: {
- dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))),
+ ...layoutProps,
domainOrSubdomain,
},
}
diff --git a/src/pages/_site/[site]/nft.tsx b/src/pages/_site/[site]/nft.tsx
index 410febbc..015830f6 100644
--- a/src/pages/_site/[site]/nft.tsx
+++ b/src/pages/_site/[site]/nft.tsx
@@ -1,7 +1,7 @@
import { GetServerSideProps } from "next"
import { SiteLayout } from "~/components/site/SiteLayout"
import { getServerSideProps as getLayoutServerSideProps } from "~/components/site/SiteLayout.server"
-import { dehydrate, QueryClient } from "@tanstack/react-query"
+import { QueryClient } from "@tanstack/react-query"
import { useGetSite, useGetNFTs } from "~/queries/site"
import { ReactElement, useEffect, useState } from "react"
import type { Asset } from "unidata.js"
@@ -12,13 +12,17 @@ import { UniLink } from "~/components/ui/UniLink"
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const queryClient = new QueryClient()
const domainOrSubdomain = ctx.params!.site as string
- await getLayoutServerSideProps(ctx, queryClient, {
- skipPages: true,
- })
+ const { props: layoutProps } = await getLayoutServerSideProps(
+ ctx,
+ queryClient,
+ {
+ skipPages: true,
+ },
+ )
return {
props: {
- dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))),
+ ...layoutProps,
domainOrSubdomain,
},
}
diff --git a/src/pages/_site/[site]/tag/[tag].tsx b/src/pages/_site/[site]/tag/[tag].tsx
index ddc89efc..10ca3fe4 100644
--- a/src/pages/_site/[site]/tag/[tag].tsx
+++ b/src/pages/_site/[site]/tag/[tag].tsx
@@ -4,7 +4,7 @@ import { getServerSideProps as getLayoutServerSideProps } from "~/components/sit
import { serverSidePropsHandler } from "~/lib/server-side-props"
import { SiteArchives } from "~/components/site/SiteArchives"
import { Profile, Notes } from "~/lib/types"
-import { dehydrate, QueryClient } from "@tanstack/react-query"
+import { QueryClient } from "@tanstack/react-query"
import { useGetPagesBySiteLite } from "~/queries/page"
import { PageVisibilityEnum } from "~/lib/types"
import type { ReactElement } from "react"
@@ -15,13 +15,17 @@ export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
const domainOrSubdomain = ctx.params!.site as string
const tag = ctx.params!.tag as string
- await getLayoutServerSideProps(ctx, queryClient, {
- take: 100,
- })
+ const { props: layoutProps } = await getLayoutServerSideProps(
+ ctx,
+ queryClient,
+ {
+ take: 100,
+ },
+ )
return {
props: {
- dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))),
+ ...layoutProps,
domainOrSubdomain,
tag,
},
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 4d2350f0..faf10d2b 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -33,7 +33,7 @@ import {
XShopLogo,
CrossbellChainLogo,
} from "@crossbell/ui"
-import { useTranslation } from "next-i18next"
+import { useTranslation, Trans } from "next-i18next"
import { serverSideTranslations } from "next-i18next/serverSideTranslations"
import { languageDetector } from "~/lib/language-detector"
@@ -43,7 +43,10 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
return {
props: {
- ...(await serverSideTranslations(languageDetector(ctx), ["common"])),
+ ...(await serverSideTranslations(languageDetector(ctx), [
+ "common",
+ "index",
+ ])),
dehydratedState: dehydrate(queryClient),
},
}
@@ -53,7 +56,7 @@ export default function Home() {
const isConnected = useAccountState((s) => !!s.computed.account)
const router = useRouter()
const showcaseSites = useGetSites(showcase)
- const { t } = useTranslation("common")
+ const { t } = useTranslation("index")
const tryNow = useConnectedAction(() => {
router.push("/dashboard")
@@ -65,15 +68,8 @@ export default function Home() {
src: "/assets/easy.png",
},
icon:
,
- title: t("easy"),
- text: (
- <>
- Connect with your
Web3 Wallet or{" "}
-
Email. Build your own site with
- custom domains, subscriptions, likes, comments, minting as nft, RSS
- and more in one second. No fees, no friction.
- >
- ),
+ title: "Easy",
+ text: "Connect with your
Web3 Wallet or
Email. Build your own site with custom domains, subscriptions, likes, comments, minting as nft, RSS and more in one second. No fees, no friction.",
},
{
screenshot: {
@@ -81,14 +77,7 @@ export default function Home() {
},
icon:
,
title: "Safe",
- text: (
- <>
- All blog data, including configs, posts, subscriptions, comments,
- etc., are signed and securely stored on the{" "}
-
blockchain with your own hands. No
- one else, including us, can make any changes.
- >
- ),
+ text: "All blog data, including configs, posts, subscriptions, comments, etc., are signed and securely stored on the
blockchain with your own hands. No one else, including us, can make any changes.",
},
{
screenshot: {
@@ -96,13 +85,7 @@ export default function Home() {
},
icon:
,
title: "Fast",
- text: (
- <>
- Blockchain doesn't always mean inefficiency. xLog's
- efficient caching mechanism and numerous optimisations take it to the
- peak of performance.
- >
- ),
+ text: "Blockchain doesn't always mean inefficiency. xLog's efficient caching mechanism and numerous optimisations take it to the peak of performance.",
},
{
screenshot: {
@@ -110,7 +93,7 @@ export default function Home() {
},
icon:
,
title: "Customizable",
- text: "Use your own domain, customise your site and style it however you like. This is your site, there are no restrictions.",
+ text: "Use your own
domain, customise your site and
style it however you like. This is your site, there are no restrictions.",
},
{
screenshot: {
@@ -118,14 +101,7 @@ export default function Home() {
},
icon:
,
title: "Open",
- text: (
- <>
- Uses
standard Markdown with export
- and import tools and rich APIs for a painless move in and out. All
- code is
open source on GitHub, all
- data is
transparent on the chain.
- >
- ),
+ text: "Uses standard
Markdown with export and import tools and rich APIs for a painless move in and out. All code is
open source on GitHub, all
data is transparent on the chain.",
},
]
@@ -244,17 +220,21 @@ export default function Home() {
height={200}
/>
@@ -296,7 +276,9 @@ export default function Home() {
width={3785}
height={2170}
>
-