Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing composer instance to Translation component #453

Merged
merged 6 commits into from
Apr 14, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/vue-i18n/src/components/Translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export interface TranslationProps extends BaseFormatProps {
* The Plural Choosing the message number prop
*/
plural?: number | string
/**
* @remarks
* An existing i18n Composer instance to use for translating
*/
i18n?: Composer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this issue is not only with the Translation component but also with the DatetimeFormat and NumberFormat components.

I hope that you could define it to BaseFormatProps interface and baseFormatProps prop.
https://github.com/intlify/vue-i18n-next/blob/master/packages/vue-i18n/src/components/base.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! 😃

}

/**
Expand Down Expand Up @@ -91,15 +96,17 @@ export const Translation = {
type: [Number, String],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
validator: (val: any): boolean => isNumber(val) || !isNaN(val)
}
},
i18n: { type: Object }
},
baseFormatProps
),
/* eslint-enable */
setup(props: TranslationProps, context: SetupContext): RenderFunction {
const { slots, attrs } = context
const i18n = useI18n({ useScope: props.scope }) as Composer &
ComposerInternal
const i18n =
props.i18n ||
(useI18n({ useScope: props.scope }) as Composer & ComposerInternal)
const keys = Object.keys(slots).filter(key => key !== '_')

return (): VNodeChild => {
Expand Down