- Install the i18n cli tool.
npm install -g @bretkikehara/i18n-cli
- Generate a Google console service key.
- Enable the Google Sheets or Google Drive APIs.
- Create a project config file.
- On the command line, generate an uploadable CSV.
i18n csv <project>
- Create a Google Sheet that will can be shared.
- Import the CSV into the Google Sheet.
Now the spreadsheet should be ready to generate bundle files.
- Ensure the project's
sheetname
config is the same name as the Google Spreadsheet sheet name. - Ensure config
path
points to your app's localization directory. - Exec
i18n bundles <project>
to create the project's localization bundles. - Ensure that the
react-i18n
module is imported inside your component. - Load you app to see the updates.
All cli configs can be stored inside a .i18nrc
JSON file. The cli will look at the present working directory for the .i18nrc
file. This behavior can be overrided by setting the REACT_I18N
environment.
$ REACT_I18N=/Users/me/.i18nrc i18n [command]
module.exports = (function(env) {
return {
"serviceKey": env.I18N_KEY || `${ env.HOME }/.google/service-key-lang.json`,
"projects": {
"project1": {
"spreadsheetId": "google-sheet-id",
"range": "sheet-name!A1:M1000",
"output": `${ env.HOME }/project-name2/i18n-directory`,
"locales": [
"en-US",
],
"format": "module",
}
}
};
})(process.env);
module.exports = (function(env) {
return {
"serviceKey": env.I18N_KEY || `${ env.HOME }/.google/service-key-lang.json`,
"spreadsheetId": "google-sheet-id",
"output": `${ env.HOME }/project-name/i18n-directory`,
"locales": [
"en-US",
"fr-FR"
],
"format": "module",
"projects": {
// project that pulls from the global configs.
"project1": {
"sheetname": "sheet-name",
"range": "A1:M1000",
},
// project that overrides the global configs.
"project2": {
"serviceKey": `${ env.HOME }/.google/override-service-key-lang.json`,
"spreadsheetId": "override-google-sheet-id",
"sheetname": "sheet-name-2",
"output": `${ env.HOME }/project-name2/i18n-directory/override`,
"locales": [
"jp-JP",
],
"format": "json",
}
}
};
})(process.env);
This command will generate the i18n compatible bundle files. Converts the Google sheets rows into a json
or es5 module
format for you app's consumption.
$ i18n bundles project2
This command will generate a CSV from compatible bundle files. This CSV can be appended to a localization spreadsheet for later consumption using the bundles
command.
$ i18n csv project2
- Create a CSV from existing i18n modules or JSON files
- Download bundles from Google Sheets
- Configure CLI using
.i18nrc
file - Configure multiple projects using 1 Google service account.
- Import existing i18n modules or JSON files into Google Sheets