Example #1
0
 public function test_setlocale_emulation()
 {
     putenv("LC_ALL=");
     // If we set it to a non-existent locale, it still works, but uses
     // emulation.
     _setlocale(LC_MESSAGES, "xxx_XXX");
     $this->assertEquals('xxx_XXX', _setlocale(LC_MESSAGES, 0));
     $this->assertEquals(1, locale_emulation());
 }
Example #2
0
 public function test_setlocale()
 {
     // _setlocale defaults to a locale name from environment variable LANG.
     putenv("LANG=sr_RS");
     $this->assertEquals('sr_RS', _setlocale(LC_MESSAGES, 0));
     // For an existing locale, it never needs emulation.
     putenv("LANG=C");
     _setlocale(LC_MESSAGES, "");
     $this->assertEquals(0, locale_emulation());
     // If we set it to a non-existent locale, it still works, but uses
     // emulation.
     _setlocale(LC_MESSAGES, "xxx_XXX");
     $this->assertEquals('xxx_XXX', _setlocale(LC_MESSAGES, 0));
     $this->assertEquals(1, locale_emulation());
 }
Example #3
0
 /**
  * Class Constructor
  *
  * @param	String			$type		Type of language-file
  * @author	Lars Michelsen <*****@*****.**>
  */
 public function __construct($textDomain = 'nagvis')
 {
     $this->textDomain = $textDomain;
     // Append encoding (UTF8)
     $this->sCurrentEncoding = 'UTF-8';
     // Check for gettext extension
     require_once 'gettext.inc';
     $this->setLanguage();
     T_bindtextdomain($this->textDomain, cfg('paths', 'language'));
     T_bind_textdomain_codeset($this->textDomain, $this->sCurrentEncoding);
     T_textdomain($this->textDomain);
     // Check if native gettext or php-gettext is used
     if (DEBUG && DEBUGLEVEL & 2) {
         if (locale_emulation()) {
             debug('GlobalLanguage: Using php-gettext for translations');
         } else {
             debug('GlobalLanguage: Using native gettext for translations');
         }
     }
 }
?>
<html>
<head>
<title>PHP-gettext fallback example</title>
</head>
<body>
<h1>PHP-gettext as a fallback solution</h1>
<p>Example showing how to use PHP-gettext as a fallback solution if the native gettext library is not available or the system does not support the requested locale.</p>

<?php 
print "<p>";
foreach ($supported_locales as $l) {
    print "[<a href=\"?lang={$l}\">{$l}</a>] ";
}
print "</p>\n";
if (!locale_emulation()) {
    print "<p>locale '{$locale}' is supported by your system, using native gettext implementation.</p>\n";
} else {
    print "<p>locale '{$locale}' is <strong>not</strong> supported on your system, using custom gettext implementation.</p>\n";
}
?>

<hr />

<?php 
// using PHP-gettext
print "<pre>";
print T_("This is how the story goes.\n\n");
for ($number = 6; $number >= 0; $number--) {
    print sprintf(T_ngettext("%d pig went to the market\n", "%d pigs went to the market\n", $number), $number);
}