Docs in other languages

The docs and demos are in English and Ukrainian. English stays at the usual URLs; Ukrainian is under the /uk/ prefix (/uk/docs/misc/twig), or ?object=docs&lang=uk without pretty URLs. The admin docs follow the admin's language and have their own switcher above the tabs. A page that has no translation yet shows the English text with a short note in the chosen language. Classes: yf_docs_i18n, yf_rewrite ($LANG_PREFIX_OBJECTS, $URL_LANG).

URLs, switcher, search engines

  • The router takes a language before an object of yf_rewrite::$LANG_PREFIX_OBJECTS (['docs' => ['uk']]) as $_GET['lang']; every link the page builds with url() to the docs keeps it. Other paths route as before.
  • A site shows the language dropdown with {execute(docs,_lang_switcher)} in its navbar_additions template, next to {execute(docs,_bs_switcher)}; it has Bootstrap 3, Bootstrap 5 and Tailwind CSS variants.
  • A page in both languages names both with <link rel="alternate" hreflang> (and x-default, the English one); a page shown in English under /uk/ names the English URL as canonical. <html> gets lang="uk".
  • Only English: $PROJECT_CONF['docs_i18n']['LANGS'] = ['en' => 'English']; turns the switcher and the links off.

Where the translations are

WhatEnglishUkrainian
Texts (Misc, Install pages)plugins/docs/share/docs/en/<name>.stplplugins/docs/share/docs/uk/<name>.stpl
Page templates (home, install)templates/user/docs/home.stpltemplates/user/docs/uk/home.stpl
UI strings (nav, cards, demo labels)the t() callsplugins/docs/share/i18n/uk.json
Glossaryplugins/docs/share/i18n/glossary.uk.json: one word per framework term, and the names that stay English

A translation keeps the code, the template tags, the {placeholders}, the method names, the links and the anchors of its English page; comments inside code samples are translated. Its first line is the same docs-access line: the English page decides who may see it, so an admin-only page stays admin-only. The UI strings load under the ::docs:: namespace, so they translate the docs pages only and never a site's own translation of the same words. A demo whose labels and texts go through t() says so with a // docs-i18n: uk line.

make docs-i18n

make docs-i18n                          # per language: translated, stale, missing; fails on a broken translation
make docs-i18n ARGS=--list              # every page with its status
make docs-i18n ARGS="--stamp misc/twig" # after translating or updating a page: record the English source it follows
make docs-i18n ARGS=--strict            # also fail on stale and missing pages

A page is stale when its English text changed after the translation was stamped (the {{-- i18n-source: ... --}} line holds the hash of the English file). The check fails when a translation lost or changed code, tags, links, anchors or the admin-only parts, when a UI string lost a placeholder, or when a name the glossary keeps in English is missing.