From 8d8aa09230eb5ddd55dffe074b20c9ed81e84a99 Mon Sep 17 00:00:00 2001
From: Innei
Date: Sat, 14 Sep 2024 14:25:58 +0800
Subject: [PATCH] feat: external page i18n
Signed-off-by: Innei
---
locales/external/en.json | 34 +++++++++++++++++++
src/renderer/src/components/header.tsx | 6 ++--
.../(with-layout)/feed/[id]/index.tsx | 15 +++++---
.../src/pages/(external)/invitation.tsx | 13 +++----
src/renderer/src/pages/(external)/login.tsx | 17 ++++++----
5 files changed, 62 insertions(+), 23 deletions(-)
diff --git a/locales/external/en.json b/locales/external/en.json
index 64b46f351..7aca60ec8 100644
--- a/locales/external/en.json
+++ b/locales/external/en.json
@@ -1,4 +1,38 @@
{
+ "feed": {
+ "follow_one": "follow",
+ "follow_other": "follows",
+ "followsAndReads": "{{subscriptionCount}} {{subscriptionNoun}} with {{readCount}} {{readNoun}} on {{appName}}",
+ "read_one": "read",
+ "read_other": "reads"
+ },
+ "header": {
+ "app": "App",
+ "download": "Download"
+ },
+ "invitation": {
+ "activate": "Activate",
+ "codeOptions": {
+ "1": "Looking for any alpha test user to invite you.",
+ "2": "Join our Discord server for occasional giveaways.",
+ "3": "Follow our X account for occasional giveaways."
+ },
+ "earlyAccess": "Follow is currently in early access and requires an invitation code to use.",
+ "earlyAccessMessage": "😰 Sorry, Follow is currently in early access and requires an invitation code to use.",
+ "generateButton": "Generate new code",
+ "generateCost": "You can spend {{INVITATION_PRICE}} Power to generate an invitation code for your friends.",
+ "getCodeMessage": "You can get an invitation code in the following ways:",
+ "title": "Invitation Code"
+ },
+ "login": {
+ "backToWebApp": "Back To Web App",
+ "continueWithGitHub": "Continue with GitHub",
+ "continueWithGoogle": "Continue with Google",
+ "logInTo": "Log in to ",
+ "openApp": "Open App",
+ "redirecting": "Redirecting",
+ "welcomeTo": "Welcome to "
+ },
"redirect": {
"continueInBrowser": "Continue in Browser",
"instruction": "Now is the time to open {{APP_NAME}} and safely close this page.",
diff --git a/src/renderer/src/components/header.tsx b/src/renderer/src/components/header.tsx
index 785f2f07d..2cf4f55f9 100644
--- a/src/renderer/src/components/header.tsx
+++ b/src/renderer/src/components/header.tsx
@@ -5,6 +5,7 @@ import type { MotionValue } from "framer-motion"
import { useMotionValueEvent, useScroll } from "framer-motion"
import type { FC } from "react"
import { cloneElement, useState } from "react"
+import { useTranslation } from "react-i18next"
import { Link } from "react-router-dom"
import { FollowIcon } from "./icons/follow"
@@ -19,6 +20,7 @@ const useMotionValueToState = (value: MotionValue) => {
export function Header() {
const present = usePresentUserProfileModal()
+ const { t } = useTranslation("external")
const { scrollY } = useScroll()
const scrollYState = useMotionValueToState(scrollY)
@@ -40,12 +42,12 @@ export function Header() {
- } label="App" />
+ } label={t("header.app")} />
}
- label="Download"
+ label={t("header.download")}
/>
diff --git a/src/renderer/src/pages/(external)/(with-layout)/feed/[id]/index.tsx b/src/renderer/src/pages/(external)/(with-layout)/feed/[id]/index.tsx
index 803d529c5..9bfaa56ea 100644
--- a/src/renderer/src/pages/(external)/(with-layout)/feed/[id]/index.tsx
+++ b/src/renderer/src/pages/(external)/(with-layout)/feed/[id]/index.tsx
@@ -6,7 +6,7 @@ import { LoadingCircle } from "@renderer/components/ui/loading"
import { views } from "@renderer/constants"
import { useTitle } from "@renderer/hooks/common"
import { FeedViewType } from "@renderer/lib/enum"
-import { cn, pluralize } from "@renderer/lib/utils"
+import { cn } from "@renderer/lib/utils"
import { ArticleItem } from "@renderer/modules/entry-column/Items/article-item"
import { NotificationItem } from "@renderer/modules/entry-column/Items/notification-item"
import { PictureItem } from "@renderer/modules/entry-column/Items/picture-item"
@@ -17,6 +17,7 @@ import { useEntriesPreview } from "@renderer/queries/entries"
import { useFeed } from "@renderer/queries/feed"
import { DEEPLINK_SCHEME } from "@shared/constants"
import type { FC } from "react"
+import { useTranslation } from "react-i18next"
import { useParams, useSearchParams } from "react-router-dom"
export function Component() {
@@ -57,6 +58,7 @@ export function Component() {
Item = ArticleItem
}
}
+ const { t } = useTranslation("external")
useTitle(feed.data?.feed.title)
return (
<>
@@ -78,10 +80,13 @@ export function Component() {
{feed.data.feed.description}
- {feed.data.subscriptionCount}{" "}
- {pluralize("follow", feed.data.subscriptionCount)} with{" "}
- {feed.data.readCount} {pluralize("read", feed.data.readCount)} on{" "}
- {APP_NAME}
+ {t("feed.followsAndReads", {
+ subscriptionCount: feed.data.subscriptionCount,
+ subscriptionNoun: t("feed.follow", { count: feed.data.subscriptionCount }),
+ readCount: feed.data.readCount,
+ readNoun: t("feed.read", { count: feed.data.readCount }),
+ appName: APP_NAME,
+ })}
diff --git a/src/renderer/src/pages/(external)/login.tsx b/src/renderer/src/pages/(external)/login.tsx
index e5f04fa4d..b1c4a4967 100644
--- a/src/renderer/src/pages/(external)/login.tsx
+++ b/src/renderer/src/pages/(external)/login.tsx
@@ -5,6 +5,7 @@ import { UserAvatar } from "@renderer/components/user-button"
import { useSignOut } from "@renderer/hooks/biz/useSignOut"
import { LOGIN_CALLBACK_URL, loginHandler } from "@renderer/lib/auth"
import { useEffect, useState } from "react"
+import { useTranslation } from "react-i18next"
import { useLocation, useNavigate } from "react-router-dom"
export function Component() {
@@ -30,6 +31,8 @@ function Login() {
}
}
+ const { t } = useTranslation("external")
+
useEffect(() => {
if (!window.electron && provider) {
if (status === "authenticated") {
@@ -49,17 +52,17 @@ function Login() {
{!isAuthenticated ? (
- Log in to
+ {t("login.logInTo")}
{` ${APP_NAME}`}
) : (
- Welcome to
+ {t("login.welcomeTo")}
{` ${APP_NAME}`}
)}
{redirecting ? (
-
Redirecting
+
{t("login.redirecting")}
) : (
{isAuthenticated ? (
@@ -72,7 +75,7 @@ function Login() {
>
@@ -92,7 +95,7 @@ function Login() {
loginHandler("github")
}}
>
-
Continue with GitHub
+
{t("login.continueWithGitHub")}
>
)}