ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Gettext\GettextTranslator Class Reference
+ Inheritance diagram for Gettext\GettextTranslator:
+ Collaboration diagram for Gettext\GettextTranslator:

Public Member Functions

 __construct ($language=null)
 Constructor. More...
 
 setLanguage ($language, $category=null)
 Define the current locale. More...
 
 loadDomain ($domain, $path=null, $default=true)
 Loads a gettext domain. More...
 
 gettext ($original)
 
 ngettext ($original, $plural, $value)
 
 dngettext ($domain, $original, $plural, $value)
 
 npgettext ($context, $original, $plural, $value)
 
 pgettext ($context, $original)
 
 dgettext ($domain, $original)
 
 dpgettext ($domain, $context, $original)
 
 dnpgettext ($domain, $context, $original, $plural, $value)
 
- Public Member Functions inherited from Gettext\BaseTranslator
 register ()
 
 register ()
 Register this translator as global, to use with the gettext functions __(), p__(), etc. More...
 
 gettext ($original)
 Gets a translation using the original string. More...
 
 ngettext ($original, $plural, $value)
 Gets a translation checking the plural form. More...
 
 dngettext ($domain, $original, $plural, $value)
 Gets a translation checking the domain and the plural form. More...
 
 npgettext ($context, $original, $plural, $value)
 Gets a translation checking the context and the plural form. More...
 
 pgettext ($context, $original)
 Gets a translation checking the context. More...
 
 dgettext ($domain, $original)
 Gets a translation checking the domain. More...
 
 dpgettext ($domain, $context, $original)
 Gets a translation checking the domain and context. More...
 
 dnpgettext ($domain, $context, $original, $plural, $value)
 Gets a translation checking the domain, the context and the plural form. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Gettext\BaseTranslator
static initGettextFunctions (TranslatorInterface $translator)
 Set a translation instance as global, to use it with the gettext functions. More...
 
- Static Public Attributes inherited from Gettext\BaseTranslator
static $current
 

Detailed Description

Definition at line 5 of file GettextTranslator.php.

Constructor & Destructor Documentation

◆ __construct()

Gettext\GettextTranslator::__construct (   $language = null)

Constructor.

Detects the current language using the environment variables.

Parameters
string$language

Definition at line 12 of file GettextTranslator.php.

13 {
14 if (!function_exists('gettext')) {
15 throw new \RuntimeException('This class require the gettext extension for PHP');
16 }
17
18 //detects the language environment respecting the priority order
19 //http://php.net/manual/en/function.gettext.php#114062
20 if (empty($language)) {
21 $language = getenv('LANGUAGE') ?: getenv('LC_ALL') ?: getenv('LC_MESSAGES') ?: getenv('LANG');
22 }
23
24 if (!empty($language)) {
25 $this->setLanguage($language);
26 }
27 }
setLanguage($language, $category=null)
Define the current locale.

Member Function Documentation

◆ dgettext()

Gettext\GettextTranslator::dgettext (   $domain,
  $original 
)
See also
TranslatorInterface

{Gets a translation checking the domain.

Parameters
string$domain
string$original
Returns
string
}

Implements Gettext\TranslatorInterface.

Definition at line 131 of file GettextTranslator.php.

132 {
133 return dgettext($domain, $original);
134 }
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8
dgettext($domain, $original)

References $domain.

◆ dngettext()

Gettext\GettextTranslator::dngettext (   $domain,
  $original,
  $plural,
  $value 
)
See also
TranslatorInterface

{Gets a translation checking the domain and the plural form.

Parameters
string$domain
string$original
string$plural
string$value
Returns
string
}

Implements Gettext\TranslatorInterface.

Definition at line 95 of file GettextTranslator.php.

96 {
97 return dngettext($domain, $original, $plural, $value);
98 }
dngettext($domain, $original, $plural, $value)

References $domain.

◆ dnpgettext()

