Cradle  0.3.3
Simple library for creating Web-based applications
Messages Class Reference

Multi language messages. More...

Static Public Member Functions

static setTextDomain ($domain, $rootDir, $codeset='UTF-8')
 
static useTextDomain ($domain)
 
static _ ($text)
 

Static Public Attributes

static $textDomains = null
 
static $language = ""
 

Detailed Description

Multi language messages.

Class to support of multi language messages. Wrap of GNU "gettext" utility and its simplest replacement (just in case).

Version
1.0
Author
Digger mrdig.nosp@m.ger@.nosp@m.sad-s.nosp@m.yste.nosp@m.ms.ru

Member Function Documentation

static _ (   $text)
static

GNU gettext utility simplest replacement.

If you can't use the gettext for any reason, the simplest way to replace it is to use this method.

But in this case you should keep your translation messages in php file (for directory structure see: setTextDomain). The php file mast returns an array of structure:

return [
'message_id' => 'message text',
...
]
Parameters
string$texttext message
Returns
string text message
See also
setTextDomain

Example:

<?php
echo Messages::_('Hello world!');
static setTextDomain (   $domain,
  $rootDir,
  $codeset = 'UTF-8' 
)
static

To set params of current text domain for translations.

(wrap of gettext)

Parameters
string$domainThe name of the text domain
string$rootDirRoot directory to find translations
The root directory structure:
(`gettext` native)
/$rootDir
$language/LC_MESSAGES/domainName.mo
For example:
messages/
en/LC_MESSAGES/domainName.mo
ru/LC_MESSAGES/domainName.mo
...
(`gettext` replacment by self::_ )
/$rootDir
$language/domainName.php
For example:
messages/
en/domainName.php
ru/domainName.php
...
string$codesetUTF-8 by default.
static useTextDomain (   $domain)
static

Change current text domain for translation.

(wrap of gettext)

Property self::$textDomains mast be defined before

See also
$textDomains
Parameters
string$domainThe name of the current text domain

Field Documentation

$language = ""
static

Current language

$textDomains = null
static

Array of text domains for translations

Structure:

self::$textDomains = [
'text_domain1' => [
'root' => '/path/to/some_folder1',
'codeset' => 'UTF-8',
],
'text_domain2' => [
'root' => '/path/to/some_folder2',
'codeset' => 'UTF-8',
],
...
]

The documentation for this class was generated from the following file: