Skip to content

Commit

Permalink
fix(i18n): add source type interface (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdehaven authored Mar 9, 2023
1 parent 9e1e1a7 commit ead9661
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/core/i18n/sandbox/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import english from './locales/en.json'
const i18n = useI18n()
// this creates local i18n and component
const i18nLocal = createI18n('en-us', english)
const i18nLocal = createI18n<typeof english>('en-us', english)
const i18nNoPlugin = i18nTComponent(i18nLocal)
</script>
2 changes: 1 addition & 1 deletion packages/core/i18n/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const intlCache = createIntlCache()
// this is global var to hold global (application) instance of Intl
let globIntl: IntlShapeEx

export const createI18n = (locale: SupportedLocales, messages: Record<string, any>, isGlobal: boolean = false): IntlShapeEx => {
export const createI18n = <T>(locale: SupportedLocales, messages: T, isGlobal: boolean = false): IntlShapeEx<T> => {
const intl = createIntl(
{
locale,
Expand Down
10 changes: 5 additions & 5 deletions packages/core/i18n/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export type MessageFormatPrimitiveValue = string | number | boolean | null | und

export type SupportedLocales = 'en-us'

export type IntlShapeEx = IntlShape & {
t: (translationKey: string, values?: Record<string, MessageFormatPrimitiveValue> | undefined, opts?: IntlMessageFormatOptions) => string,
te: (translationKey: string) => boolean,
tm: (translationKey: string) => Array<string>,
source: Record<string, any>,
export type IntlShapeEx<T = any> = IntlShape & {
t: (translationKey: string, values?: Record<string, MessageFormatPrimitiveValue> | undefined, opts?: IntlMessageFormatOptions) => string
te: (translationKey: string) => boolean
tm: (translationKey: string) => Array<string>
source: T
}

0 comments on commit ead9661

Please sign in to comment.