ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ()
 

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.

References $language.

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.

References $domain.

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

◆ 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.

References $domain.

96  {
97  return dngettext($domain, $original, $plural, $value);
98  }
dngettext($domain, $original, $plural, $value)
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8

◆ 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.

References $context, $domain, and $message.

155  {
156  $message = $context."\x04".$original;
157  $translation = dngettext($domain, $message, $plural, $value);
158 
159  return ($translation === $message) ? $original : $translation;
160  }
$context
Definition: webdav.php:25
dngettext($domain, $original, $plural, $value)
catch(Exception $e) $message
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8

◆ 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.

References $context, $domain, and $message.

142  {
143  $message = $context."\x04".$original;
144  $translation = dgettext($domain, $message);
145 
146  return ($translation === $message) ? $original : $translation;
147  }
$context
Definition: webdav.php:25
catch(Exception $e) $message
dgettext($domain, $original)
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8

◆ 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.

References $default, $domain, and $path.

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  }
$path
Definition: aliased.php:25
$default
Definition: build.php:20
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8

◆ 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.

References $context, and $message.

106  {
107  $message = $context."\x04".$original;
108  $translation = ngettext($message, $plural, $value);
109 
110  return ($translation === $message) ? $original : $translation;
111  }
ngettext($original, $plural, $value)
$context
Definition: webdav.php:25
catch(Exception $e) $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.

References $context, and $message.

119  {
120  $message = $context."\x04".$original;
121  $translation = gettext($message);
122 
123  return ($translation === $message) ? $original : $translation;
124  }
$context
Definition: webdav.php:25
catch(Exception $e) $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.

References $language.

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  }

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