Exemplo n.º 1
0
 public function TranslateToken($strToken)
 {
     if (self::$objGettextTables instanceof gettext_reader) {
         return self::$objGettextTables->translate($strToken);
     } else {
         return $strToken;
     }
 }
Exemplo n.º 2
0
 /**
  * @dataProvider data_provider_test_npgettext
  */
 public function test_npgettext($number, $expected)
 {
   $parser = new gettext_reader(NULL);
   $result = $parser->npgettext("context",
                                "%d pig went to the market\n",
                                "%d pigs went to the market\n",
                                $number);
   $this->assertSame($expected, $result);
 }
Exemplo n.º 3
0
 public function test_extract_plural_forms_header_from_po_header()
 {
     $parser = new gettext_reader(NULL);
     // It defaults to a "Western-style" plural header.
     $this->assertEquals('nplurals=2; plural=n == 1 ? 0 : 1;', $parser->extract_plural_forms_header_from_po_header(""));
     // Extracting it from the middle of the header works.
     $this->assertEquals('nplurals=1; plural=0;', $parser->extract_plural_forms_header_from_po_header("Content-type: text/html; charset=UTF-8\n" . "Plural-Forms: nplurals=1; plural=0;\n" . "Last-Translator: nobody\n"));
     // It's also case-insensitive.
     $this->assertEquals('nplurals=1; plural=0;', $parser->extract_plural_forms_header_from_po_header("PLURAL-forms: nplurals=1; plural=0;\n"));
     // It falls back to default if it's not on a separate line.
     $this->assertEquals('nplurals=2; plural=n == 1 ? 0 : 1;', $parser->extract_plural_forms_header_from_po_header("Content-type: text/html; charset=UTF-8" . "Plural-Forms: nplurals=1; plural=0;\n" . "Last-Translator: nobody\n"));
 }
Exemplo n.º 4
0
function load_textdomain()
{
    $locale = get_locale();
    $mofile = "./languages/{$locale}.mo";
    if (is_readable($mofile)) {
        $input = new CachedFileReader($mofile);
    } else {
        return;
    }
    $gettext = new gettext_reader($input);
    if (isset($gettext)) {
        $gettext->load_tables();
    }
    return $gettext;
}
Exemplo n.º 5
0
/**
* Load the language files content in a single object and order these files
* by domain. The domain must be unique for each element. By example: Application
* MyWords can have "mywords" as domain. Domains 'global' and 'system' are reserved
* by EXM System and could not be used by other elements.
* 
* @param string $domain Unique identifier for this file
* @param string Local path to file
*/
function load_locale_file($domain, $file)
{
    global $l10n;
    if (is_readable($file)) {
        $cache = new CachedFileReader($file);
    } else {
        return;
    }
    $gettext = new gettext_reader($cache);
    if (isset($l10n[$domain])) {
        $l10n[$domain]->load_tables();
        $gettext->load_tables();
        $l10n[$domain]->cache_translations = array_merge($gettext->cache_translations, $l10n[$domain]->cache_translations);
    } else {
        $l10n[$domain] = $gettext;
    }
    unset($input, $gettext);
}
Exemplo n.º 6
0
 /**
  * Gets the current instantiated locale's name
  *
  * @return string locale name
  */
 public function GetLocaleName()
 {
     if (!$this->localeReader) {
         return 'English';
     }
     $localeName = $this->localeReader->translate('English');
     if ($localeName == 'English') {
         // someone didn't translate the language name - don't mislabel it as english
         return '';
     }
     return $localeName;
 }
Exemplo n.º 7
0
        error_reporting(E_ALL);
    }
    ini_set("display_errors", 1);
}
// User language selection prevails over system-wide defined language.
if (isset($_SESSION['id_usuario'])) {
    $temp = get_db_value('lang', 'tusuario', 'id_usuario', $_SESSION['id_usuario']);
    if ($temp != "") {
        $config['language_code'] = $temp;
    }
}
if (isset($_GET['language'])) {
    $config['language_code'] = $_GET['language'];
}
if (file_exists($config["homedir"] . '/include/languages/' . $config['language_code'] . '.mo')) {
    $l10n = new gettext_reader(new CachedFileReader($config["homedir"] . '/include/languages/' . $config['language_code'] . '.mo'));
    $l10n->load_tables();
}
// Set a the system timezone default
if (!isset($config["timezone"]) or $config["timezone"] == "") {
    $config["timezone"] = "Europe/Berlin";
}
date_default_timezone_set($config["timezone"]);
include_once $config["homedir"] . "/include/functions_html.php";
include_once $config["homedir"] . "/include/functions_form.php";
include_once $config["homedir"] . "/include/functions_calendar.php";
// Function include_graphs_dependencies() it's called in the code below
require_once "include_graph_dependencies.php";
include_graphs_dependencies($config['homedir'] . '/');
//Compound base url
$protocol = "http";
Exemplo n.º 8
0
 public function load_textdomain($domain, $mofile)
 {
     include_once FRAMEWORK_CORE_PATH . '/Translate/gettext/streams.php';
     include_once FRAMEWORK_CORE_PATH . '/Translate/gettext/gettext.php';
     if (is_readable($mofile)) {
         $input = new CachedFileReader($mofile);
     } else {
         return;
     }
     $gettext = new gettext_reader($input);
     if (isset($this->_l10n[$domain])) {
         $this->_l10n[$domain]->load_tables();
         $gettext->load_tables();
         $this->_l10n[$domain]->cache_translations = array_merge($gettext->cache_translations, $this->_l10n[$domain]->cache_translations);
     } else {
         $this->_l10n[$domain] = $gettext;
     }
     unset($input, $gettext);
 }
Exemplo n.º 9
0
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
if (!$_SERVER['argc']) {
    die("cannot be called via web");
}
ini_set('include_path', dirname(dirname(__FILE__)) . ':' . ini_get('include_path'));
define('SESSION_DISABLE', true);
include_once 'lib/freemed.php';
if (empty($_SERVER['argv'][1])) {
    die("syntax: " . $_SERVER['argv'][0] . " locale\n");
} else {
    $my_locale = $_SERVER['argv'][1];
}
$reader = new FileReader(dirname(dirname(__FILE__)) . "/locale/" . $my_locale . "/LC_MESSAGES/gwt.mo");
$streamer = new gettext_reader($reader);
$streamer->load_tables();
// Remove bad entry at the beginning
unset($streamer->cache_translations['']);
$out = json_encode($streamer->cache_translations);
$filename = dirname(dirname(__FILE__)) . "/ui/gwt/src/main/webapp/resources/locale/" . $my_locale . ".json";
// Write to locale file
file_put_contents($filename, $out);
Exemplo n.º 10
0
 /**
  * Get the strings of specified language from locale files.
  *
  * @param   string  $lang_code      language code
  * @param   integer $device_type_id device type ID
  * @return  array   strings
  */
 function get_translations($lang_code, $device_type_id = FALSE)
 {
     $translations_key = "translations_" . $lang_code . "_" . $device_type_id;
     // If the strings of specified language is not loaded
     if (empty($this->_translations[$translations_key])) {
         $translations = array();
         // Get a list of files to load.
         $file_list = $this->get_locale_file_list($lang_code, $device_type_id);
         // Get the strings from each locale file using php_gettext.
         foreach ($file_list as $locale_file) {
             $stream = new FileReader($locale_file);
             $gettext = new gettext_reader($stream);
             $gettext->load_tables();
             $translations = array_merge($translations, $gettext->cache_translations);
         }
         $this->_translations[$translations_key] = $translations;
     }
     return $this->_translations[$translations_key];
 }