Skip to main content
Internationalization

Internationalization

Internationalization keeps user-facing text in language files so the same application can serve more than one locale.

Create a language file

<?php // app/Language/en/App.php

return [
    'welcome' => 'Welcome',
    'saved'   => 'Your changes were saved.',
];

Add a matching file under another locale, for example app/Language/fr/App.php, with the same keys.

Use a line

echo lang('App.welcome');
echo lang('App.saved');

Placeholders

// Language file
'greeting' => 'Hello, {name}.',

// Usage
echo lang('App.greeting', ['name' => $user['name']]);

Configure locales

Set defaultLocale and supportedLocales in app/Config/App.php. The request locale can be negotiated from the URL, a cookie, or the browser header, depending on your design.

$locale = $this->request->getLocale();
echo lang('App.welcome');

Working with translators

  • Keep keys short and stable; changing keys breaks translations.
  • Use placeholders instead of building sentences by concatenation.
  • Avoid putting HTML in language strings unless it is unavoidable.
  • Provide a fallback locale so a missing key still shows readable text.
  • Test long translations; they often break tight button layouts.