Skip to content

Commit

Permalink
✨ feat(intl): add more intl
Browse files Browse the repository at this point in the history
  • Loading branch information
summerscar committed Nov 6, 2024
1 parent 4039cba commit 3698c5b
Show file tree
Hide file tree
Showing 10 changed files with 682 additions and 122 deletions.
8 changes: 8 additions & 0 deletions app/components/cache-toolbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NextCacheToolbar } from "next-cache-toolbar";
import "next-cache-toolbar/style.css";

function CacheToolbar() {
return <NextCacheToolbar />;
}

export { CacheToolbar };
20 changes: 8 additions & 12 deletions app/components/home-drawer/dict-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,27 @@ const DictMenu = ({
importLocalDict(onDictUpdate);
} else {
const fileString = await importJSONFile();
// TODO: intl
const cancel = createLoadingToast("importing....");
const cancel = createLoadingToast(tHome("importing"));
await importDictItemToUserDict(dictId, fileString as string);
await serverActionTimeOut();
cancel();
createSuccessToast("success");
createSuccessToast(tHome("imported"));
}
};

const createDict = async () => {
// TODO: intl
if (!isLogin) {
router.push("/api/auth/signin");
return;
}
const dictName = prompt("name:");
const dictName = prompt(tHome("createWordList"));
if (dictName) {
const removeInfoToast = createLoadingToast(tHome("generating"));
const removeInfoToast = createLoadingToast(tHome("creating"));
const res = await createDictAction(dictName);
router.push(`/?dict=${res.id}`);
await serverActionTimeOut();
removeInfoToast();
// TODO: intl
createSuccessToast("success");
createSuccessToast(tHome("created"));
}
};

Expand All @@ -143,8 +140,7 @@ const DictMenu = ({
const handleRemoveDict = async () => {
const res = confirm();
if (!res) return;
// TODO: intl
const removeInfoToast = createLoadingToast("removing....");
const removeInfoToast = createLoadingToast(tHome("removing"));
await removeDictAction(dictId);
router.push("/");
await serverActionTimeOut();
Expand Down Expand Up @@ -231,8 +227,8 @@ const DictMenu = ({
</option>
))}
<option value="_local">{tDict(Dicts.local)}</option>
{/* // TODO: intl */}
<option value="_create">+ create new</option>

<option value="_create">{tHome("createNewDict")}</option>
</select>
</div>
);
Expand Down
10 changes: 6 additions & 4 deletions app/components/home-drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { removeLocalDict } from "@/utils/local-dict";
import { serverActionTimeOut, timeOut } from "@/utils/time-out";
import { useMemoizedFn } from "ahooks";
import clsx from "clsx";
import { useLocale } from "next-intl";
import { useLocale, useTranslations } from "next-intl";
import { useEffect, useRef } from "react";
import { createPortal } from "react-dom";
import { DictMenu } from "./dict-menu";
Expand Down Expand Up @@ -45,6 +45,7 @@ const HomeDrawer = ({
}) => {
const drawerListRef = useRef<HTMLUListElement>(null);
const locale = useLocale();
const tHome = useTranslations("Home");
const controllerRef = useRef<HTMLInputElement>(null);
const open = useMemoizedFn(() => {
if (controllerRef.current) {
Expand Down Expand Up @@ -78,12 +79,13 @@ const HomeDrawer = ({
removeLocalDict(item.name);
onLocalDictUpdate();
} else {
// TODO: intl
const cancel = createLoadingToast(`【${item.name}】removing....`);
const cancel = createLoadingToast(
`【${item.name}${tHome("removing")}`,
);
await removeDictItemAction(dictId, item.id!);
await serverActionTimeOut();
cancel();
createSuccessToast("success");
createSuccessToast(tHome("removed"));
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion app/components/home-status/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const HomeStatus = ({
}, [originalDict, setLocalDict, setDictAndDisableVoice]);

const shuffleDict = useMemoizedFn(() => {
setDictAndDisableVoice((prev) => shuffleArr(prev), true);
setDictAndDisableVoice((prev) => shuffleArr(prev));
});

// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
Expand Down
1 change: 1 addition & 0 deletions app/components/root-layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export async function DefaultLayout({
</NextIntlClientProvider>
</SessionProvider>
<ToastRoot />
{/* {isDev && <CacheToolbar />} */}
{isProd && <SpeedInsights />}
{isProd && <Analytics />}
{isProd && <GoogleAnalytics gaId={GAId} />}
Expand Down
16 changes: 15 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@
"generateError": "Failed to generate. Please try again.",
"autoVoice": "Auto read",
"showMeaning": "Show meaning",
"enableAudio": "Enable audio effect"
"enableAudio": "Enable audio effect",
"deleting": "Deleting...",
"deleted": "Deleted successfully!",
"deleteError": "Failed to delete. Please try again.",
"importing": "Importing...",
"imported": "Imported successfully!",
"importError": "Failed to import. Please try again.",
"createWordList": "Input Word List Name:",
"creating": "Creating...",
"created": "Created successfully!",
"createError": "Failed to create. Please try again.",
"removing": "Removing...",
"removed": "Removed successfully!",
"removeError": "Failed to remove. Please try again.",
"createNewDict": "Create new"
},
"Dict": {
"popular": "Popular Words",
Expand Down
16 changes: 15 additions & 1 deletion messages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@
"generateError": "生成に失敗しました。もう一度お試しください。",
"autoVoice": "自動読み上げ",
"showMeaning": "意味を表示",
"enableAudio": "オーバイドエフェクト"
"enableAudio": "オーバイドエフェクト",
"deleting": "削除中...",
"deleted": "削除に成功しました!",
"deleteError": "削除に失敗しました。もう一度お試しください。",
"importing": "インポート中...",
"imported": "インポートに成功しました!",
"importError": "インポートに失敗しました。もう一度お試しください。",
"createWordList": "単語リストの名前を入力してください:",
"creating": "作成中...",
"created": "作成に成功しました!",
"createError": "作成に失敗しました。もう一度お試しください。",
"removing": "削除中...",
"removed": "削除に成功しました!",
"removeError": "削除に失敗しました。もう一度お試しください。",
"createNewDict": "新しい辞書を作成"
},
"Dict": {
"popular": "トレンド用語",
Expand Down
16 changes: 15 additions & 1 deletion messages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@
"generateError": "生成失败,请重试。",
"autoVoice": "自动朗读",
"showMeaning": "显示释义",
"enableAudio": "启用音效"
"enableAudio": "启用音效",
"deleting": "删除中...",
"deleted": "删除成功!",
"deleteError": "删除失败,请重试。",
"importing": "导入中...",
"imported": "导入成功!",
"importError": "导入失败,请重试。",
"createWordList": "输入词单名称:",
"creating": "创建中...",
"created": "创建成功!",
"createError": "创建失败,请重试。",
"removing": "删除中...",
"removed": "删除成功!",
"removeError": "删除失败,请重试。",
"createNewDict": "新建词单"
},
"Dict": {
"popular": "热门词汇",
Expand Down
Loading

0 comments on commit 3698c5b

Please sign in to comment.