This guide explains how to add new language translations to the application.
-
Create the translation file
- Copy
locales/en.jsontolocales/{lang}.json - Replace
{lang}with your ISO 639-1 language code
- Copy
-
Translate all strings
- Translate every string in the JSON file
- Keep the same JSON structure
- Don't change the keys, only the values
-
Import the locale in client-side i18n
- Open
helpers/i18n.tsx - Add import:
import {lang} from '../locales/{lang}.json' - Add to
localesobject:{lang}: {lang}
- Open
-
Import the locale in server-side i18n
- Open
helpers/i18n-server.ts - Add import:
import {lang} from '../locales/{lang}.json' - Add to
localesobject:{lang}: {lang}
- Open
-
Test
- Restart dev server
- Test API:
curl "localhost:3000/api?lang={lang}" - Test UI: Change language in footer dropdown
-
Create the translation file
- Copy the base language file (e.g.,
locales/es.json) - Name it
locales/{lang}-{REGION}.json - Use uppercase for region code
- Copy the base language file (e.g.,
-
Customize translations
- Modify strings to use regional slang, terms, or cultural references
- Keep the same JSON structure
-
Import the locale in client-side i18n
- Open
helpers/i18n.tsx - Add import:
import {langREGION} from '../locales/{lang}-{REGION}.json' - Add to
localesobject:'{lang}-{REGION}': {langREGION} - Note: Use quotes for keys with hyphens
- Open
-
Import the locale in server-side i18n
- Open
helpers/i18n-server.ts - Add import:
import {langREGION} from '../locales/{lang}-{REGION}.json' - Add to
localesobject:'{lang}-{REGION}': {langREGION} - Note: Use quotes for keys with hyphens
- Open
-
Test
- Restart dev server
- Test API:
curl "localhost:3000/api?lang={lang}-{REGION}" - Test fallback:
curl "localhost:3000/api?lang={lang}-XX"should use base language
The system automatically falls back in this order:
- Exact match (e.g.,
es-AR) - Base language (e.g.,
esfromes-AR) - English (
en)
This means:
es-MXwill useesifes-MXdoesn't existfr-CAwill useenif neitherfr-CAnorfrexist
{
"meta": { "title": "...", "description": "..." },
"tagline": "...",
"reload": { "hit": "...", "space": "...", "or_click": "..." },
"footer": { "share": "...", "source": "...", ... },
"slack": { "footer": "..." },
"reasons": {
"to_deploy": ["...", "..."],
"to_not_deploy": ["...", "..."],
"thursday_afternoon": ["...", "..."],
"friday_afternoon": ["...", "..."],
"friday_13th": ["...", "..."],
"afternoon": ["...", "..."],
"weekend": ["...", "..."],
"day_before_christmas": ["...", "..."],
"christmas": ["...", "..."],
"new_year": ["...", "..."]
}
}- Use ISO 639-1 codes for languages (2 letters)
- Use ISO 3166-1 alpha-2 codes for regions (2 letters, uppercase)
- Format:
{lang}or{lang}-{REGION} - Always restart the dev server after adding a new language
- Both client and server files must be updated
- The
reasonsarrays can have different lengths per language