A CLI tool for efficient translation management using Google Sheets, with a focus on developer experience (DX).
- ✨ Initialize CLI configuration for translation workflows.
- 👀 Watch files or directories for changes.
- 📤 Register translation data to Google Sheets.
- 🛠️ Built with TypeScript for type safety.
The traditional process of managing translations with Google Spreadsheets often includes these steps:
- Translator identifies the text to be translated from the page (without developer involvement).
- Translator adds the translation data to a Google Spreadsheet.
- Developer creates a script to locally download the translation data from the sheet.
- Developer inspects the translation data, matches it with the code, and finds the corresponding values in the source code (this can be time-consuming).
- If discrepancies exist between the spreadsheet and the code, developers request changes from the translator.
- Once resolved, the developer applies the translations using an internationalization (intl) library.
- For additional translations, developers manually import and apply them in the code.
- Results are checked on the page, and any errors prompt a repeat of the cycle.
This process is lengthy and redundant. Translators often lack visibility into how text is structured in code, especially when developers split strings, need to insert variables on the text, or add line breaks (<br/>
). As a result, the translation burden falls back to the developers.
This CLI streamlines the process by shifting the focus to developers:
- Developers identify and mark variables or text for translation directly in the code.
- Run the CLI to register changes (it automatically adds translations using Google Translate with support for Google Spreadsheets).
- Translators inspect and refine the translations for improved fluency and meaning on the Google Sheet.
- Developers import the confirmed translation data, completing the process.
With this approach, unnecessary back-and-forth is eliminated, and translations align seamlessly with code.
@sheet-i18n/cli
provides a fully automated setup for React applications.
Once installed, you can bootstrap the required i18n context, store, and folder structure by simply running:
npx sheet-i18n init
This will automatically generate:
- A preconfigured
i18nStore
using@sheet-i18n/react
- A ready-to-use
i18nContext.ts
that exportsIntlProvider
,useTranslation
, andgetTranslation
- Example locale JSON files (e.g.,
en.json
,ko.json
) - The
sheet.config.json
file for managing your CLI behavior and Google Sheets credentials
💡 All files will be created in the recommended structure (e.g.
src/i18n
,src/locales
), and safely skipped if they already exist.
- You don’t need to manually initiate
I18nStore
or set up the React context. - You don’t need to manually prepare locale JSON templates.
- You don’t need to manually configure
sheet.config.json
.
Just run the init command and you’re ready to use useTranslation()
in your components.
📦 your-project/
├── 📄 .gitignore # Automatically appends 'sheet.config.json' to ignore list
├── 📄 sheet.config.json # CLI configuration file (contains Google Sheet credentials & options)
└── 📁 src/
└── 📁 i18n/
├── 📄 i18nContext.tsx # React context for IntlProvider, useTranslation, and getTranslation
├── 📄 i18nStore.ts # Initializes I18nStore with supported locales and translation data
├── 📄 en.json # Placeholder for English translation strings
└── 📄 ko.json # Placeholder for Korean translation strings
✅ The CLI automatically creates this structure after running npx sheet-i18n init
.
🛡️ If sheet.config.json
or src/i18n
already exist, the CLI will skip the creation of these files.
after running npx sheet-i18n init
, you can mount the IntlProvider in your app.
import React from 'react';
import I18nContextProvider from './i18n/i18nContext';
const App = () => {
const [locale, setLocale] = useState('en');
return (
<I18nContextProvider currentLocale={locale}>
<YourComponent />
</I18nContextProvider>
);
};
// YourComponent.tsx
import React from 'react';
import { useTranslation } from './i18n/i18nContext';
const YourComponent = () => {
const { t } = useTranslation('header');
return (
<div>
<button>{t('login')}</button>
<button>{t('logout')}</button>
</div>
);
};
your translations are now ready to use in your application.
The CLI requires a sheet.config.json
file in the root of your project. Run sheet-i18n init
to generate this file automatically.
Example sheet.config.json
:
{
"watchEntry": "src",
"detectExtensions": ["tsx", "ts", "jsx", "js"],
"googleSheetConfig": {
"credentials": {
"sheetId": "YOUR_GOOGLE_SHEET_ID",
"clientEmail": "YOUR_CLIENT_EMAIL",
"privateKey": "YOUR_PRIVATE_KEY"
},
"defaultLocale": "en",
"supportedLocales": ["en", "fr", "es"],
"ignoredSheets": ["BASE"],
"importPath": "./src/locales"
}
}
Option | Type | Required | Description |
---|---|---|---|
watchEntry | string | Entry path to monitor file changes, relative to the current working directory. Default: "src" . |
|
detectExtensions | string[] | List of file extensions to watch. Default: ["jsx", "js", "tsx", "ts"] . |
Option | Type | Required | Description |
---|---|---|---|
credentials.sheetId |
string | ✅ | The same ID as spreadsheetId (for API auth). |
credentials.clientEmail |
string | ✅ | Client email from your Google Service Account credentials. |
credentials.privateKey |
string | ✅ | Private key from your Google Service Account credentials. |
defaultLocale |
string | ✅ | The default language/locale used in the sheet's header row. |
supportedLocales |
string[] | ✅ | Array of all supported locale codes (e.g., ["en", "ko"] ). Default is [defaultLocale] . |
headerStartRowNumber | number | Row number where sheet headers begin. Default: 1 . |
|
ignoredSheets | string[] | Titles of sheets to ignore during register/import (e.g., ["BASE"] ). |
|
importPath | string | Directory path to export translation JSON files. Default is current working directory . |
npx sheet-i18n init
Sets up the sheet.config.json
file in your project. This configuration file is required for all other commands.
npx sheet-i18n watch
Monitors files or directories for changes and logs relevant updates. When watch mode is started, the CLI will detect changes of "useTranslation" and "t" calls of "@sheet-i18n/react" package.
//translationContext.tsx
import { createI18nContext } from 'sheet-i18n/react';
export const { IntlProvider, useTranslation } = createI18nContext(i18nStore);
// Component.tsx
import { useTranslation } from '../translationContext'
...
function Component (){
// The arguments of useTranslation function = sheetTitle
const { t } = useTranslation('environment');
...
// The arguments of t function = translation key
return (
<>
<SettingItem label={t('over')}>
<SettingItem label={t('under')}>
</>
)
}
The watched result is
Detected Translations:
📄 [Sheet Title]: environment
- over
- under
# You can proceed using the shortcuts below:
- Press <Shift + R> to register the detected changes.
- Press <Ctrl + C> to cancel the watch command.
npx sheet-i18n register [options]
Registers translation data to Google Sheets.
-
The
register
command collects the current sheets in Google Spreadsheets. If there are sheets in your local changes that do not exist in the current list, it prompts you to create the missing sheets. -
It updates rows and adds "translation" entries using the
GOOGLETRANSLATE
function supported by Google Spreadsheets for automated translations. -
After registering, it asks whether you want to update the locale JSON data locally. It then exports the JSON data to the
importPath
specified insheet.config.json
(default is the current working directory).
-
-s, --scope <scope>
Define the scope of the registration process:-
diff
: Only scans translation keys that have been modified in the Git history (based ongit diff
). -
total
: Scans the entire directory for all translation keys and updates the spreadsheet, regardless of Git changes. -
select
: User selection mode which allows you to choose the sheets to register.
-
-
Default:
diff
- The CLI identifies changes in translation keys by comparing the current state of the codebase with the latest Git commit.
- It only processes translation keys added, removed, or modified since the last commit.
- This is useful for incremental updates, ensuring only new or updated keys are registered.
# diff is the default scope. So you can omit the --scope option.
npx sheet-i18n register
- The CLI scans the entire specified directory for all translation keys from the directory path you provide.
- This is useful for full synchronization, ensuring all keys are registered in the spreadsheet.
- However, it may take longer to process large directories. So, use with caution.
npx sheet-i18n register --scope total
-
The CLI prompts you to manually select which sheets you want to update.
-
Once the selection is made, only the chosen sheets will have their translation data updated in the Google Spreadsheet.
-
This mode is especially useful for partial updates, allowing you to skip scanning the entire directory and focus on specific sheets.
-
It’s also helpful in cases where you’ve committed changes without registering translation data during development — instead of syncing all translations, you can update only the relevant sheets as needed.
npx sheet-i18n register --scope select
npx sheet-i18n import
Exports translation data from Google Sheets to local export directory.
The configuration of export command is based on sheet.config.json
on your root.
{
"googleSheetConfig": {
"credentials": {
"sheetId": "YOUR_GOOGLE_SHEET_ID",
"clientEmail": "YOUR_CLIENT_EMAIL",
"privateKey": "YOUR_PRIVATE_KEY"
},
"defaultLocale": "The base language of your application in sheet header",
"ignoredSheets": ["BASE"],
"importPath": "The path of export directory of translation data. (default: current working directory)"
}
}