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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TypeScript #4

Closed
dsonet opened this issue May 23, 2022 · 7 comments
Closed

Support TypeScript #4

dsonet opened this issue May 23, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@dsonet
Copy link

dsonet commented May 23, 2022

馃殌 Feature Proposal

Ref:
When I use i18next react, it supports TypeScript. Could this vue version also add TypeScript support for the $t interface?

https://react.i18next.com/latest/typescript

Motivation

Add translation key validation/auto-completion support during dev.

Example

//similar usage as react version.
const { t } = useTranslation('settings')//namespace support, load namespace if it's not loaded

t('TranslationKey')//can be validated by TypeScript

@adrai adrai added the enhancement New feature or request label May 30, 2022
@kkuegler
Copy link
Member

The type definitions used by react-i18next are quite lengthy and complex, and that's not something I'd like to duplicate and maintain separately for i18next-vue.

There seem to be efforts of extracting the types to the core library, see i18next/i18next#1504.
When that works out, I think using (and possibly slightly augmenting) the types sounds like a good idea.

@adrai
Copy link
Member

adrai commented Jul 14, 2022

@pedrodurek interesting... also others are looking for it 馃槈

@kendallroth
Copy link

It looks like the linked issue has been merged; is this something that could be re-evaluated at this point?

@adrai
Copy link
Member

adrai commented Dec 16, 2022

i18next/i18next#1884

@kkuegler
Copy link
Member

I look into this in the near future and see how to integrate the types best.

We'll probably not publish a new version with this right away, but wait a bit for the "dust to settle". As @adrai's linked ticket shows, there are still quite some type-related changes and fixes going on in i18next itself.

@kkuegler
Copy link
Member

We plan to include this in i18next-vue v3. In fact, you can try it in the alpha version already: https://github.com/i18next/i18next-vue/releases/tag/v3.0.0-alpha.0

The syntax is like in your example

const { t } = useTranslation('settings');

This should work as good as the types for i18next.getFixedT().

See #16 for other changes planned for version 3.

@kkuegler
Copy link
Member

As outlined above, this is implemented in v3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants