Skip to content

Commit

Permalink
fix autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
eliyya committed Dec 21, 2024
1 parent 5e591b9 commit 9900542
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import i18n from 'i18n'
import { LocaleKeys } from './keys.js'

type NestedKeyOf<T> = {
[K in keyof T]: T[K] extends string
? T[K]
: `${K & string}.${NestedKeyOf<T[K]>}`
}[keyof T]

interface Translate<T extends LocaleKeys = LocaleKeys> {
<K extends keyof T>(phrase: K, options?: T[K]): string
<K extends NestedKeyOf<T>>(
phrase: K,
options?: Record<string, string>,
): string
}
// TODO: Fix the type of the phrase parameter

export function Translator<T extends LocaleKeys = LocaleKeys>(locale: string) {
const translate: Translate<T> = (phrase, options) => {
return i18n.__mf({ phrase: phrase as string, locale }, options)
Expand Down
2 changes: 1 addition & 1 deletion src/keys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface LocaleKeys {
[key: string]: unknown
[key: string]: string | LocaleKeys
}
export default LocaleKeys
export const localeKeys: LocaleKeys = {}
5 changes: 0 additions & 5 deletions t.ts

This file was deleted.

0 comments on commit 9900542

Please sign in to comment.