diff --git a/locales/app/en.json b/locales/app/en.json index 5839f757e..18249e9ef 100644 --- a/locales/app/en.json +++ b/locales/app/en.json @@ -73,6 +73,16 @@ "mark_all_read_button.mark_all_as_read": "Mark all as read", "mark_all_read_button.mark_as_read": "Mark {{which}} as read", "mark_all_read_button.undo": "Undo", + "search.empty.no_results": "No results found.", + "search.group.entries": "Entries", + "search.group.feeds": "Feeds", + "search.options.all": "All", + "search.options.entries": "Entries", + "search.options.feeds": "Feeds", + "search.options.search_type": "Search Type", + "search.placeholder": "Search...", + "search.result_count_local_mode": "(Local mode)", + "search.tooltip.local_search": "This search covers locally available data. Try a Refetch to include the latest data.", "sidebar.category_remove_dialog.cancel": "Cancel", "sidebar.category_remove_dialog.continue": "Continue", "sidebar.category_remove_dialog.description": "This operation will delete your category, but the feeds it contains will be retained and grouped by website.", @@ -101,6 +111,11 @@ "signin.sign_in_to": "Sign in to", "sync_indicator.offline": "Offline", "sync_indicator.synced": "Synced with server", + "user_profile.close": "Close", + "user_profile.edit": "Edit", + "user_profile.loading": "Loading", + "user_profile.share": "Share", + "user_profile.toggle_item_style": "Toggle Item Style", "words.add": "Add", "words.confirm": "Confirm", "words.discover": "Discover", diff --git a/locales/app/zh-CN.json b/locales/app/zh-CN.json index 151373ef2..8e9f43af6 100644 --- a/locales/app/zh-CN.json +++ b/locales/app/zh-CN.json @@ -73,6 +73,16 @@ "mark_all_read_button.mark_all_as_read": "全部标记为已读", "mark_all_read_button.mark_as_read": "标记{{which}}为已读", "mark_all_read_button.undo": "撤消", + "search.empty.no_results": "未找到结果。", + "search.group.entries": "条目", + "search.group.feeds": "订阅源", + "search.options.all": "全部", + "search.options.entries": "条目", + "search.options.feeds": "订阅源", + "search.options.search_type": "搜索类型", + "search.placeholder": "搜索...", + "search.result_count_local_mode": "(本地模式)", + "search.tooltip.local_search": "此搜索仅涵盖本地可用数据。尝试重新获取以包含最新数据。", "sidebar.category_remove_dialog.cancel": "取消", "sidebar.category_remove_dialog.continue": "继续", "sidebar.category_remove_dialog.description": "此操作将删除您的类别,但其中包含的 Feed 将保留并按网站分组。", @@ -101,6 +111,11 @@ "signin.sign_in_to": "登录到", "sync_indicator.offline": "离线", "sync_indicator.synced": "已与服务器同步", + "user_profile.close": "关闭", + "user_profile.edit": "编辑", + "user_profile.loading": "加载中", + "user_profile.share": "分享", + "user_profile.toggle_item_style": "切换列表样式", "words.add": "添加", "words.confirm": "确认", "words.discover": "发现", diff --git a/locales/common/en.json b/locales/common/en.json index 8e5c17f32..5350e008e 100644 --- a/locales/common/en.json +++ b/locales/common/en.json @@ -10,10 +10,18 @@ "tips.load-lng-error": "Failed to load language pack", "words.back": "Back", "words.copy": "Copy", + "words.edit": "Edit", "words.entry": "Entry", "words.id": "ID", "words.items_one": "Item", "words.items_other": "Items", + "words.local": "local", + "words.record": "record", + "words.record_one": "record", + "words.record_other": "records", + "words.result": "result", + "words.result_one": "result", + "words.result_other": "results", "words.space": " ", "words.which.all": "All" } diff --git a/locales/common/zh-CN.json b/locales/common/zh-CN.json index 459bc2fa8..9d94f3309 100644 --- a/locales/common/zh-CN.json +++ b/locales/common/zh-CN.json @@ -15,6 +15,9 @@ "words.items": "内容", "words.items_one": "内容", "words.items_other": "内容", + "words.local": "本地", + "words.record": "记录", + "words.result": "结果", "words.space": "", "words.which.all": "全部" } diff --git a/locales/settings/zh-CN.json b/locales/settings/zh-CN.json index 66cf47942..ad4d70343 100644 --- a/locales/settings/zh-CN.json +++ b/locales/settings/zh-CN.json @@ -53,8 +53,8 @@ "appearance.guess_code_language.description": "使用模型来推断未标记代码块的主要编程语言", "appearance.guess_code_language.label": "猜测代码语言", "appearance.misc": "杂项", - "appearance.modal_overlay.description": "显示模态叠加", - "appearance.modal_overlay.label": "显示模态叠加", + "appearance.modal_overlay.description": "显示模态遮罩,以提高可访问性", + "appearance.modal_overlay.label": "显示模态遮罩", "appearance.opaque_sidebars.label": "不透明侧边栏", "appearance.reader_render_inline_style.description": "允许渲染原始 HTML 的内联样式。", "appearance.reader_render_inline_style.label": "渲染内联样式", diff --git a/package.json b/package.json index e2c407033..fce3c0cf4 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "electron-updater": "^6.3.4", "font-list": "1.5.1", "foxact": "0.2.38", - "framer-motion": "11.0.10", + "framer-motion": "11.5.4", "franc-min": "6.2.0", "fuse.js": "7.0.0", "hast-util-to-jsx-runtime": "2.3.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 718f46e32..7c3c9e949 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -195,8 +195,8 @@ importers: specifier: 0.2.38 version: 0.2.38(react@18.3.1) framer-motion: - specifier: 11.0.10 - version: 11.0.10(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: 11.5.4 + version: 11.5.4(@emotion/is-prop-valid@0.8.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) franc-min: specifier: 6.2.0 version: 6.2.0 @@ -4999,12 +4999,15 @@ packages: react: optional: true - framer-motion@11.0.10: - resolution: {integrity: sha512-aaImib9FQlfno2yiZAdkvN6zLXLr8a9uGsGFlQO64hSm8NoCeiUng2//5ok7RHCW2ufzT74uuPsmWzUsrHPYDQ==} + framer-motion@11.5.4: + resolution: {integrity: sha512-E+tb3/G6SO69POkdJT+3EpdMuhmtCh9EWuK4I1DnIC23L7tFPrl8vxP+LSovwaw6uUr73rUbpb4FgK011wbRJQ==} peerDependencies: + '@emotion/is-prop-valid': '*' react: ^18.0.0 react-dom: ^18.0.0 peerDependenciesMeta: + '@emotion/is-prop-valid': + optional: true react: optional: true react-dom: @@ -13937,7 +13940,7 @@ snapshots: optionalDependencies: react: 18.3.1 - framer-motion@11.0.10(react-dom@18.3.1(react@18.3.1))(react@18.3.1): + framer-motion@11.5.4(@emotion/is-prop-valid@0.8.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1): dependencies: tslib: 2.7.0 optionalDependencies: diff --git a/src/renderer/src/components/ui/modal/stacked/modal.tsx b/src/renderer/src/components/ui/modal/stacked/modal.tsx index 9458efb3d..183624023 100644 --- a/src/renderer/src/components/ui/modal/stacked/modal.tsx +++ b/src/renderer/src/components/ui/modal/stacked/modal.tsx @@ -113,7 +113,7 @@ export const ModalInternal = memo( }) const animateController = useAnimationControls() useEffect(() => { - requestAnimationFrame(() => { + nextFrame(() => { animateController.start(modalMontionConfig.animate) }) }, [animateController]) @@ -259,6 +259,7 @@ export const ModalInternal = memo( )} onPointerUp={handleDetectSelectEnd} onClick={handleClickOutsideToDismiss} + onFocus={stopPropagation} style={zIndexStyle} > {DragBar} @@ -296,6 +297,7 @@ export const ModalInternal = memo( modalContainerClassName, !isResizeable && "center", )} + onFocus={stopPropagation} onPointerUp={handleDetectSelectEnd} onClick={handleClickOutsideToDismiss} > diff --git a/src/renderer/src/hooks/common/index.ts b/src/renderer/src/hooks/common/index.ts index 24d38568b..5331c8bfb 100644 --- a/src/renderer/src/hooks/common/index.ts +++ b/src/renderer/src/hooks/common/index.ts @@ -1,5 +1,6 @@ export * from "./useBizQuery" export * from "./useDark" +export * from "./useI18n" export * from "./useInputComposition" export * from "./useInterval" export * from "./useIsOnline" diff --git a/src/renderer/src/hooks/common/useI18n.ts b/src/renderer/src/hooks/common/useI18n.ts new file mode 100644 index 000000000..9d8af18bd --- /dev/null +++ b/src/renderer/src/hooks/common/useI18n.ts @@ -0,0 +1,23 @@ +import { ns } from "@renderer/@types/constants" +import { useMemo } from "react" +import type { FallbackNs, UseTranslationResponse } from "react-i18next" +import { useTranslation } from "react-i18next" + +const allNameSpaces = ns + +export function useI18n() { + const { t } = useTranslation() + + return useMemo(() => { + const clonedT = t.bind(t) + + for (const ns of allNameSpaces) { + clonedT[ns] = (key: any, options: Omit[1], "ns"> = {}) => { + return t(key, { ns: ns as any, ...options }) + } + } + return clonedT as typeof t & { + [K in (typeof allNameSpaces)[number]]: UseTranslationResponse, undefined>["t"] + } + }, [t]) +} diff --git a/src/renderer/src/lib/utils.ts b/src/renderer/src/lib/utils.ts index 7eea3e870..5135ba772 100644 --- a/src/renderer/src/lib/utils.ts +++ b/src/renderer/src/lib/utils.ts @@ -145,6 +145,9 @@ export const sleep = (ms: number) => new Promise((resolve) => setTimeout(r export const capitalizeFirstLetter = (string: string) => string.charAt(0).toUpperCase() + string.slice(1) +/** + * @deprecated + */ export const pluralize = ( noun: string, count: number, diff --git a/src/renderer/src/modules/entry-column/components/mark-all-button.tsx b/src/renderer/src/modules/entry-column/components/mark-all-button.tsx index e2119ade9..dbc0690ff 100644 --- a/src/renderer/src/modules/entry-column/components/mark-all-button.tsx +++ b/src/renderer/src/modules/entry-column/components/mark-all-button.tsx @@ -5,6 +5,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@renderer/components/ui import { RootPortal } from "@renderer/components/ui/portal" import { HotKeyScopeMap } from "@renderer/constants" import { shortcuts } from "@renderer/constants/shortcuts" +import { useI18n } from "@renderer/hooks/common" import { cn } from "@renderer/lib/utils" import { AnimatePresence, m } from "framer-motion" import type { FC, ReactNode } from "react" @@ -235,8 +236,8 @@ export const MarkAllReadPopover = forwardRef = (props) => { - const { t } = useTranslation() - const { t: commonT } = useTranslation("common") + const t = useI18n() + const { className, filter, which } = props const [status, setStatus] = useState<"initial" | "confirm" | "done">("initial") const handleMarkAll = useMarkAllByRoute(filter) @@ -278,9 +279,7 @@ export const FlatMarkAllReadButton: FC = (props) => { diff --git a/src/renderer/src/modules/panel/cmdk.tsx b/src/renderer/src/modules/panel/cmdk.tsx index 5c5ba03d9..6d056b271 100644 --- a/src/renderer/src/modules/panel/cmdk.tsx +++ b/src/renderer/src/modules/panel/cmdk.tsx @@ -15,8 +15,9 @@ import { import { Tooltip, TooltipContent, TooltipTrigger } from "@renderer/components/ui/tooltip" import { ROUTE_ENTRY_PENDING } from "@renderer/constants" import { useNavigateEntry } from "@renderer/hooks/biz/useNavigateEntry" +import { useI18n } from "@renderer/hooks/common" import type { FeedViewType } from "@renderer/lib/enum" -import { cn, pluralize } from "@renderer/lib/utils" +import { cn } from "@renderer/lib/utils" import { getFeedById } from "@renderer/store/feed" import { searchActions, useSearchStore } from "@renderer/store/search" import { SearchType } from "@renderer/store/search/constants" @@ -28,11 +29,13 @@ import { Command } from "cmdk" import type { FC } from "react" import * as React from "react" import { memo, useMemo } from "react" +import { useTranslation } from "react-i18next" import styles from "./cmdk.module.css" const SearchCmdKContext = React.createContext | null>(null) export const SearchCmdK: React.FC = () => { + const { t } = useTranslation() const open = useAppSearchOpen() const [searchInstance, setSearchInstance] = React.useState(() => @@ -134,7 +137,7 @@ export const SearchCmdK: React.FC = () => {
@@ -150,7 +153,12 @@ export const SearchCmdK: React.FC = () => { {renderedEntries.length > 0 && ( } + heading={ + + } className="flex w-full min-w-0 flex-col py-2" > {renderedEntries.map((entry) => { @@ -173,7 +181,10 @@ export const SearchCmdK: React.FC = () => { {renderedFeeds.length > 0 && ( + } className="py-2" > @@ -264,10 +275,11 @@ const SearchGroupHeading: FC<{ icon: string; title: string }> = ({ icon, title } const SearchResultCount: FC<{ count?: number }> = ({ count }) => { + const t = useI18n() const searchInstance = React.useContext(SearchCmdKContext) const hasKeyword = useSearchStore((s) => !!s.keyword) const searchType = useSearchStore((s) => s.searchType) - + const recordCountPromise = useMemo(async () => { let count = 0 const counts = await searchInstance?.then((s) => s.counts) @@ -290,35 +302,37 @@ const SearchResultCount: FC<{ {hasKeyword ? ( - {count} {pluralize("result", count || 0)} + {count} {t.common("words.result", { count })} ) : ( {(count) => ( <> - {count} local {pluralize("record", count)} + {count} {t.common("quantifier.piece")} + {t.common("words.local")} + {t.common("words.space")} + {t.common("words.record", { count })} )} )}{" "} - (Local mode) + {t("search.result_count_local_mode")} - - This search covers locally available data. Try a Refetch to include the latest data. - + {t("search.tooltip.local_search")} ) } const SearchOptions: Component = memo(({ children }) => { + const { t } = useTranslation() const searchType = useSearchStore((s) => s.searchType) const searchInstance = React.useContext(SearchCmdKContext) return (
- Search Type + {t("search.options.search_type")} @@ -365,13 +379,14 @@ const SearchOptions: Component = memo(({ children }) => { }) const SearchPlaceholder = () => { + const { t } = useTranslation() const hasKeyword = useSearchStore((s) => !!s.keyword) return ( {hasKeyword ? (
- No results found. + {t("search.empty.no_results")}
) : ( diff --git a/src/renderer/src/modules/profile/user-profile-modal.tsx b/src/renderer/src/modules/profile/user-profile-modal.tsx index 7dd46ef2f..0d36ffec5 100644 --- a/src/renderer/src/modules/profile/user-profile-modal.tsx +++ b/src/renderer/src/modules/profile/user-profile-modal.tsx @@ -7,7 +7,7 @@ import { ActionButton, Button } from "@renderer/components/ui/button" import { LoadingCircle, LoadingWithIcon } from "@renderer/components/ui/loading" import { useCurrentModal, useModalStack } from "@renderer/components/ui/modal" import { ScrollArea } from "@renderer/components/ui/scroll-area" -import { useAuthQuery } from "@renderer/hooks/common" +import { useAuthQuery, useI18n } from "@renderer/hooks/common" import { apiClient } from "@renderer/lib/api-fetch" import { defineQuery } from "@renderer/lib/defineQuery" import { nextFrame, stopPropagation } from "@renderer/lib/dom" @@ -23,6 +23,7 @@ import { atomWithStorage } from "jotai/utils" import { throttle } from "lodash-es" import type { FC } from "react" import { Fragment, useEffect, useMemo, useRef, useState } from "react" +import { useTranslation } from "react-i18next" import { FeedForm } from "../discover/feed-form" @@ -40,6 +41,7 @@ export const UserProfileModalContent: FC<{ variant: "drawer" | "dialog" }> = ({ userId, variant }) => { + const { t } = useTranslation() const user = useAuthQuery( defineQuery(["profiles", userId], async () => { const res = await apiClient.profiles.$get({ @@ -171,7 +173,6 @@ export const UserProfileModalContent: FC<{ >
{ const currentVisible = currentVisibleRef.current const topOfCurrent = currentVisible?.values().next().value @@ -213,14 +214,14 @@ export const UserProfileModalContent: FC<{ /> { window.open(`${env.VITE_WEB_URL}/profile/${user.data?.id}`) }} > - +
@@ -267,7 +268,7 @@ export const UserProfileModalContent: FC<{ @@ -325,6 +326,7 @@ const SubscriptionItem: FC<{ variant: ItemVariant }> = ({ subscription, variant }) => { + const t = useI18n() const isFollowed = !!useSubscriptionStore((state) => state.data[subscription.feedId]) const { present } = useModalStack() const isLoose = variant === "loose" @@ -354,10 +356,11 @@ const SubscriptionItem: FC<{ onClick={(e) => { e.stopPropagation() e.preventDefault() + const defaultView = subscription.view present({ - title: `${isFollowed ? "Edit " : ""}${APP_NAME} - ${subscription.feeds.title}`, + title: `${isFollowed ? `${t.common("words.edit")} ` : ""}${APP_NAME} - ${subscription.feeds.title}`, clickOutsideToDismiss: true, content: ({ dismiss }) => ( {isFollowed ? ( - "Edit" + t("user_profile.edit") ) : ( <> diff --git a/src/renderer/src/providers/i18n-provider.tsx b/src/renderer/src/providers/i18n-provider.tsx index 61086b8fc..a336c7689 100644 --- a/src/renderer/src/providers/i18n-provider.tsx +++ b/src/renderer/src/providers/i18n-provider.tsx @@ -8,6 +8,7 @@ import { getGeneralSettings } from "@renderer/atoms/settings/general" import { i18nAtom } from "@renderer/i18n" import { EventBus } from "@renderer/lib/event-bus" import { jotaiStore } from "@renderer/lib/jotai" +import { isEmptyObject } from "@renderer/lib/utils" import dayjs from "dayjs" import i18next from "i18next" import { useAtom } from "jotai" @@ -67,8 +68,17 @@ const langChangedHandler = async (lang: string) => { } } } else { - const res = await eval(`import('/locales/${lang}.js').then((res) => res?.default || res)`) + const res = await eval( + `import('/locales/${lang}.js').then((res) => res?.default || res)`, + ).catch(() => { + toast.error(`${t("common:tips.load-lng-error")}: ${lang}`) + loadingLangLock.delete(lang) + return {} + }) + if (isEmptyObject(res)) { + return + } for (const namespace in res) { i18next.addResourceBundle(lang, namespace, res[namespace], true, true) } diff --git a/tsconfig.node.json b/tsconfig.node.json index 30a7f1684..4203d84c0 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -17,6 +17,8 @@ "types": ["electron-vite/node"], "moduleResolution": "Bundler", "noImplicitReturns": false, + "noUnusedLocals": false, + "noUnusedParameters": false, "baseUrl": ".", "paths": { "@shared/*": ["src/shared/src/*"],