feat: support i18n namespace

This commit is contained in:
ReaJason
2025-08-13 23:53:40 +08:00
parent a5f6411444
commit 3f5a2ddb6b
41 changed files with 987 additions and 663 deletions
@@ -17,8 +17,11 @@ import { UrlPatternFormField } from "./urlpattern-field";
export function AntSwordTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<MemShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
}: Readonly<{
form: UseFormReturn<MemShellFormSchema>;
shellTypes: Array<string>;
}>) {
const { t } = useTranslation(["memshell", "common"]);
return (
<FormProvider {...form}>
<TabsContent value="AntSword">
@@ -34,9 +37,12 @@ export function AntSwordTabContent({
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.antSwordPass")} {t("optional")}
{t("shellToolConfig.antSword.pass")} {t("common:optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -46,9 +52,12 @@ export function AntSwordTabContent({
name="headerName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.headerName")}</FormFieldLabel>
<FormFieldLabel>{t("common:headerName")}</FormFieldLabel>
<FormControl>
<Input {...field} placeholder={t("placeholders.input")} />
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormControl>
</FormFieldItem>
)}
@@ -59,9 +68,12 @@ export function AntSwordTabContent({
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.headerValue")} {t("optional")}
{t("common:headerValue")} {t("common:optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -12,8 +12,11 @@ import { UrlPatternFormField } from "./urlpattern-field";
export function BehinderTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<MemShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
}: Readonly<{
form: UseFormReturn<MemShellFormSchema>;
shellTypes: Array<string>;
}>) {
const { t } = useTranslation(["memshell", "common"]);
return (
<FormProvider {...form}>
<TabsContent value="Behinder">
@@ -29,9 +32,12 @@ export function BehinderTabContent({
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.behinderPass")} {t("optional")}
{t("shellToolConfig.behinder.pass")} {t("common:optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -41,8 +47,11 @@ export function BehinderTabContent({
name="headerName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.headerName")}</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<FormFieldLabel>{t("common:headerName")}</FormFieldLabel>
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -52,9 +61,12 @@ export function BehinderTabContent({
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.headerValue")} {t("optional")}
{t("common:headerValue")} {t("common:optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -11,11 +11,11 @@ import {
import { Input } from "@/components/ui/input.tsx";
import type { MemShellFormSchema } from "@/types/schema.ts";
export function OptionalClassFormField({ form }: Readonly<{ form: UseFormReturn<MemShellFormSchema> }>) {
const { t } = useTranslation();
export function OptionalClassFormField({
form,
}: Readonly<{ form: UseFormReturn<MemShellFormSchema> }>) {
const { t } = useTranslation(["memshell", "common"]);
const [showAdvanced, setShowAdvanced] = useState(false);
const shellClassNameId = useId();
const injectClassNameId = useId();
return (
<Fragment>
<div className="pt-2">
@@ -28,7 +28,11 @@ export function OptionalClassFormField({ form }: Readonly<{ form: UseFormReturn<
>
<Settings className="h-4 w-4" />
{t("classNameOptions")}
{showAdvanced ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}
{showAdvanced ? (
<ChevronUp className="h-4 w-4" />
) : (
<ChevronDown className="h-4 w-4" />
)}
</Button>
</div>
{showAdvanced && (
@@ -38,10 +42,14 @@ export function OptionalClassFormField({ form }: Readonly<{ form: UseFormReturn<
name="shellClassName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel htmlFor={shellClassNameId}>
{t("mainConfig.shellClassName")} {t("optional")}
<FormFieldLabel htmlFor="shellClassName">
{t("mainConfig.shellClassName")} {t("common:optional")}
</FormFieldLabel>
<Input id={shellClassNameId} {...field} placeholder={t("placeholders.input")} />
<Input
id="shellClassName"
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -50,10 +58,14 @@ export function OptionalClassFormField({ form }: Readonly<{ form: UseFormReturn<
name="injectorClassName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel htmlFor={injectClassNameId}>
{t("mainConfig.injectorClassName")} {t("optional")}
<FormFieldLabel htmlFor="injectClassName">
{t("mainConfig.injectorClassName")} {t("common:optional")}
</FormFieldLabel>
<Input id={injectClassNameId} {...field} placeholder={t("placeholders.input")} />
<Input
id="injectClassName"
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -26,9 +26,15 @@ import { UrlPatternFormField } from "./urlpattern-field";
export function CommandTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<MemShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
const { data } = useQuery<{ encryptors: Array<string>; implementationClasses: Array<string> }>({
}: Readonly<{
form: UseFormReturn<MemShellFormSchema>;
shellTypes: Array<string>;
}>) {
const { t } = useTranslation(["memshell", "common"]);
const { data } = useQuery<{
encryptors: Array<string>;
implementationClasses: Array<string>;
}>({
queryKey: ["commandConfigs"],
queryFn: async () => {
const response = await fetch(`${env.API_URL}/config/command/configs`);
@@ -51,10 +57,13 @@ export function CommandTabContent({
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.paramName")} {t("optional")}
{t("common:paramName")} {t("common:optional")}
</FormFieldLabel>
<FormControl>
<Input {...field} placeholder={t("placeholders.input")} />
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormControl>
</FormFieldItem>
)}
@@ -65,11 +74,17 @@ export function CommandTabContent({
name="encryptor"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.encryptor")}</FormFieldLabel>
<Select onValueChange={field.onChange} value={field.value} defaultValue="RAW">
<FormFieldLabel>{t("common:encryptor")}</FormFieldLabel>
<Select
onValueChange={field.onChange}
value={field.value}
defaultValue="RAW"
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder={t("placeholders.select")} />
<SelectValue
placeholder={t("common:placeholders.select")}
/>
</SelectTrigger>
</FormControl>
<SelectContent>
@@ -88,11 +103,19 @@ export function CommandTabContent({
name="implementationClass"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.implementationClass")}</FormFieldLabel>
<Select onValueChange={field.onChange} value={field.value} defaultValue="RuntimeExec">
<FormFieldLabel>
{t("common:implementationClass")}
</FormFieldLabel>
<Select
onValueChange={field.onChange}
value={field.value}
defaultValue="RuntimeExec"
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder={t("placeholders.select")} />
<SelectValue
placeholder={t("common:placeholders.select")}
/>
</SelectTrigger>
</FormControl>
<SelectContent>
+20 -11
View File
@@ -22,10 +22,12 @@ import { UrlPatternFormField } from "./urlpattern-field";
export default function CustomTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<MemShellFormSchema>; shellTypes: Array<string> }>) {
}: Readonly<{
form: UseFormReturn<MemShellFormSchema>;
shellTypes: Array<string>;
}>) {
const [isFile, setIsFile] = useState(false);
const optionOneId = useId();
const optionTwoId = useId();
const { t } = useTranslation(["memshell", "common"]);
return (
<FormProvider {...form}>
<TabsContent value="Custom">
@@ -40,7 +42,7 @@ export default function CustomTabContent({
name="shellClassBase64"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.base64String")}</FormFieldLabel>
<FormFieldLabel>{t("shellClass")}</FormFieldLabel>
<RadioGroup
value={isFile ? "file" : "base64"}
onValueChange={(value) => {
@@ -50,12 +52,12 @@ export default function CustomTabContent({
className="flex items-center space-x-2"
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="base64" id={optionOneId} />
<Label htmlFor={optionOneId}>Base64</Label>
<RadioGroupItem value="base64" id="optionOne" />
<Label htmlFor="optionOne">Base64</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="file" id={optionTwoId} />
<Label htmlFor={optionTwoId}>File</Label>
<RadioGroupItem value="file" id="optionTwo" />
<Label htmlFor="optionTwo">File</Label>
</div>
</RadioGroup>
<FormControl className="mt-2">
@@ -66,18 +68,25 @@ export default function CustomTabContent({
if (file) {
const reader = new FileReader();
reader.onload = (event) => {
const base64String = (event.target?.result as string)?.split(",")[1] || "";
const base64String =
(event.target?.result as string)?.split(
",",
)[1] || "";
field.onChange(base64String);
};
reader.readAsDataURL(file);
}
}}
accept=".class"
placeholder={t("placeholders.input")}
placeholder={t("common:placeholders.input")}
type="file"
/>
) : (
<Textarea {...field} placeholder={t("placeholders.input")} className="h-24" />
<Textarea
{...field}
placeholder={t("common:placeholders.input")}
className="h-24"
/>
)}
</FormControl>
<FormMessage />
@@ -12,8 +12,11 @@ import { UrlPatternFormField } from "./urlpattern-field";
export function GodzillaTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<MemShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
}: Readonly<{
form: UseFormReturn<MemShellFormSchema>;
shellTypes: Array<string>;
}>) {
const { t } = useTranslation(["memshell", "common"]);
return (
<FormProvider {...form}>
<TabsContent value="Godzilla">
@@ -30,9 +33,13 @@ export function GodzillaTabContent({
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.pass")} {t("optional")}
{t("shellToolConfig.godzilla.pass")}{" "}
{t("common:optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -42,9 +49,12 @@ export function GodzillaTabContent({
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.key")} {t("optional")}
{t("shellToolConfig.godzilla.key")} {t("common:optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -53,8 +63,11 @@ export function GodzillaTabContent({
name="headerName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.headerName")}</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<FormFieldLabel>{t("common:headerName")}</FormFieldLabel>
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -64,9 +77,12 @@ export function GodzillaTabContent({
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.headerValue")} {t("optional")}
{t("common:headerValue")} {t("common:optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -12,8 +12,11 @@ import { UrlPatternFormField } from "./urlpattern-field";
export function NeoRegTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<MemShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
}: Readonly<{
form: UseFormReturn<MemShellFormSchema>;
shellTypes: Array<string>;
}>) {
const { t } = useTranslation(["memshell", "common"]);
return (
<FormProvider {...form}>
<TabsContent value="NeoreGeorg">
@@ -29,8 +32,11 @@ export function NeoRegTabContent({
name="headerName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.headerName")}</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<FormFieldLabel>{t("common:headerName")}</FormFieldLabel>
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -40,9 +46,12 @@ export function NeoRegTabContent({
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.headerValue")} {t("optional")}
{t("common:headerValue")} {t("common:optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -18,8 +18,11 @@ import type { MemShellFormSchema } from "@/types/schema.ts";
export function ShellTypeFormField({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<MemShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
}: Readonly<{
form: UseFormReturn<MemShellFormSchema>;
shellTypes: Array<string>;
}>) {
const { t } = useTranslation(["memshell", "common"]);
return (
<FormProvider {...form}>
<FormField
@@ -37,7 +40,7 @@ export function ShellTypeFormField({
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder={t("placeholders.select")} />
<SelectValue placeholder={t("common:placeholders.select")} />
</SelectTrigger>
</FormControl>
<SelectContent key={shellTypes?.join(",")}>
@@ -48,7 +51,9 @@ export function ShellTypeFormField({
</SelectItem>
))
) : (
<SelectItem value=" ">{t("tips.shellToolNotSelected")}</SelectItem>
<SelectItem value=" ">
{t("tips.shellToolNotSelected")}
</SelectItem>
)}
</SelectContent>
</Select>
+15 -6
View File
@@ -12,8 +12,11 @@ import { UrlPatternFormField } from "./urlpattern-field";
export function Suo5TabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<MemShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
}: Readonly<{
form: UseFormReturn<MemShellFormSchema>;
shellTypes: Array<string>;
}>) {
const { t } = useTranslation(["memshell", "common"]);
return (
<FormProvider {...form}>
<TabsContent value="Suo5">
@@ -29,8 +32,11 @@ export function Suo5TabContent({
name="headerName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.headerName")}</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<FormFieldLabel>{t("common:headerName")}</FormFieldLabel>
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -40,9 +46,12 @@ export function Suo5TabContent({
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.headerValue")} {t("optional")}
{t("common:headerValue")} {t("common:optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<Input
{...field}
placeholder={t("common:placeholders.input")}
/>
</FormFieldItem>
)}
/>
@@ -10,8 +10,10 @@ import { Input } from "@/components/ui/input.tsx";
import { shouldHidden } from "@/lib/utils";
import type { MemShellFormSchema } from "@/types/schema.ts";
export function UrlPatternFormField({ form }: Readonly<{ form: UseFormReturn<MemShellFormSchema> }>) {
const { t } = useTranslation();
export function UrlPatternFormField({
form,
}: Readonly<{ form: UseFormReturn<MemShellFormSchema> }>) {
const { t } = useTranslation("common");
const shellType = form.watch("shellType");
return (
<FormProvider {...form}>
@@ -19,8 +21,10 @@ export function UrlPatternFormField({ form }: Readonly<{ form: UseFormReturn<Mem
control={form.control}
name="urlPattern"
render={({ field }) => (
<FormFieldItem className={shouldHidden(shellType) ? "hidden" : "grid"}>
<FormFieldLabel>{t("mainConfig.urlPattern")}</FormFieldLabel>
<FormFieldItem
className={shouldHidden(shellType) ? "hidden" : "grid"}
>
<FormFieldLabel>{t("urlPattern")}</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<FormMessage />
</FormFieldItem>