diff --git a/docs/translations.md b/docs/translations.md index 44c81a3..49d2457 100644 --- a/docs/translations.md +++ b/docs/translations.md @@ -15,6 +15,12 @@ Not in the language files: the hero (becomes a CMS module), the privacy statemen 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. +## Two ways to read a text + +- A single text in a component: `t('home.pricing.title')`, or `tList(...)` for a list of plain texts, `tPlural(...)` for singular and plural. +- Structured content (a list of items with several texts, such as the questions and answers of a page): the content module reads the typed tree directly, `messages.shoots.newborn.faq.map((item) => ({ question: item.question, answer: item.answer }))`. A missing property breaks `tsc`, the same as a missing key. The content modules in `web/src/content` keep their types, images and paths and take the words from `messages`. +- `t()` is not given keys that are built at run time (`` `faq.${i}.question` ``): use the tree for lists. + ## How a missing text is found - `t('...')` only accepts keys that exist in the Dutch files; a typo or a missing key stops `tsc` and the build. diff --git a/web/eslint.config.js b/web/eslint.config.js index 5a8c80c..c36ef19 100644 --- a/web/eslint.config.js +++ b/web/eslint.config.js @@ -47,6 +47,16 @@ export default tseslint.config( ], plugins: { react }, rules: { + // Text in attributes that people read or hear (labels, alt text) + 'no-restricted-syntax': [ + 'warn', + { + selector: + "JSXAttribute[name.name=/^(aria-label|aria-description|alt|title|placeholder|label)$/][value.type='Literal']", + message: + 'Put the text in a language file (src/i18n) and use t().', + }, + ], 'react/jsx-no-literals': [ 'warn', { diff --git a/web/src/i18n/index.ts b/web/src/i18n/index.ts index 4992f22..d280e9f 100644 --- a/web/src/i18n/index.ts +++ b/web/src/i18n/index.ts @@ -1,4 +1,13 @@ +import about from './nl/about.json'; import common from './nl/common.json'; +import contact from './nl/contact.json'; +import home from './nl/home.json'; +import instagram from './nl/instagram.json'; +import portfolio from './nl/portfolio.json'; +import seo from './nl/seo.json'; +import shoots from './nl/shoots.json'; +import site from './nl/site.json'; +import testimonials from './nl/testimonials.json'; // The texts of the site, per language, as JSON per area (src/i18n//*.json). // Only Dutch exists now. The types come from the Dutch files: a second language @@ -9,7 +18,18 @@ import common from './nl/common.json'; // No library: the files are imported as modules, so prerendering, hydrating // and the host injection all see the same text without a loading step. -export const nl = { common }; +export const nl = { + common, + site, + home, + about, + contact, + shoots, + portfolio, + instagram, + testimonials, + seo, +}; export type Messages = typeof nl; diff --git a/web/src/i18n/nl/about.json b/web/src/i18n/nl/about.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/web/src/i18n/nl/about.json @@ -0,0 +1 @@ +{} diff --git a/web/src/i18n/nl/common.json b/web/src/i18n/nl/common.json index 535b048..fc457a4 100644 --- a/web/src/i18n/nl/common.json +++ b/web/src/i18n/nl/common.json @@ -1,5 +1,13 @@ { "aria": { - "backToTop": "Terug naar boven" + "backToTop": "Terug naar boven", + "skipToContent": "Direct naar de inhoud" + }, + "site": { + "name": "Andrea Slop Fotografie" + }, + "newTab": { + "short": "(opent in nieuw tabblad)", + "instagram": "(Instagram, opent in nieuw tabblad)" } } diff --git a/web/src/i18n/nl/contact.json b/web/src/i18n/nl/contact.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/web/src/i18n/nl/contact.json @@ -0,0 +1 @@ +{} diff --git a/web/src/i18n/nl/home.json b/web/src/i18n/nl/home.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/web/src/i18n/nl/home.json @@ -0,0 +1 @@ +{} diff --git a/web/src/i18n/nl/instagram.json b/web/src/i18n/nl/instagram.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/web/src/i18n/nl/instagram.json @@ -0,0 +1 @@ +{} diff --git a/web/src/i18n/nl/portfolio.json b/web/src/i18n/nl/portfolio.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/web/src/i18n/nl/portfolio.json @@ -0,0 +1 @@ +{} diff --git a/web/src/i18n/nl/seo.json b/web/src/i18n/nl/seo.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/web/src/i18n/nl/seo.json @@ -0,0 +1 @@ +{} diff --git a/web/src/i18n/nl/shoots.json b/web/src/i18n/nl/shoots.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/web/src/i18n/nl/shoots.json @@ -0,0 +1 @@ +{} diff --git a/web/src/i18n/nl/site.json b/web/src/i18n/nl/site.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/web/src/i18n/nl/site.json @@ -0,0 +1 @@ +{} diff --git a/web/src/i18n/nl/testimonials.json b/web/src/i18n/nl/testimonials.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/web/src/i18n/nl/testimonials.json @@ -0,0 +1 @@ +{}