Localization

Textstem supports localization using Laravel's translation files. The admin ships in English, Greek, Italian and Japanese (en, el, it, ja).

Enable Locales

To let people switch language, add an available_locales key to config/app.php, listing the languages to offer as label => locale:

'available_locales' => [
    'English' => 'en',
    'Greek' => 'el',
    'Italian' => 'it',
],

The admin's settings menu (and the mobile menu) then shows a language picker. Picking a language visits /language/{locale}, which stores the choice in the session and goes back to the previous page. Only locales in available_locales, plus app.locale, are accepted; anything else gets a 400.

The package's Localization middleware, added to the web group, applies the session's locale on every request.

Translation files

The package's strings are plain-text keys in JSON files (lang/{locale}.json in the package), used with __('…'), trans('…') and @lang('…'). To add a language or change wording, add or edit the JSON file of the same name in the host app, for example lang/fr.json. Keys in the app's file win over the package's.

On Laravel 10 apps that still use it, the folder is resources/lang instead of lang.

How it works

  • Default. Without a choice in the session, the app's app.locale (usually en) is used.
  • Switching. The language/{locale} route (in the package's routes/web.php) checks the locale, calls app()->setLocale(), stores it in the session under locale and redirects back.
  • Every request. Medialight\Textstem\Http\Middleware\Localization reads locale from the session and sets it with App::setLocale(). TextstemServiceProvider appends it to the web middleware group, so host-app routes get it too.
  • The page's language. The admin layouts set <html lang="…"> from app()->getLocale(), so browsers and screen readers know the page's language. Set it the same way in your own public layouts.
esc