Translation files: one file per language (src/i18n/nl.json)
The ten area files are merged into nl.json with the blocks common, site, home, about, contact, shoots, portfolio, instagram, testimonials and seo, same key paths as before. A second language becomes en.json. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ The texts of the site live in language files, not in the components. Dutch is th
|
||||
|
||||
## Where things are
|
||||
|
||||
- `web/src/i18n/nl/*.json`: the Dutch texts, one file per area (`common`, `site`, `home`, `about`, `contact`, `shoots`, `portfolio`, `instagram`, `testimonials`, `seo`). The files are the source of the types.
|
||||
- `web/src/i18n/nl.json`: all Dutch texts of the site in one file, in blocks per area in the order of the site: `common`, `site`, `home`, `about`, `contact`, `shoots`, `portfolio`, `instagram`, `testimonials`, `seo`. The file is the source of the types. A second language is `web/src/i18n/en.json` with the same keys.
|
||||
- `web/src/i18n/index.ts`: `t(key, params?)` for a text, `tList(key)` for a list of texts, `tPlural(key, count, params?)` for a text with a singular and a plural form, `locales`, `locale` and `Messages`.
|
||||
- `web/src/i18n/compare.ts`: the checks the tests use (same keys and parameters, nothing empty).
|
||||
- The typed content modules in `web/src/content` keep their structure, images and paths; the words come from the language files.
|
||||
@@ -13,7 +13,7 @@ Not in the language files: the hero (becomes a CMS module), the privacy statemen
|
||||
|
||||
## Keys
|
||||
|
||||
Dotted paths: the file name, then the page or section, then the element: `home.pricing.title`, `shoots.newborn.faq.0.question`, `common.aria.backToTop`, `common.form.errors.required`, `seo.pages.contact.title`. A list is an array in the JSON and keeps the order of the page; a position is a number in the path. Parameters are written `{name}`; a text with a plural has the forms `one` and `other` (`photos.one`, `photos.other`) and `{count}` is filled in by `tPlural`. No HTML in the texts: a text with a link or emphasis is a structured list of parts, as the content modules already have.
|
||||
Dotted paths: the block (`common`, `home`, ...), then the page or section, then the element: `home.pricing.title`, `shoots.newborn.faq.0.question`, `common.aria.backToTop`, `common.form.errors.required`, `seo.pages.contact.title`. A list is an array in the JSON and keeps the order of the page; a position is a number in the path. Parameters are written `{name}`; a text with a plural has the forms `one` and `other` (`photos.one`, `photos.other`) and `{count}` is filled in by `tPlural`. No HTML in the texts: a text with a link or emphasis is a structured list of parts, as the content modules already have.
|
||||
|
||||
## Two ways to read a text
|
||||
|
||||
@@ -28,7 +28,7 @@ Dotted paths: the file name, then the page or section, then the element: `home.p
|
||||
- A test checks that every language has the same keys and `{parameters}` as Dutch, and that no text is empty or says TODO.
|
||||
- ESLint (`react/jsx-no-literals`) warns about a text typed straight into JSX, so a new hardcoded text is noticed in review and in CI.
|
||||
|
||||
## What is in which file
|
||||
## What is in which block
|
||||
|
||||
| File | Texts |
|
||||
| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
@@ -44,15 +44,15 @@ Not here: the hero, the privacy statement, everything from the CMS, and the form
|
||||
|
||||
## Importing the language files
|
||||
|
||||
Components import from `@/i18n`. Files that Node loads while building (everything reached from `src/seo.ts`, `src/sitePages.ts`, the content modules, `src/lib`, `src/navigation.ts`) cannot use the `@/` alias or a directory import, so they use `../i18n/index.ts` (relative, with the extension). The JSON files are imported with `with { type: 'json' }` for the same reason.
|
||||
Components import from `@/i18n`. Files that Node loads while building (everything reached from `src/seo.ts`, `src/sitePages.ts`, the content modules, `src/lib`, `src/navigation.ts`) cannot use the `@/` alias or a directory import, so they use `../i18n/index.ts` (relative, with the extension). The JSON file is imported with `with { type: 'json' }` for the same reason.
|
||||
|
||||
## Rules that are enforced
|
||||
|
||||
`react/jsx-no-literals` and a rule for text attributes (`aria-label`, `alt`, `title`, `placeholder`, `label`) are errors in components and routes (the hero, tests and the privacy page are left out; an empty `alt=""` for a decorative image is fine). A new text goes into the language file first.
|
||||
`react/jsx-no-literals` and a rule for text attributes (`aria-label`, `alt`, `title`, `placeholder`, `label`) are errors in components and routes (the hero, tests and the privacy page are left out; an empty `alt=""` for a decorative image is fine). A new text goes into `nl.json` first.
|
||||
|
||||
## Adding a language (later)
|
||||
|
||||
1. Copy `web/src/i18n/nl` to `web/src/i18n/<code>` and translate the values (keys and `{parameters}` stay).
|
||||
1. Copy `web/src/i18n/nl.json` to `web/src/i18n/<code>.json` and translate the values (keys and `{parameters}` stay).
|
||||
2. Add it to `locales` in `web/src/i18n/index.ts`; the tests then compare it with Dutch.
|
||||
3. The site needs routes per language (`/en/...`) and a prerender per language, and `<html lang>` from the language. That is a separate piece of work; the texts do not stand in its way.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user