Gettext\GettextTranslator::dnpgettext (   $domain,
  $context,
  $original,
  $plural,
  $value 
)
See also
TranslatorInterface

{Gets a translation checking the domain, the context and the plural form.

Parameters
string$domain
string$context
string$original
string$plural
string$value
}

Implements Gettext\TranslatorInterface.

Definition at line 154 of file GettextTranslator.php.

155 {
156 $message = $context."\x04".$original;
157 $translation = dngettext($domain, $message, $plural, $value);
158
159 return ($translation === $message) ? $original : $translation;
160 }
catch(Exception $e) $message

References $domain, and $message.

◆ dpgettext()

Gettext\GettextTranslator::dpgettext (   $domain,
  $context,
  $original 
)
See also
TranslatorInterface

{Gets a translation checking the domain and context.

Parameters
string$domain
string$context
string$original
Returns
string
}

Implements Gettext\TranslatorInterface.

Definition at line 141 of file GettextTranslator.php.

142 {
143 $message = $context."\x04".$original;
144 $translation = dgettext($domain, $message);
145
146 return ($translation === $message) ? $original : $translation;
147 }

References $domain, and $message.

◆ gettext()

Gettext\GettextTranslator::gettext (   $original)
See also
TranslatorInterface

{Gets a translation using the original string.

Parameters
string$original
Returns
string
}

Implements Gettext\TranslatorInterface.

Definition at line 75 of file GettextTranslator.php.

76 {
77 return gettext($original);
78 }

◆ loadDomain()

Gettext\GettextTranslator::loadDomain (   $domain,
  $path = null,
  $default = true 
)

Loads a gettext domain.

Parameters
string$domain
string$path
bool$default
Returns
self

Definition at line 58 of file GettextTranslator.php.

59 {
60 bindtextdomain($domain, $path);
61 bind_textdomain_codeset($domain, 'UTF-8');
62
63 if ($default) {
64 textdomain($domain);
65 }
66
67 return $this;
68 }

References $domain, and $path.

◆ ngettext()

Gettext\GettextTranslator::ngettext (   $original,
  $plural,
  $value 
)
See also
TranslatorInterface

{Gets a translation checking the plural form.

Parameters
string$original
string$plural
string$value
Returns
string
}

Implements Gettext\TranslatorInterface.

Definition at line 85 of file GettextTranslator.php.

86 {
87 return ngettext($original, $plural, $value);
88 }
ngettext($original, $plural, $value)

◆ npgettext()

Gettext\GettextTranslator::npgettext (   $context,
  $original,
  $plural,
  $value 
)
See also
TranslatorInterface

{Gets a translation checking the context and the plural form.

Parameters
string$context
string$original
string$plural
string$value
Returns
string
}

Implements Gettext\TranslatorInterface.

Definition at line 105 of file GettextTranslator.php.

106 {
107 $message = $context."\x04".$original;
108 $translation = ngettext($message, $plural, $value);
109
110 return ($translation === $message) ? $original : $translation;
111 }

References $message.

◆ pgettext()

Gettext\GettextTranslator::pgettext (   $context,
  $original 
)
See also
TranslatorInterface

{Gets a translation checking the context.

Parameters
string$context
string$original
Returns
string
}

Implements Gettext\TranslatorInterface.

Definition at line 118 of file GettextTranslator.php.

119 {
120 $message = $context."\x04".$original;
121 $translation = gettext($message);
122
123 return ($translation === $message) ? $original : $translation;
124 }

References $message.

◆ setLanguage()

Gettext\GettextTranslator::setLanguage (   $language,
  $category = null 
)

Define the current locale.

Parameters
string$language
int | null$category
Returns
self

Definition at line 37 of file GettextTranslator.php.

38 {
39 if ($category === null) {
40 $category = defined('LC_MESSAGES') ? LC_MESSAGES : LC_ALL;
41 }
42
43 setlocale($category, $language);
44 putenv('LANGUAGE='.$language);
45
46 return $this;
47 }
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27

References defined.


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