Skip to content

Commit

Permalink
i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
rockbenben committed Dec 31, 2024
1 parent 2a18a86 commit 48c936f
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 996 deletions.
99 changes: 16 additions & 83 deletions i18n/ar/docusaurus-plugin-content-pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import React, { useContext, useState, useMemo, useEffect, useCallback, useRef } from "react";
import React, { useContext, useState, useMemo, useEffect, useCallback } from "react";
import clsx from "clsx";
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";

import Translate, { translate } from "@docusaurus/Translate";
import { useHistory, useLocation } from "@docusaurus/router";
import Link from "@docusaurus/Link";
import Translate, { translate } from "@docusaurus/Translate";
import { useLocation } from "@docusaurus/router";
import Layout from "@theme/Layout";
import Heading from "@theme/Heading";

import { EditOutlined, HeartOutlined, ArrowDownOutlined } from "@ant-design/icons";
import { ConfigProvider, theme } from "antd";
import { debounce } from "lodash";
import FavoriteIcon from "@site/src/components/svgIcons/FavoriteIcon";
import styles from "@site/src/pages/styles.module.css";
import { Tags, TagList, type User, type TagType } from "@site/src/data/tags";
import { sortedUsers } from "@site/src/data/users.ar";
import { EditOutlined, HeartOutlined, ArrowDownOutlined } from "@ant-design/icons";

import FavoriteIcon from "@site/src/components/svgIcons/FavoriteIcon";
import ShowcaseTagSelect, { readSearchTags } from "@site/src/pages/_components/ShowcaseTagSelect";
import ShowcaseFilterToggle, { type Operator, readOperator } from "@site/src/pages/_components/ShowcaseFilterToggle";
import ShowcaseTooltip from "@site/src/pages/_components/ShowcaseTooltip";
Expand All @@ -25,27 +20,17 @@ import UserStatus from "@site/src/pages/_components/user/UserStatus";
import UserPrompts from "@site/src/pages/_components/user/UserPrompts";
import UserFavorite from "@site/src/pages/_components/user/UserFavorite";
import ShareButtons from "@site/src/pages/_components/ShareButtons";
import SearchBar, { NoResults, type UserState } from "@site/src/pages/_components/SearchBar";

import styles from "@site/src/pages/styles.module.css";
import { Tags, TagList, type User, type TagType } from "@site/src/data/tags";
import { SLOGAN, TITLE, DESCRIPTION } from "@site/src/data/constants";

import { AuthContext, AuthProvider } from "@site/src/pages/_components/AuthContext";

import { fetchAllCopyCounts } from "@site/src/api";

const TITLE = translate({
id: "homepage.title",
message: "AiShort(ChatGPT Shortcut)-简单易用的 AI 快捷指令表,让生产力倍增!",
});
const DESCRIPTION = translate({
id: "homepage.description",
message: "AI Short 是一款用于管理和分享 AI 提示词的工具,帮助用户更有效地定制、保存和共享自己的提示词,以提高生产力。该平台还包括一个提示词分享社区,让用户轻松找到适用于不同场景的指令。",
});
const SLOGAN = translate({
id: "homepage.slogan",
message: "让生产力加倍的 AI 快捷指令",
});

type UserState = {
scrollTopPosition: number;
focusedElementId: string | undefined;
};
import { sortedUsers } from "@site/src/data/users.ar";

export function prepareUserState(): UserState | undefined {
if (ExecutionEnvironment.canUseDOM) {
Expand Down Expand Up @@ -293,58 +278,6 @@ function ShowcaseFilters({ onToggleDescription, showUserFavs, setShowUserFavs })
);
}

function SearchBar({ setShowUserPrompts = (value) => {}, setShowUserFavs = (value) => {} }) {
const history = useHistory();
const location = useLocation();
const searchRef = useRef<HTMLInputElement>(null);
const [value, setValue] = useState<string | null>(null);

useEffect(() => {
setValue(readSearchName(location.search));
if (searchRef.current) {
searchRef.current.focus();
}
}, [location]);

const updateSearch = useCallback(
debounce((searchValue: string) => {
const newSearch = new URLSearchParams(location.search);
newSearch.delete(SearchNameQueryKey);
if (searchValue) {
newSearch.set(SearchNameQueryKey, searchValue);
}
history.push({
...location,
search: newSearch.toString(),
state: prepareUserState(),
});
setShowUserPrompts(false);
setShowUserFavs(false);
}, 1000), // search latency 搜索延时
[location, history]
);

const handleInput = (e: React.FormEvent<HTMLInputElement>) => {
setValue(e.currentTarget.value);
updateSearch(e.currentTarget.value);
};

return (
<div className={styles.searchContainer}>
<input
ref={searchRef}
id="searchbar"
placeholder={translate({
message: "Search for prompts...",
id: "showcase.searchBar.placeholder",
})}
value={value ?? undefined}
onInput={handleInput}
/>
</div>
);
}

