Exemple #1
0
<?php

//composer autoloader
include '../vendor/autoload.php';
use Smarty;
$lang = isset($_GET['lang']) ? $_GET['lang'] : 'bg';
$file_to_translate = 'smarty.html';
$file_with_translations = 'locale/' . $lang . '/' . $file_to_translate . '.php';
Gettext\Translator::loadTranslations($file_with_translations);
$smarty = new Smarty();
//$smarty->setTemplateDir("View");
$smarty->setCompileDir("templates_c");
$smarty->setCacheDir("cache");
//$smarty->setConfigDir(APPPATH."config/smarty");
//register
$smarty->registerPlugin("function", "__", 'smarty__');
$smarty->registerPlugin("function", "__n", 'smartyn__');
$smarty->registerPlugin("function", "__p", 'smartyp__');
$smarty->registerPlugin("function", "__np", 'smartynp__');
function smarty__($params)
{
    $original = $params['original'];
    return __($original);
}
function smartyn__($params)
{
    $original = $params['original'];
    $plural = $params['plural'];
    $n = $params['count'];
    return n__($original, $plural, $n);
}
Exemple #2
0
Gettext\Translator::setLanguage($lang);
Gettext\Translator::loadTranslations($file_with_translations);
//$entries = Gettext\Translator::getTranslationsAsEntries();
switch ($file_extension) {
    case 'js':
        $translations = Gettext\Extractors\JsCode::extract($file_to_translate);
        break;
    case 'html':
        $translations = Gettext\Extractors\Smarty::extract($file_to_translate);
        break;
    default:
        $file_extension = 'php';
        $translations = Gettext\Extractors\PhpCode::extract($file_to_translate);
        break;
}
$entries = Gettext\Translator::getTranslationsAsEntries(false, $translations);
if (isset($_POST['submit'])) {
    foreach ($_POST as $trans) {
        $context = isset($trans[0]) ? $trans[0] : '';
        $original = isset($trans[1]) ? $trans[1] : false;
        $original_translation = isset($trans[2]) ? html_entity_decode($trans[2]) : false;
        $plural = isset($trans[3]) ? $trans[3] : '';
        $plural_translation = isset($trans[4]) ? html_entity_decode($trans[4]) : false;
        $translation = $entries->find($context, $original, $plural);
        if ($translation) {
            $translation->setTranslation($original_translation);
            if ($plural) {
                $translation->setPlural($plural);
                if ($plural_translation) {
                    $translation->setPluralTranslation($plural_translation, 0);
                }
Exemple #3
0
 /**
  * @depends testPoFileExtractor
  */
 public function testMultiPlural($translations)
 {
     $translator = new \Gettext\Translator();
     $translator->loadTranslations($translations);
     //Set the current translator before execute the functions
     __currentTranslator($translator);
     /**
      * Test that nplural=3 plural translation check comes up with the correct translation key.
      */
     $this->assertEquals('1 plik', n__("one file", "multiple files", 1), "plural calculation result bad");
     $this->assertEquals('2,3,4 pliki', n__("one file", "multiple files", 2), "plural calculation result bad");
     $this->assertEquals('2,3,4 pliki', n__("one file", "multiple files", 3), "plural calculation result bad");
     $this->assertEquals('2,3,4 pliki', n__("one file", "multiple files", 4), "plural calculation result bad");
     $this->assertEquals('5-21 plików', n__("one file", "multiple files", 5), "plural calculation result bad");
     $this->assertEquals('5-21 plików', n__("one file", "multiple files", 6), "plural calculation result bad");
     /**
      * Test that when less then the nplural translations are available it still works.
      */
     $this->assertEquals('1', n__("one", "more", 1), "non-plural fallback failed");
     $this->assertEquals('*', n__("one", "more", 2), "non-plural fallback failed");
     $this->assertEquals('*', n__("one", "more", 3), "non-plural fallback failed");
     /**
      * Test that non-plural translations the fallback still works.
      */
     $this->assertEquals('more', n__("single", "more", 3), "non-plural fallback failed");
 }
<?php

if (!defined('BASE_PATH')) {
    exit('No direct script access allowed');
}
/**
 * eduTrac SIS Text Domain.
 *  
 * @license GPLv3
 * 
 * @since       6.1.13
 * @package     eduTrac SIS
 * @author      Joshua Parker <*****@*****.**>
 */
$t = new \Gettext\Translator();
$t->register();
/**
 * Loads the current or default locale.
 * 
 * @since 6.1.09
 * @return string The locale.
 */
function load_core_locale()
{
    $app = \Liten\Liten::getInstance();
    if (is_readable(BASE_PATH . 'config.php')) {
        $locale = get_option('et_core_locale');
    } else {
        $locale = 'en_US';
    }
    return $app->hook->apply_filter('core_locale', $locale);