diff --git a/example/app.tsx b/example/app.tsx
index 6937c7d..4865e51 100644
--- a/example/app.tsx
+++ b/example/app.tsx
@@ -41,7 +41,7 @@ export const App = () => {
{{name}}!"
+ "nested": {
+ "welcome": "Willkommen, {{name}}!"
+ }
}
diff --git a/example/locale/en/translation.json b/example/locale/en/translation.json
index 0e347ae..11204cb 100644
--- a/example/locale/en/translation.json
+++ b/example/locale/en/translation.json
@@ -1,3 +1,5 @@
{
- "welcome": "Welcome, {{name}}!"
+ "nested": {
+ "welcome": "Welcome, {{name}}!"
+ }
}
diff --git a/src/trans.tsx b/src/trans.tsx
index d24eeb1..5833a52 100644
--- a/src/trans.tsx
+++ b/src/trans.tsx
@@ -1,27 +1,37 @@
-import type { TFunction, TOptions } from "i18next";
+import type { Namespace, ParseKeys, TFunction, TOptions } from "i18next";
import { type Component, createMemo, type JSX } from "solid-js";
import { useTranslation } from "./use-translation.ts";
export type TransEmbeddedComponent = Component<{ children?: string }>;
-export type TransProps = {
- key: string;
+export type TransProps<
+ Key extends ParseKeys,
+ Ns extends Namespace,
+ KPrefix = undefined,
+ TOpt extends TOptions = TOptions,
+> = {
+ key: Key | Key[];
fallback?: string;
components?: Record;
- replace?: TOptions["replace"];
+ replace?: TOpt["replace"];
- t?: TFunction;
- options?: TOptions;
+ t?: TFunction;
+ options?: TOpt;
};
-export const Trans: Component = (props) => {
+export const Trans = <
+ Key extends ParseKeys,
+ Ns extends Namespace,
+ KPrefix = undefined,
+ TOpt extends TOptions = TOptions,
+>(
+ props: TransProps,
+): JSX.Element => {
const [contextT] = useTranslation(() => props.options?.ns);
const t = ((...args: Parameters) =>
- props.t
- ? props.t(...(args as Parameters))
- : contextT(...(args as Parameters))) as TFunction;
+ props.t ? props.t(...args) : contextT(...args)) as TFunction;
const mergedOptions = createMemo(
(): TOptions => ({