I was wondering if setState
is a good way of changing language on a web page. To be more precise, I have a form and I want to allow the user to toggle between two languages, let's say "EN" and "FR". I created two buttons for each language, and passed two different functions for the onClick
event which changes the state:
this.state = {
message : "Hello"
}
setState
handleEN() {
this.setState(
message : "Hello"
)}
handleFR() {
this.setState(
message : "Bonjour"
)}
The buttons:
<button onClick={this.handleEN}> EN </button>
<button onClick={this.handleFR}> FR </button>
Display:
<h1> {this.state.message} </h1>
I already can see a problem with this method since I have to change state to English even though the initial state was "hello". I've read about the react-intl
and i18n
libraries, but I would like to hear which route I should go regarding page translation and why.