This script, originally shared by born2net (#261), reads the en.json translation file and generates localized translation files for various languages. The script utilizes Google Translate to automatically populate translations and saves them as JSON files in your projectโs i18n directory.
Steps to Use:
1
Install google-translate package
pnpmaddgoogle-translate
yarnaddgoogle-translate
npmigoogle-translate
2
Uncomment createLocalFiles() once to generate all necessary files (e.g., he.json, ca.json, etc.)
3
Comment or delete createLocalFiles() once the files have been created.
4
Set your Google API key in process.env.GOOGLE_KEY
5
Run the provided script to populate translations. Re-run it whenever you update your en.json
When you run this script, it will generate or update translation files for each specified language based on the English en.json file. The translations will be fetched from Google Translate and added to the corresponding localized JSON file.