switon/i18n

Per-request locale, flat translation files, fallback lookup, and optional ICU formatting for Switon Framework

Maintainers

Package info

github.com/switon-php/i18n

Documentation

pkg:composer/switon/i18n

Statistics

Installs: 4

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 03:41:32 UTC


README

CI PHP 8.3+

Switon's locale-aware translation layer for request-local locale state, fallback lookup, and message formatting.

Highlights

  • One translation entrypoint: TranslatorInterface gives app services one place for message lookup.
  • Request-local locale: the active locale stays isolated per request.
  • Fallback-aware lookup: translation files can fall back through configured candidates.
  • Formatted messages: placeholders and ICU formatting both work from the same source.
  • Missing-key reporting: TranslationKeyMissing can surface which translations are still missing.

Installation

composer require switon/i18n

Quick Start

use Switon\Core\Attribute\Autowired;
use Switon\Core\LocaleInterface;
use Switon\Core\TranslatorInterface;

class WelcomeService
{
    #[Autowired] protected TranslatorInterface $translator;
    #[Autowired] protected LocaleInterface $locale;

    public function message(string $name): string
    {
        $this->locale->set('en');

        return $this->translator->translate('hello', ['name' => $name]);
    }
}

Docs: https://docs.switon.dev/latest/i18n

License

MIT.