Tooling · Spreadsheets
From a translation spreadsheet to next-intl
Translations often live in one big Excel workbook, with a sheet per screen and a column per language. xlsx-sheet-lists-downloader is a set of small Bun scripts that split that workbook into files, turn the sheets into next-intl message JSON, check for gaps, and copy the result into your app.
github.com/sawissac/xlsx-sheet-lists-downloaderThe problem
On a multilingual project, the source of truth for copy is rarely the codebase. It's a spreadsheet the client or translators own: one sheet per screen, a column of keys, and a column for each language. Every time it changes, someone has to get those cells into the messages/en.json, messages/ja.json and friends that next-intl reads.
Doing that by hand is slow and easy to get wrong: a key pasted twice, a Thai cell left empty, a sheet forgotten. This repo turns it into four commands you can run in one line.
The pipeline
| Step | Command | What it does |
|---|---|---|
| 1 | bun run split | Splits every sheet of a workbook into its own xlsx, CSV or JSON |
| 2 | bun run next-intl | Turns a folder of CSVs into one message file per language |
| 3 | bun run next-intl-check | Reports duplicate keys and missing translations, writes nothing |
| 4 | bun run paste | Copies the generated files into another project |
Each step is its own script, so you can use the splitter alone for any workbook, not just translations.
Step 1: split the workbook
bun run split report.xlsxThat writes one .xlsx per sheet into ./report/. Pick another format, only some sheets, or another folder:
# list the sheets first
bun run split report.xlsx --list
# two sheets as CSV into ./csv/
bun run split report.xlsx -f csv -s Users -s Orders -o csv| Option | Description |
|---|---|
-o, --out <dir> | Output folder (default: ./<workbook-name>/) |
-f, --format <fmt> | xlsx (default), csv or json |
-s, --sheet <name> | Only export this sheet; repeat for several |
-l, --list | Print the sheet names and exit |
Sheet names become file names, so characters that aren't allowed in paths (\ / : * ? " < > |) are replaced with _. Asking for a sheet that doesn't exist stops the run with the missing names instead of quietly exporting the rest.
JSON output is one object per row, keyed by the header, with empty cells written as null rather than dropped.
Step 2: build next-intl messages
The translation sheets, now CSVs, share a shape: one column holds the key, the others hold a language each. A small config file says which is which.
bun run next-intl-init ./output/csvPass the CSV folder and it reads the first CSV's header to pre-fill the config: the first column becomes the key, the rest become languages, and it guesses a locale code for common names (Japanese → ja, Thai → th, Myanmar (Burmese) → my).
import { defineConfig } from "./src/next-intl/config";
export default defineConfig({
key: {
name: "Lang Key",
targetText: "",
replaceText: "",
},
language: [
{ name: "Lang Value", as: "en" },
{ name: "Japanese", as: "ja" },
{ name: "Thai", as: "th" },
],
defaultLanguage: "en",
});as is the output file name. targetText and replaceText are a find-and-replace applied to every key, for when the sheet's keys use a prefix your app doesn't. defaultLanguage is the fallback: a cell left empty reuses that language's value for the same row, so the app shows English instead of a blank.
Then build:
bun run next-intl ./output/csv -o ./output/next-intlEvery CSV in the folder is merged, and one file per language lands in ./output/next-intl/csv_nextintl/<as>.json. Dotted keys are nested the way next-intl expects:
{
"auth": {
"password_forget": "Forgot password?"
}
}Two flags change the shape:
--no-nestedkeeps keys flat:{ "auth.password_forget": "Forgot password?" }.--no-combined-filewrites one file per CSV per language instead of merging, soAuth Screen.csvbecomesen/auth_screen.json,ja/auth_screen.json, and so on.
Real sheets are messy, and the build is written for that. Header cells are trimmed, because "Lang Value " with a trailing space is common. Rows whose key isn't a dotted identifier (a section title like "Header, Draft State", or a — placeholder) are skipped and counted. A CSV missing one of the configured columns is warned about and skipped rather than breaking the run, and a key that collides with an existing namespace (a.b when a.b.c is already there) is reported instead of overwriting it.
Step 3: check before you ship
A spreadsheet can't tell you that two rows share a key, or that half the Thai column is still empty. The check command can:
bun run next-intl-check ./output/csvIt reads the same CSVs and config as the build, writes nothing, and sorts every problem into one of three buckets:
- duplicate: the key appears in more than one row. At build time the last one wins, silently.
- empty: the cell is blank and there's nothing to fall back to, so
""will be written. - default: the cell is blank but
defaultLanguagehas a value, so that will be used.
5 key(s) in 6 row(s) from 2 csv file(s) — fallback: en ("Lang Value")
✗ 1 duplicate key(s) — the last occurrence wins
home.title a.csv → b.csv
✗ en 5/6 filled, 1 empty
empty about.title (a.csv)
✗ ja 4/6 filled, 1 from default, 1 empty
empty about.title (a.csv)
default home.sub (a.csv)
! th 3/6 filled, 3 from default
default home.sub (a.csv)
default about.body (a.csv)
default contact.title (b.csv)Empty cells are listed first, since those are the ones a translator needs to fill. It exits with 1 when any cell would be written empty, so it works as a CI gate in front of the build. Add --strict to also fail on cells filled from the default language, -S for counts only, or -n 0 to list every key instead of the first 20.
Step 4: paste into the app
The last step is getting the files where the app reads them. A second config lists folders to copy and where:
import { defineConfig } from "./src/copy/config";
export default defineConfig([
{
targetPath: "../my-next-app/messages",
copyFolder: "./output/next-intl/csv_nextintl",
},
]);bun run pasteThe contents of each copyFolder go into its targetPath, so csv_nextintl/en.json lands at messages/en.json. The target folder is created if needed; files with the same name are overwritten and anything else there is left alone. .DS_Store and Thumbs.db never make it across. Relative paths resolve from the config file, not from wherever you ran the command.
All of it in one line
Put together, updating an app's translations from the latest workbook is a single command:
bun run split ./input/localization.xlsx -f csv -o ./output/csv \
&& bun run next-intl ./output/csv -o ./output/next-intl --no-nested --no-combined-file \
&& bun run pasteDrop next-intl-check in front of the build if you want it to stop on missing translations.
Under the hood
| Layer | Tech |
|---|---|
| Runtime | Bun, with TypeScript run directly, no build step |
| Spreadsheets | SheetJS (xlsx 0.20.3, installed from the SheetJS CDN) |
| Arguments | parseArgs from node:util |
| Config | Plain .ts files with a typed defineConfig helper |
SheetJS is installed from its own CDN rather than npm, because the copy on the npm registry is no longer kept up to date. The config files are TypeScript and are loaded with a dynamic import, so you get type checking and autocomplete while editing them.
Run it yourself
git clone https://github.com/sawissac/xlsx-sheet-lists-downloader.git
cd xlsx-sheet-lists-downloader
bun install
bun run split path/to/workbook.xlsx --listEvery command takes -h for its full options.
The splitter started as a way to stop exporting sheets one at a time from Excel, and grew into the whole route from a translator's spreadsheet to a running app. The source is on GitHub.