-
Notifications
You must be signed in to change notification settings - Fork 37
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
Decorators #28
Comments
Hi, It is true that decorators are not supported. I thought of decorators while implementing That being said, I'm opened to contributions adding support for decorators. If you want to make a PR, I'm unsure whether decorators are properly typed in Babel, but I think it is acceptable to type them as any if we don't have a better alternative. Secondly, if I remember correctly, decorators are known to cause problems regarding exports. In your example you use the legacy mode, but I think we should support both legacy mode and the mode that fixes the export problem. You may find useful to experiment with ASTExplorer which uses the non-legacy mode. Note that this is not the only issue with Let me know if you need any further information or help. |
As a workaround, if your only goal is to get your translation keys to be extracted, you could very well go like this: import { withTranslation } from 'react-i18next';
@withTranslation()
export default class Login extends React.Component {
render() {
const t = this.props.t;
return <span>{t("string")}</span>
}
} You would loose namespace parsing from class _Login extends React.Component {
render() {
return <span>{this.props.t("string")}</span>
}
}
export default withTranslation()(_Login); |
@gilbsgilbs Thank you so much about the replies. I think you right about decorators is a bit of a mess (but it will be great one day, will revisit when it hits stage 3). The above solution is great, thats the perfect shortcut for me. |
Thanks for replying. I'm reopening in order to keep track on improvements regarding decorators. |
I have been trying to make the
babel-plugin-i18next-extract
work on code thats usingdecorators.
I got the following .babelrc using
@babel/plugin-proposal-decorators
The
babel-plugin-i18next-extract
fails to pick up anything that contains a@withTranslation
it seemsWanted to hear if anybody got any ideas, how to bring that to work?
The text was updated successfully, but these errors were encountered: