\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 reset Reset singleton instance
public setInstance Set the i18n instance for the \I18n__ function
public translate Translate a text.
protected loadTranslations Load translation messages

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(): null|\Piko\I18n

public static  getInstance(): null|\Piko\I18n

Return I18n singleton instance

Return:

null|\Piko\I18n


public reset(): void

public static  reset(): void

Reset singleton instance


public setInstance(): void

public static  setInstance(\Piko\I18n|null  $instance): void

Set the i18n instance for the \I18n__ function

Parameters

$instance : The i18n 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).


protected loadTranslations(): void

protected  loadTranslations(string  $domain): void

Load translation messages

Parameters

$domain :