\Piko\I18n

Internationalization class

Properties summary

Name Description
public $language The language code currently used for translations
public $translations A key-value paired array of domain / path
protected $instance I18n Instance
protected $messages Messages container by domain

Inherited Properties

Name Description
protected $eventDispatcher  
protected $listenerProvider  

Methods summary

Name Description
public __construct Constructor
public addTranslation Register a translation
public getInstance Return I18n singleton instance
public loadTranslations Load translation messages
public reset Reset singleton instance
public translate Translate a text.

Inherited Methods

Name Description
public on Registers an event listener.
public trigger Trigger an event that may be listen by event liste…

Properties

public $language : string

The language code currently used for translations

public $translations : array<string,string>

A key-value paired array of domain / path

protected $instance : \Piko\I18n|null

I18n Instance

protected $messages : array<string,string>[]

Messages container by domain


Methods

public __construct(): mixed

public  __construct(array&lt;string,string&gt;  $translations = [], string  $language = 'en'): mixed

Constructor The $translations argument should contains a key-value paired array of domain / path. Example :

[
   'app' => '@app/messages'
]

Parameters

$translations (default: []):

$language (default: ‘en’): The language code

Return:

mixed


public addTranslation(): void

public  addTranslation(string  $domain, string  $path): void

Register a translation

Parameters

$domain : The translation domain, for instance ‘app’.

$path : The path to the directory where to find translation files.


public getInstance(): \Piko\I18n

public static  getInstance(): \Piko\I18n

Return I18n singleton instance

Return:

\Piko\I18n


public loadTranslations(): void

public  loadTranslations(): void

Load translation messages


public reset(): void

public static  reset(): void

Reset singleton instance


public translate(): string|null

public  translate(string  $domain, string|null  $text, array&lt;string,string&gt;  $params = []): string|null

Translate a text.

Parameters

$domain : The translation domain, for instance ‘app’.

$text : The text to translate.

$params (default: []): Parameters substitution, eg. $this->translate(‘site’, ‘Hello {name}’, [‘name’ => ‘John’]).

Return:

string|null The translated text or the text itself if no translation was found (the text can be null).