function ShowcaseCards({ isDescription, showUserFavs }) {
const [copyCounts, setCopyCounts] = useState({});

Expand Down Expand Up @@ -405,10 +338,10 @@ function ShowcaseCards({ isDescription, showUserFavs }) {
return (
<section className="margin-top--lg margin-bottom--xl">
<div className="container padding-vert--md text--center">
<Heading as="h2">
<Translate id="showcase.usersList.noResult">😒 找不到结果,请缩短搜索词</Translate>
</Heading>
<SearchBar />
<div className={clsx("margin-bottom--md", styles.showcaseFavoriteHeader)}>
<SearchBar />
</div>
<NoResults />
</div>
</section>
);
Expand Down
99 changes: 16 additions & 83 deletions i18n/bn/docusaurus-plugin-content-pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import React, { useContext, useState, useMemo, useEffect, useCallback, useRef } from "react";
import React, { useContext, useState, useMemo, useEffect, useCallback } from "react";
import clsx from "clsx";
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";

import Translate, { translate } from "@docusaurus/Translate";
import { useHistory, useLocation } from "@docusaurus/router";
import Link from "@docusaurus/Link";
import Translate, { translate } from "@docusaurus/Translate";
import { useLocation } from "@docusaurus/router";
import Layout from "@theme/Layout";
import Heading from "@theme/Heading";

import { EditOutlined, HeartOutlined, ArrowDownOutlined } from "@ant-design/icons";
import { ConfigProvider, theme } from "antd";
import { debounce } from "lodash";
import FavoriteIcon from "@site/src/components/svgIcons/FavoriteIcon";
import styles from "@site/src/pages/styles.module.css";
import { Tags, TagList, type User, type TagType } from "@site/src/data/tags";
import { sortedUsers } from "@site/src/data/users.bn";
import { EditOutlined, HeartOutlined, ArrowDownOutlined } from "@ant-design/icons";

import FavoriteIcon from "@site/src/components/svgIcons/FavoriteIcon";
import ShowcaseTagSelect, { readSearchTags } from "@site/src/pages/_components/ShowcaseTagSelect";
import ShowcaseFilterToggle, { type Operator, readOperator } from "@site/src/pages/_components/ShowcaseFilterToggle";
import ShowcaseTooltip from "@site/src/pages/_components/ShowcaseTooltip";
Expand All @@ -25,27 +20,17 @@ import UserStatus from "@site/src/pages/_components/user/UserStatus";
import UserPrompts from "@site/src/pages/_components/user/UserPrompts";
import UserFavorite from "@site/src/pages/_components/user/UserFavorite";
import ShareButtons from "@site/src/pages/_components/ShareButtons";
import SearchBar, { NoResults, type UserState } from "@site/src/pages/_components/SearchBar";

import styles from "@site/src/pages/styles.module.css";
import { Tags, TagList, type User, type TagType } from "@site/src/data/tags";
import { SLOGAN, TITLE, DESCRIPTION } from "@site/src/data/constants";

import { AuthContext, AuthProvider } from "@site/src/pages/_components/AuthContext";

import { fetchAllCopyCounts } from "@site/src/api";

const TITLE = translate({
id: "homepage.title",
message: "AiShort(ChatGPT Shortcut)-简单易用的 AI 快捷指令表,让生产力倍增!",
});
const DESCRIPTION = translate({
id: "homepage.description",
message: "AI Short 是一款用于管理和分享 AI 提示词的工具,帮助用户更有效地定制、保存和共享自己的提示词,以提高生产力。该平台还包括一个提示词分享社区,让用户轻松找到适用于不同场景的指令。",
});
const SLOGAN = translate({
id: "homepage.slogan",
message: "让生产力加倍的 AI 快捷指令",
});

type UserState = {
scrollTopPosition: number;
focusedElementId: string | undefined;
};
import { sortedUsers } from "@site/src/data/users.bn";

export function prepareUserState(): UserState | undefined {
if (ExecutionEnvironment.canUseDOM) {
Expand Down Expand Up @@ -293,58 +278,6 @@ function ShowcaseFilters({ onToggleDescription, showUserFavs, setShowUserFavs })
);
}

function SearchBar({ setShowUserPrompts = (value) => {}, setShowUserFavs = (value) => {} }) {
const history = useHistory();
const location = useLocation();
const searchRef = useRef<HTMLInputElement>(null);
const [value, setValue] = useState<string | null>(null);

useEffect(() => {
setValue(readSearchName(location.search));
if (searchRef.current) {
searchRef.current.focus();
}
}, [location]);

const updateSearch = useCallback(
debounce((searchValue: string) => {
const newSearch = new URLSearchParams(location.search);
newSearch.delete(SearchNameQueryKey);
if (searchValue) {
newSearch.set(SearchNameQueryKey, searchValue);
}
history.push({
...location,
search: newSearch.toString(),
state: prepareUserState(),
});
setShowUserPrompts(false);
setShowUserFavs(false);
}, 1000), // search latency 搜索延时
[location, history]
);

const handleInput = (e: React.FormEvent<HTMLInputElement>) => {
setValue(e.currentTarget.value);
updateSearch(e.currentTarget.value);
};

return (
<div className={styles.searchContainer}>
<input
ref={searchRef}
id="searchbar"
placeholder={translate({
message: "Search for prompts...",
id: "showcase.searchBar.placeholder",
})}
value={value ?? undefined}
onInput={handleInput}
/>
</div>
);
}

function ShowcaseCards({ isDescription, showUserFavs }) {
const [copyCounts, setCopyCounts] = useState({});

Expand Down Expand Up @@ -405,10 +338,10 @@ function ShowcaseCards({ isDescription, showUserFavs }) {
return (
<section className="margin-top--lg margin-bottom--xl">
<div className="container padding-vert--md text--center">
<Heading as="h2">
<Translate id="showcase.usersList.noResult">😒 找不到结果,请缩短搜索词</Translate>
</Heading>
<SearchBar />
<div className={clsx("margin-bottom--md", styles.showcaseFavoriteHeader)}>
<SearchBar />
</div>
<NoResults />
</div>
</section>
);
Expand Down
Loading

0 comments on commit 48c936f

Please sign in to comment.