Tsugi

I18N
in package

Internationalization (i18n) utility class for translation support

Provides translation functions similar to WordPress pattern. Supports both legacy gettext and Symfony Translation component.

Table of Contents

Methods

__()  : string
Translate a message from a textdomain
_e()  : void
Echo a translated message from a textdomain
_m()  : string
Translate a message from the master domain
_me()  : void
Echo a translated message from the master domain
setLocale()  : void
Set the locale for the current user
setupTextDomain()  : void
Set up the translation text domain

Methods

__()

Translate a message from a textdomain

public static __(string $message[, string|false $textdomain = false ]) : string

Pattern borrowed from WordPress. This is the core translation function.

Parameters
$message : string

The message to translate

$textdomain : string|false = false

The text domain to use, or false for current domain

Return values
string —

The translated message

_e()

Echo a translated message from a textdomain

public static _e(string $message[, string|false $textdomain = false ]) : void
Parameters
$message : string

The message to translate and echo

$textdomain : string|false = false

The text domain to use, or false for current domain

_m()

Translate a message from the master domain

public static _m(string $message) : string
Parameters
$message : string

The message to translate

Return values
string —

The translated message

_me()

Echo a translated message from the master domain

public static _me(string $message) : void
Parameters
$message : string

The message to translate and echo

setLocale()

Set the locale for the current user

public static setLocale([string|null $locale = null ]) : void
Parameters
$locale : string|null = null

The locale to set (e.g., 'en_US', 'fr_FR'). If null, detects from HTTP headers

setupTextDomain()

Set up the translation text domain

public static setupTextDomain() : void

Configures the translation system with master and domain-specific translation files. Uses Symfony Translation component if available, falls back to legacy gettext.


        
On this page

Search results