-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Type-safe translations do not work with keyPrefix #1387
Comments
I wasn't aware of such feature. |
We also need to take into consideration the increase in compilation time with the implementation of |
If this will not be implemented, then what are the alternatives to keep typecheck happy (if I'm indeed using the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This would be really helpful – commenting so this doesn't go stale |
I'll be taking a look, and measuring the compilation time. For now, the workaround is this: const b = useTranslation('translation');
b.t('home.admin_settings');
// or
const b = useTranslation('translation');
const keyPrefix = 'home' as const;
b.t(`${keyPrefix}.admin_settings`); |
Same issue here, it would be excellent to have that. |
Throwing my name in the hat as another dev that would love this fix 🙏 Thank you for working on this! |
I'll have a PR ready by end of the week, hopefully compilation time won't be affected much 🤞 |
Should we wait for the other PR before releasing a new version? |
yeah, we can hold off this one for now |
fixed in v11.13.0 |
Thank you very much for your help @pedrodurek |
No problem 😄 |
It works as expected! Thanks, @pedrodurek |
Thanks! Just one case: for me it only works if keyPrefix is without a dot, I mean the following still errors: // you can define a keyPrefix to be used for the resulting t function
const { t } = useTranslation('translation', { keyPrefix: 'very.deeply.nested' });
const text = t('key'); // "here" (example is from documentation) |
You are right @Shaddix, it would be great to also support nested key-prefixes. |
I'll look into it |
@adrai could you please reopen the issue? Or should I create a separate one regarding nested keyPrefixes? |
@pedrodurek what do you prefer? |
I'm working on it, we can reopen for now |
after update from 11.12.0 to 11.13.0, typescript auto complete stop working. |
🐛 Bug Report
After setting up a type-safe translations and having a translation file like
To Reproduce
The following thing works (and compiles)
But the following doesn't compile (typescript complains)
Expected behavior
The latter examples compiles without errors
Your Environment
The text was updated successfully, but these errors were encountered: