lang support
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { useScopedT } from "@/contexts/I18nContext";
|
||||
import {
|
||||
addCustomFont,
|
||||
type CustomFont,
|
||||
@@ -25,6 +26,8 @@ interface AddCustomFontDialogProps {
|
||||
}
|
||||
|
||||
export function AddCustomFontDialog({ onFontAdded }: AddCustomFontDialogProps) {
|
||||
const t = useScopedT("settings");
|
||||
const tc = useScopedT("common");
|
||||
const [open, setOpen] = useState(false);
|
||||
const [importUrl, setImportUrl] = useState("");
|
||||
const [fontName, setFontName] = useState("");
|
||||
@@ -45,17 +48,17 @@ export function AddCustomFontDialog({ onFontAdded }: AddCustomFontDialogProps) {
|
||||
const handleAdd = async () => {
|
||||
// Validate inputs
|
||||
if (!importUrl.trim()) {
|
||||
toast.error("Please enter a Google Fonts import URL");
|
||||
toast.error(t("customFont.errorEmptyUrl"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidGoogleFontsUrl(importUrl)) {
|
||||
toast.error("Please enter a valid Google Fonts URL");
|
||||
toast.error(t("customFont.errorInvalidUrl"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fontName.trim()) {
|
||||
toast.error("Please enter a font name");
|
||||
toast.error(t("customFont.errorEmptyName"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,7 +68,7 @@ export function AddCustomFontDialog({ onFontAdded }: AddCustomFontDialogProps) {
|
||||
// Extract font family from URL
|
||||
const fontFamily = parseFontFamilyFromImport(importUrl);
|
||||
if (!fontFamily) {
|
||||
toast.error("Could not extract font family from URL");
|
||||
toast.error(t("customFont.errorExtractFailed"));
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
@@ -86,7 +89,7 @@ export function AddCustomFontDialog({ onFontAdded }: AddCustomFontDialogProps) {
|
||||
onFontAdded(newFont);
|
||||
}
|
||||
|
||||
toast.success(`Font "${fontName}" added successfully`);
|
||||
toast.success(t("customFont.successMessage", { fontName }));
|
||||
|
||||
// Reset and close
|
||||
setImportUrl("");
|
||||
@@ -95,10 +98,10 @@ export function AddCustomFontDialog({ onFontAdded }: AddCustomFontDialogProps) {
|
||||
} catch (error) {
|
||||
console.error("Failed to add custom font:", error);
|
||||
const errorMessage = error instanceof Error ? error.message : "Failed to load font";
|
||||
toast.error("Failed to add font", {
|
||||
toast.error(t("customFont.failedToAdd"), {
|
||||
description: errorMessage.includes("timeout")
|
||||
? "Font took too long to load. Please check the URL and try again."
|
||||
: "The font could not be loaded. Please verify the Google Fonts URL is correct.",
|
||||
? t("customFont.errorTimeout")
|
||||
: t("customFont.errorLoadFailed"),
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -114,12 +117,12 @@ export function AddCustomFontDialog({ onFontAdded }: AddCustomFontDialogProps) {
|
||||
className="w-full bg-white/5 border-white/10 text-slate-200 hover:bg-white/10 h-9 text-xs"
|
||||
>
|
||||
<Plus className="w-3 h-3 mr-1" />
|
||||
Add Google Font
|
||||
{t("customFont.dialogTitle")}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="bg-[#1a1a1c] border-white/10 text-slate-200">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Add Google Font</DialogTitle>
|
||||
<DialogTitle>{t("customFont.dialogTitle")}</DialogTitle>
|
||||
<DialogDescription className="text-slate-400">
|
||||
Add a custom font from Google Fonts to use in your annotations.
|
||||
</DialogDescription>
|
||||
@@ -128,34 +131,30 @@ export function AddCustomFontDialog({ onFontAdded }: AddCustomFontDialogProps) {
|
||||
<div className="space-y-4 mt-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="import-url" className="text-slate-200">
|
||||
Google Fonts Import URL
|
||||
{t("customFont.urlLabel")}
|
||||
</Label>
|
||||
<Input
|
||||
id="import-url"
|
||||
placeholder="https://fonts.googleapis.com/css2?family=Roboto&display=swap"
|
||||
placeholder={t("customFont.urlPlaceholder")}
|
||||
value={importUrl}
|
||||
onChange={(e) => handleImportUrlChange(e.target.value)}
|
||||
className="bg-white/5 border-white/10 text-slate-200"
|
||||
/>
|
||||
<p className="text-xs text-slate-400">
|
||||
Get this from Google Fonts: Select a font → Click "Get font" → Copy the @import URL
|
||||
</p>
|
||||
<p className="text-xs text-slate-400">{t("customFont.urlHelp")}</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="font-name" className="text-slate-200">
|
||||
Display Name
|
||||
{t("customFont.nameLabel")}
|
||||
</Label>
|
||||
<Input
|
||||
id="font-name"
|
||||
placeholder="My Custom Font"
|
||||
placeholder={t("customFont.namePlaceholder")}
|
||||
value={fontName}
|
||||
onChange={(e) => setFontName(e.target.value)}
|
||||
className="bg-white/5 border-white/10 text-slate-200"
|
||||
/>
|
||||
<p className="text-xs text-slate-400">
|
||||
This is how the font will appear in the font selector
|
||||
</p>
|
||||
<p className="text-xs text-slate-400">{t("customFont.nameHelp")}</p>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 mt-6">
|
||||
@@ -164,14 +163,14 @@ export function AddCustomFontDialog({ onFontAdded }: AddCustomFontDialogProps) {
|
||||
onClick={() => setOpen(false)}
|
||||
className="bg-white/5 border-white/10 text-slate-200 hover:bg-white/10"
|
||||
>
|
||||
Cancel
|
||||
{tc("actions.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleAdd}
|
||||
disabled={loading}
|
||||
className="bg-blue-600 hover:bg-blue-700 text-white"
|
||||
>
|
||||
{loading ? "Adding..." : "Add Font"}
|
||||
{loading ? t("customFont.addingButton") : t("customFont.addButton")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user