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

typesafe translate? #407

Closed
rainmanhhh opened this issue Mar 23, 2021 · 3 comments · Fixed by #489
Closed

typesafe translate? #407

rainmanhhh opened this issue Mar 23, 2021 · 3 comments · Fixed by #489
Labels
Status: Proposal Request for comments Type: Improvement Includes backwards-compatible fixes

Comments

@rainmanhhh
Copy link

key of t() is a string (eg.: t('foo.bar'))
I can get message functions by useI18n().locale.messages (eg.: foo.bar in which bar is a function)
Is it possible to translate like

const msgFunc = useI18n().locale.messages
msgFunc.foo.bar() // how to get context?

or

const msgFunc = useI18n().locale.messages
trans(msgFunc.foo.bar) // how to get context?
@rainmanhhh rainmanhhh added the Status: Proposal Request for comments label Mar 23, 2021
@kazupon
Copy link
Member

kazupon commented Mar 23, 2021

Thank you for your feedback.

Unfortunately, We doesn’t allow to use directly Message functions in VueI18n 😞
It's designed to be used with the VueI18n runtime in mind.

I would like to know more about why you want to call and translate directly.
I'd like to know more about it for future reference, if you don't mind. 🙏

@kazupon kazupon removed the Status: Proposal Request for comments label Mar 23, 2021
@rainmanhhh
Copy link
Author

because I want make my app typesafe. t('foo.bar') is obviously not (no auto-completion in IDE and no compile error if I pass a wrong key)

@kazupon
Copy link
Member

kazupon commented Mar 24, 2021

Thank you for your reply!

You are right, vue-i18n still needs to be improved for typescript.
I’ll improve the typesafe (auto complition) in key parameter in the future.

I'll also improve around the type parameter.
#382

@kazupon kazupon added Priority: Medium Type: Improvement Includes backwards-compatible fixes Status: Proposal Request for comments labels Mar 24, 2021
@kazupon kazupon mentioned this issue May 2, 2021
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Proposal Request for comments Type: Improvement Includes backwards-compatible fixes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants