Mainstay GitHub
All docs

Languages

Content locales, where each is served, and which fields have a value per language.

Content is translated per field. A title and a slug get a value in each language; a date or a price stays one value for all of them. Each field says which it is with localized: true.

The locales

locales in config/mainstay.php lists the languages content is written in, the default first, each with where it is served: a path prefix, a host, or both.

'locales' => ['en' => '/', 'nl' => '/nl'],

'locales' => ['en' => 'https://example.com', 'nl' => 'https://example.nl'],

Either every locale names a host or none does. A public page sets the application's locale to the one it is served in, so __() and the reads a template makes follow it. Out of the box there is one locale, your APP_LOCALE, served at /.

Where translations are kept

A type's localized fields live in its _locales table, a row per language, beside the main table holding the fields shared by all of them. Reads take a locale:; without one they read the request's.

Writing a translation

update() without a locale updates the entry as the request's locale reads it. Pass one the entry has no row in yet and it adds that translation, asking for its required localized fields since nothing is stored for them:

Mainstay::update(Article::class, $id, [
    'title' => 'Hallo',
    'slug' => 'hallo',
], locale: 'nl', overrideAccess: true);

Paths per language

A route takes one pattern for every locale, or one per locale where a segment is translated:

#[Route(['en' => '/blog/{slug}', 'nl' => '/nieuws/{slug}'])]

The pattern holds no locale prefix: the prefix or host is the catch-all's, from the config.

What follows the language, and what does not

  • An entry's content is translated whole, a document per language.

  • An image's alt text has a value per locale.

  • Terms are the same in every language; each term is translated itself.

  • An entry not written in a language is absent there: its path answers 404, and a relation to it reads as missing.

Not built yet

There is no fallback from one language to another, and publishing and the trash act on every language at once.

Both are planned; the roadmap says when.