PHP Class Bluz\Translator\Translator

Inheritance: use trait Bluz\Common\Options
Show file Open project: bluzphp/framework Class Usage Examples

Protected Properties

Property Type Description
$domain text domain
$locale string Locale
$path path to text domain files

Public Methods

Method Description
addTextDomain ( string $domain, string $path ) : self Add text domain for gettext
setDomain ( string $domain ) : self Set domain
setLocale ( string $locale ) : self Set locale
setPath ( string $path ) : self Set path to l10n
translate ( string $message, $text ) : string Translate message
translatePlural ( string $singular, string $plural, integer $number, $text ) : string Translate plural form

Protected Methods

Method Description
initOptions ( ) : void Initialization

Method Details

addTextDomain() public method

Add text domain for gettext
public addTextDomain ( string $domain, string $path ) : self
$domain string of text for gettext setup
$path string on filesystem
return self

initOptions() protected method

Initialization
protected initOptions ( ) : void
return void

setDomain() public method

Set domain
public setDomain ( string $domain ) : self
$domain string
return self

setLocale() public method

Set locale
public setLocale ( string $locale ) : self
$locale string
return self

setPath() public method

Set path to l10n
public setPath ( string $path ) : self
$path string
return self

translate() public static method

Simple example of usage equal to gettext('Message') Translator::translate('Message'); Simple replace of one or more argument(s) equal to sprintf(gettext('Message to %s'), 'Username') Translator::translate('Message to %s', 'Username');
public static translate ( string $message, $text ) : string
$message string
$text
return string

translatePlural() public static method

Example of usage plural form + sprintf equal to sprintf(ngettext('%d comment', '%d comments', 4), 4) Translator::translatePlural('%d comment', '%d comments', 4, 4) Example of usage plural form + sprintf equal to sprintf(ngettext('%d comment', '%d comments', 4), 4, 'Topic') Translator::translatePlural('%d comment to %s', '%d comments to %s', 4, 'Topic')
public static translatePlural ( string $singular, string $plural, integer $number, $text ) : string
$singular string
$plural string
$number integer
$text
return string

Property Details

$domain protected property

text domain
protected $domain

$locale protected property

Locale
protected string $locale
return string

$path protected property

path to text domain files
protected $path