mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-06 13:01:51 +08:00
feat: add English interface localization and fix preview crashes
This commit is contained in:
1 parent
a05a886d3d
commit
9ccaa81497
163 files changed
+17100
-6944
No files matched your search
@@ -3,12 +3,13 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { format, parse } from "date-fns";
|
||||
import { zhCN } from "date-fns/locale/zh-CN";
|
||||
import { CalendarDays, ChevronDown, X } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Calendar } from "@/components/ui/calendar";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { useDateLocale } from "@/i18n/use-date-locale";
|
||||
|
||||
function parseDate(value?: string) {
|
||||
if (!value) return undefined;
|
||||
@@ -20,7 +21,7 @@ export function DateSelect({
|
||||
value,
|
||||
onValueChange,
|
||||
optional = false,
|
||||
placeholder = "选择日期",
|
||||
placeholder,
|
||||
"aria-label": ariaLabel,
|
||||
}: {
|
||||
value?: string;
|
||||
@@ -29,6 +30,8 @@ export function DateSelect({
|
||||
placeholder?: string;
|
||||
"aria-label"?: string;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { dateLocale, datePattern } = useDateLocale();
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const selected = parseDate(value);
|
||||
return (
|
||||
@@ -44,9 +47,9 @@ export function DateSelect({
|
||||
<span className="flex items-center gap-2">
|
||||
<CalendarDays className="size-4 text-muted-foreground" />
|
||||
{selected ? (
|
||||
format(selected, "yyyy年M月d日", { locale: zhCN })
|
||||
format(selected, datePattern, { locale: dateLocale })
|
||||
) : (
|
||||
<span className="text-muted-foreground">{placeholder}</span>
|
||||
<span className="text-muted-foreground">{placeholder ?? t("date.select")}</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
@@ -57,7 +60,7 @@ export function DateSelect({
|
||||
<PopoverContent align="start" className="w-auto overflow-hidden p-0">
|
||||
<Calendar
|
||||
mode="single"
|
||||
locale={zhCN}
|
||||
locale={dateLocale}
|
||||
captionLayout="dropdown"
|
||||
startMonth={new Date(2020, 0, 1)}
|
||||
endMonth={new Date(2100, 11, 31)}
|
||||
@@ -79,7 +82,7 @@ export function DateSelect({
|
||||
}}
|
||||
>
|
||||
<X data-icon="inline-start" />
|
||||
清除日期
|
||||
{t("date.clear")}
|
||||
</Button>
|
||||
)}
|
||||
</PopoverContent>
|
||||
|
||||
Reference in new issue
Block a user