feat: add i18n with type safety

This commit is contained in:
Sonny
2024-04-30 00:36:13 +02:00
committed by Sonny
parent 31f22d382e
commit 2cc490b611
32 changed files with 706 additions and 30 deletions

9
inertia/types/i18n.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
import 'i18next';
import { resources } from '../i18n';
declare module 'i18next' {
interface CustomTypeOptions {
returnNull: false;
resources: (typeof resources)['fr'];
}
}

24
inertia/types/utils.d.ts vendored Normal file
View File

@@ -0,0 +1,24 @@
type Join<K, P> = K extends string
? P extends string
? `${K}${'' extends P ? '' : '.'}${P}`
: never
: never;
type Paths<T> = T extends object
? {
[K in keyof T]-?: K extends string
? `${K}` | Join<K, Paths<T[K]>>
: never;
}[keyof T]
: '';
type Leaves<T> = T extends object
? {
[K in keyof T]-?: Join<K, Leaves<T[K]>>;
}[keyof T]
: '';
type RemoveSuffix<
Key extends string,
SuffixAfter extends string = '_',
> = Key extends `${infer Prefix}${SuffixAfter}${string}` ? Prefix : Key;