I recently started responding to React js and they started to like it.
There is one logic with which I am stuck.
My site is multilingual and I have problems displaying strings.
So, I was thinking of placing an attribute data-translatefor id or classes, but still not suitable.
This is just a basic example of my logic.
Js reaction
var counter = document.getElementById('counter').getAttribute('data-translate');
var Timer = React.createClass({
getInitialState: function() {
return {secondsElapsed: 0};
},
tick: function() {
this.setState({secondsElapsed: this.state.secondsElapsed + 1});
},
componentDidMount: function() {
this.interval = setInterval(this.tick, 1000);
},
componentWillUnmount: function() {
clearInterval(this.interval);
},
render: function() {
return (
<div className={this.translate}>{counter} {this.state.secondsElapsed}</div>
);
}
});
React.renderComponent(
<Timer />,
document.getElementById('counter')
);
HTML
<div id="counter" data-translate="{{ trans('stream.counter') }}"></div>
So itโs not a good idea.
Can someone give me a hint?
user1130272
source
share