I would like to create a multilingual app with React.
The way I see it would be to have a js file for each language, for example :
en.js:
module.exports = {
langEnglish: 'English',
langFrench: 'French',
navHome: 'Home',
navUsers: 'Users',
...
};
fr.js:
module.exports = {
langEnglish: 'Anglais',
langFrench: 'Français',
navHome: 'Accueil',
navUsers: 'Utilisateurs',
...
};
As each language file will be quite big and there could be dozens of different languages supported, I would prefer to download only the correct file to use depending on the language chosen in order to minimize loading time (and bandwidth usage).
For example I could have a variable in the app state
var App = React.createClass({
getInitialState: function () {
return {
lang: 'en'
};
},
...
and some user control to switch this variable between fr and en.
Is it possible to load only the en.js file on the initial load, and if the user switches the language to French then load and use the fr.js file instead and so on for each language?