-
Notifications
You must be signed in to change notification settings - Fork 6
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
I18N has undefined message prop when rendering server side #3
Comments
I wrote up a unit test that reproduces the failure: zbyte64@1773be8 |
I didn't understand what/why was happening until I saw: So jsxlate wants to rewrite the I18N tag before it gets interpreted. Currently I have a server running with the babel polyfill which can load up JSX directly - that method does not work with jsxlate. Seems I have three options:
|
You are correct. What we do in development mode (generally) is option 3. Here's how we do that: var components = require('jsxlate/lib/components');
if (__DEV__) {
// Simple mock for i18n to avoid parsing i18n stuff
components.i18n = (x) => x;
components.I18N = React.createClass({
render() {
if (React.Children.count(this.props.children) === 1
&& (typeof this.props.children !== 'string')) {
return this.props.children;
} else {
return <span>{this.props.children}</span>;
}
}
});
} When I need to test translations locally, I do modify my require.extensions to preprocess files with jsxlate. |
To use jsxlate with node, I modified the babel/register compiler to allow for an optional preprocessor. Here is the modified compiler: https://gist.github.com/drd/d5a2e225065f525e57d9 And here is how I use it: var compiler = require('./compiler');
var translator = require('jsxlate').translator;
var fs = require('fs');
require.extensions['.js'] = require.extensions['.jsx'] = function(module, filename) {
var src = fs.readFileSync(filename, 'utf-8');
// pass all .jsx files and all .js files not in node_modules through babel
if (filename.match(/jsx$/) || !filename.match(/node_modules/)) {
src = compiler.compile(filename, src, translator.transformMessageNodes);
}
module._compile(src, filename);
} |
TY, That last bit worked for me :) |
I do not understand how/where
props.children
gets converted toprops.message
. When I try rendering from nodejs the I18N component only getsprops.children
.The text was updated successfully, but these errors were encountered: