Recently in my work, the need to include translations to a project built with React arose. I had to investigate and came to this solution, which I think someone might find helpful.
Installation of necessary packages
For the installation of these packages, we will need to have previously installed and configured npm.
Once we have npm installed we must install the following packages:
Create a file where translations will be stored
We will create a folder called translations within src and, within the translations folder, we will create a folder for each language to which we want to add the translations.
./src
./translations
./es
./translations.js
We will create the translation.js file where the translations stored in this case for the Spanish language:
Create the configuration file for i18n
./src
./translations
./i18n.js
with the following content:
Using the hook for translations in component
Thanks for reading me. 😊