Localization and Translations

The documentation is constantly evolving and updated alongside the project's progress. Since it is developed in parallel with the code, some sections may temporarily refer to earlier versions of the system-these are gradually adapted to the current state of the application. If you notice any outdated information, please report it or open an Issue / Pull Request.

Documentation

# Localization and Translations

The framework localization components resolve a request language and provide translations through TranslationInterface. The platform configures available languages and translation resources; check its active bootstrap/provider before assuming a particular path or URL convention.

# Use translations

use Dbm\Localization\Contracts\TranslationInterface;

final class WelcomeService
{
    public function __construct(private readonly TranslationInterface $translation) {}

    public function greeting(string $name): string
    {
        return $this->translation->trans('welcome.message', ['name' => $name]);
    }
}

A translation catalog returns an associative array:

return [
    'welcome.message' => 'Hello, :name!',
];

Translation files are application resources. The loader/provider determines the exact catalog naming and search path. Configure supported languages with the application's APP_LANGUAGES setting where that integration is enabled; a platform may select a language from the request, persist the selection, and dispatch a locale-changed event.

# Placeholders and fallback

Use stable keys across catalogs. Pass replacement values as the second argument to trans(). Provide every configured language or intentionally rely on the configured fallback behavior; do not assume a missing key is automatically translated.

The Validator can also receive a translation service so validation messages use the same localization system. Keep translation keys separate from business logic and avoid hard-coding user-facing messages in reusable services.