ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
GettextTranslator.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Gettext;
4 
6 {
12  public function __construct($language = null)
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  }
28 
37  public function setLanguage($language, $category = null)
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  }
48 
58  public function loadDomain($domain, $path = null, $default = true)
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  }
69 
75  public function gettext($original)
76  {
77  return gettext($original);
78  }
79 
85  public function ngettext($original, $plural, $value)
86  {
87  return ngettext($original, $plural, $value);
88  }
89 
95  public function dngettext($domain, $original, $plural, $value)
96  {
97  return dngettext($domain, $original, $plural, $value);
98  }
99 
105  public function npgettext($context, $original, $plural, $value)
106  {
107  $message = $context."\x04".$original;
108  $translation = ngettext($message, $plural, $value);
109 
110  return ($translation === $message) ? $original : $translation;
111  }
112 
118  public function pgettext($context, $original)
119  {
120  $message = $context."\x04".$original;
121  $translation = gettext($message);
122 
123  return ($translation === $message) ? $original : $translation;
124  }
125 
131  public function dgettext($domain, $original)
132  {
133  return dgettext($domain, $original);
134  }
135 
141  public function dpgettext($domain, $context, $original)
142  {
143  $message = $context."\x04".$original;
144  $translation = dgettext($domain, $message);
145 
146  return ($translation === $message) ? $original : $translation;
147  }
148 
154  public function dnpgettext($domain, $context, $original, $plural, $value)
155  {
156  $message = $context."\x04".$original;
157  $translation = dngettext($domain, $message, $plural, $value);
158 
159  return ($translation === $message) ? $original : $translation;
160  }
161 }
Interface used by all translators.
ngettext($original, $plural, $value)
dnpgettext($domain, $context, $original, $plural, $value)
loadDomain($domain, $path=null, $default=true)
Loads a gettext domain.
dngettext($domain, $original, $plural, $value)
catch(Exception $e) $message
dpgettext($domain, $context, $original)
dgettext($domain, $original)
pgettext($context, $original)
__construct($language=null)
Constructor.
npgettext($context, $original, $plural, $value)
setLanguage($language, $category=null)
Define the current locale.
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27