inkphp GitHub 中文

Multiple languages

Inline translations: t()

UI text lives in the page itself, so changing a sentence touches one file:

<h1><?= e(t(['zh' => '留言板', 'en' => 'Guestbook'])) ?></h1>
<p><?= e(t(['zh' => '已有 {n} 条', 'en' => '{n} messages'], ['n' => $count])) ?></p>

bin/ink check warns about a t() that misses a configured language. For long passages, branch on locale().

The current language: locale()

Order: ?lang=en → cookie → the browser's Accept-Language → the first of config('locales'). ?lang= is remembered in a cookie.

locale('zh', false);   // fix the language for this request only, no cookie (single-language admin pages)

One URL per language

The kernel does not handle languages in URLs; pick a simple approach yourself:

ApproachURLsGood for
Query parameter/about?lang=enadding translations to existing pages; every link carries ?lang=
One directory per language/about, /en/aboutsites and docs where each language is written separately (this site works this way)
Fixed URLs/about, /about-usa handful of pages

Put hreflang and canonical tags in the layout; each page passes the URL of its other-language version to the layout.