Exemplo n.º 1
0
 public function testScript()
 {
     $translations = Gettext\Extractors\JsCode::fromFile(__DIR__ . '/files/script.js');
     $string1 = $translations->toJedString();
     $string2 = file_get_contents(__DIR__ . '/files/jed.json');
     $this->assertEquals($string1, $string2);
 }
Exemplo n.º 2
0
//Simple autoload function
ini_set('display_errors', 'On');
//composer autoloader
include '../vendor/autoload.php';
$lang = isset($_GET['lang']) ? $_GET['lang'] : 'bg';
//$file_to_translate = 'javascript.js';
$file_to_translate = 'gettext.html.php';
//$file_to_translate = 'smarty.html';
$file_extension = substr($file_to_translate, stripos($file_to_translate, '.') + 1);
$file_with_translations = 'locale/' . $lang . '/' . $file_to_translate . '.php';
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;
Exemplo n.º 3
0
}
function buildOptions($args)
{
    $options = array('-o' => null, '-i' => null);
    $len = count($args);
    $i = 0;
    while ($i < $len) {
        if (preg_match('#^-[a-z]$#i', $args[$i])) {
            $options[$args[$i]] = isset($args[$i + 1]) ? trim($args[$i + 1]) : true;
            $i += 2;
        } else {
            $options[] = $args[$i];
            $i++;
        }
    }
    return $options;
}
spl_autoload_register('autoload');
$options = buildOptions($argv);
$input = $options['-i'];
$output = $options['-o'];
//Custom functions
Gettext\Extractors\JsCode::$functions = array('T_' => '__');
if (!strpos($input, ':\\') && $input[0] !== DIRECTORY_SEPARATOR) {
    $input = __DIR__ . DIRECTORY_SEPARATOR . $input;
}
if (!strpos($output, ':\\') && $output[0] !== DIRECTORY_SEPARATOR) {
    $output = __DIR__ . DIRECTORY_SEPARATOR . $output;
}
$Entries = Gettext\Extractors\JsCode::extract($input);
Gettext\Generators\Po::generateFile($Entries, $output);