Exemplo n.º 1
0
 function add_translate_string($entries)
 {
     //create mofile;
     $pot = new PO();
     $pot->import_from_file(dirname(__FILE__) . '/ce_alert.po', true);
     return array_merge($entries, $pot->entries);
 }
Exemplo n.º 2
0
 function action_on_translation_set($translation_set)
 {
     $po = new PO();
     $po->import_from_file($this->options['f']);
     $added = $translation_set->import($po);
     printf(_n("%s translation were added", "%s translations were added", $added), $added);
 }
Exemplo n.º 3
0
function wpll_create_mofile()
{
    global $wpll_pofile, $wpll_mofile;
    include_once ABSPATH . WPINC . '/pomo/po.php';
    $po = new PO();
    if (!@$po->import_from_file($wpll_pofile)) {
        return;
    }
    foreach ($po->entries as $key => $entry) {
        if (!empty($entry->references)) {
            $entry->references = array_filter($entry->references, 'wpll_filter_references');
            if (empty($entry->references)) {
                unset($po->entries[$key]);
                continue;
            }
        }
        if (!empty($entry->translations)) {
            if ($entry->singular == $entry->translations[0]) {
                unset($po->entries[$key]);
            }
        }
    }
    $mo = new MO();
    $mo->headers = $po->headers;
    $mo->entries = $po->entries;
    $mo->export_to_file($wpll_mofile);
    die;
}
Exemplo n.º 4
0
function ae_fields_add_translate_string($entries)
{
    $lang_path = dirname(__FILE__) . '/lang/default.po';
    if (file_exists($lang_path)) {
        $pot = new PO();
        $pot->import_from_file($lang_path, true);
        return array_merge($entries, $pot->entries);
    }
    return $entries;
}
Exemplo n.º 5
0
/**
 * Carrega um arquivo PO
 * @param string $language - codigo da linguagem
 * @param string $group - grupo que pertence a tradu��o
 * @param string <URL> $path - caminho para encontrar o arquivo
 * @return object
 */
function loadPO($language, $group = 'default', $path = false)
{
    global $cfg;
    $PO = new PO();
    $path = $path == false ? './' . $cfg['po_dir'] : $path . '/';
    $path .= $group . '.' . $language . ".po";
    if (file_exists($path)) {
        $PO->import_from_file(realpath($path));
        return $PO;
    }
    return false;
}
Exemplo n.º 6
0
 function action_on_translation_set($translation_set)
 {
     $po = new PO();
     $po->import_from_file($this->options['f']);
     $disable_propagating = isset($this->options['disable-propagating']);
     if ($disable_propagating) {
         add_filter('enable_propagate_translations_across_projects', '__return_false');
     }
     $added = $translation_set->import($po);
     if ($disable_propagating) {
         remove_filter('enable_propagate_translations_across_projects', '__return_false');
     }
     printf(_n("%s translation were added\n", "%s translations were added\n", $added), $added);
 }
Exemplo n.º 7
0
 function run()
 {
     if (!isset($this->options['p'])) {
         $this->usage();
     }
     $project = GP::$project->by_path($this->options['p']);
     if (!$project) {
         $this->error('Project not found!');
     }
     $translations = new PO();
     $translations->import_from_file($this->options['f']);
     if (!$translations) {
         $this->error('Error importing from POT file!');
     }
     GP::$original->import_for_project($project, $translations);
 }
Exemplo n.º 8
0
 function test_export_po()
 {
     $set = GP::$translation_set->create(array('name' => 'Set', 'slug' => 'set', 'project_id' => 1, 'locale' => 'bg'));
     GP::$translation->create(array('original_id' => 1, 'translation_set_id' => $set->id, 'translation_0' => 'Baba', 'user_id' => 1, 'status' => 'current'));
     GP::$translation->create(array('original_id' => 2, 'translation_set_id' => $set->id, 'translation_0' => 'Dudu', 'user_id' => 1, 'status' => 'waiting'));
     $po_file = $this->temp_filename();
     file_put_contents($po_file, $set->export_as_po());
     $po = new PO();
     $po->import_from_file($po_file);
     $translated = 0;
     foreach ($po->entries as $entry) {
         if (isset($entry->translations[0]) && $entry->translations[0]) {
             $translated += 1;
         }
     }
     $this->assertEquals(1, $translated);
 }
Exemplo n.º 9
0
 function add_translate_string($entries)
 {
     $pot = new PO();
     $pot->import_from_file(dirname(__FILE__) . '/default.po', true);
     return array_merge($entries, $pot->entries);
 }
Exemplo n.º 10
0
 function test_import_from_file()
 {
     $po = new PO();
     $res = $po->import_from_file('data/simple.po');
     $this->assertEquals(true, $res);
     $this->assertEquals(array('Project-Id-Version' => 'WordPress 2.6-bleeding', 'Plural-Forms' => 'nplurals=2; plural=n != 1;'), $po->headers);
     $simple_entry = new Translation_Entry(array('singular' => 'moon'));
     $this->assertEquals($simple_entry, $po->entries[$simple_entry->key()]);
     $all_types_entry = new Translation_Entry(array('singular' => 'strut', 'plural' => 'struts', 'context' => 'brum', 'translations' => array('ztrut0', 'ztrut1', 'ztrut2')));
     $this->assertEquals($all_types_entry, $po->entries[$all_types_entry->key()]);
     $multiple_line_entry = new Translation_Entry(array('singular' => 'The first thing you need to do is tell Blogger to let WordPress access your account. You will be sent back here after providing authorization.', 'translations' => array("baba\ndyadogugu")));
     $this->assertEquals($multiple_line_entry, $po->entries[$multiple_line_entry->key()]);
     $multiple_line_all_types_entry = new Translation_Entry(array('context' => 'context', 'singular' => 'singular', 'plural' => 'plural', 'translations' => array('translation0', 'translation1', 'translation2')));
     $this->assertEquals($multiple_line_all_types_entry, $po->entries[$multiple_line_all_types_entry->key()]);
     $comments_entry = new Translation_Entry(array('singular' => 'a', 'translator_comments' => "baba\nbrubru", 'references' => array('wp-admin/x.php:111', 'baba:333', 'baba'), 'extracted_comments' => "translators: buuu", 'flags' => array('fuzzy')));
     $this->assertEquals($comments_entry, $po->entries[$comments_entry->key()]);
     $end_quote_entry = new Translation_Entry(array('singular' => 'a"'));
     $this->assertEquals($end_quote_entry, $po->entries[$end_quote_entry->key()]);
 }
Exemplo n.º 11
0
 /**
  * Import a file into the translation set
  *
  * ## OPTIONS
  *
  * <project>
  * : Project path
  *
  * <locale>
  * : Locale to export
  *
  * <file>
  * : File to import
  *
  * [--set=<set>]
  * : Translation set slug; default is "default"
  *
  * [--disable-propagating]
  * : If set, propagation will be disabled.
  */
 public function import($args, $assoc_args)
 {
     $set_slug = isset($assoc_args['set']) ? $assoc_args['set'] : 'default';
     $translation_set = $this->get_translation_set($args[0], $args[1], $set_slug);
     if (is_wp_error($translation_set)) {
         WP_CLI::error($translation_set->get_error_message());
     }
     $po = new PO();
     $imported = $po->import_from_file($args[2]);
     if (!$imported) {
         WP_CLI::error(__("Couldn't load translations from file!", 'glotpress'));
     }
     $disable_propagating = isset($assoc_args['disable-propagating']);
     if ($disable_propagating) {
         add_filter('gp_enable_propagate_translations_across_projects', '__return_false');
     }
     $added = $translation_set->import($po);
     if ($disable_propagating) {
         remove_filter('gp_enable_propagate_translations_across_projects', '__return_false');
     }
     /* translators: %s: Number of imported translations */
     WP_CLI::line(sprintf(_n('%s translation was added', '%s translations were added', $added, 'glotpress'), $added));
 }
Exemplo n.º 12
0
 function test_import_from_file_with_windows_line_endings_should_work_as_with_unix_line_endings()
 {
     $po = new PO();
     $this->assertTrue($po->import_from_file('data/windows-line-endings.po'));
     $this->assertEquals(1, count($po->entries));
 }
Exemplo n.º 13
0
 /**
  * Import a file into the translation set
  *
  * ## OPTIONS
  *
  * <project>
  * : Project path
  *
  * <locale>
  * : Locale to export
  *
  * <file>
  * : File to import
  *
  * [--set=<set>]
  * : Translation set slug; default is "default"
  */
 public function import($args, $assoc_args)
 {
     $set_slug = isset($assoc_args['set']) ? $assoc_args['set'] : 'default';
     $translation_set = $this->get_translation_set($args[0], $args[1], $set_slug);
     if (is_wp_error($translation_set)) {
         WP_CLI::error($translation_set->get_error_message());
     }
     $po = new PO();
     $imported = $po->import_from_file($args[2]);
     if (!$imported) {
         WP_CLI::error(__("Couldn't load translations from file!", 'glotpress'));
     }
     $added = $translation_set->import($po);
     /* translators: %s: Number of imported translations */
     WP_CLI::line(sprintf(_n('%s translation was added', '%s translations were added', $added, 'glotpress'), $added));
 }
Exemplo n.º 14
0
 public function compilePot()
 {
     $this->prepareExport();
     $path = $this->getPath();
     $pot_file = $this->getPotFile();
     $this->makePot($path, $pot_file);
     // remove headers
     $po = new \PO();
     $po->import_from_file($pot_file);
     $po->export_to_file($pot_file, false);
 }
 /**
  * Load data from the file into the PO interface.
  *
  * @since 1.0.0
  *
  * @uses Project::$filename
  * @uses Project::$loaded
  *
  * @param bool $reload Force reload of the file?
  */
 public function load($reload = false)
 {
     if (!$reload && $this->loaded) {
         // Already loaded, no reload requested, abort
         return;
     }
     if (!file_exists($this->filename)) {
         throw new Exception("File not found ({$this->filename})");
     }
     $this->po->import_from_file($this->filename);
     $this->loaded = true;
 }
Exemplo n.º 16
0
 public function LoadPo($lang, $modulo = 'default')
 {
     $PO = new PO();
     $modulo = $this->cfg['po_dir'] . $modulo . '.' . $lang . '.po';
     $modulo2 = $this->cfg['modulo_dir'] . '/' . $modulo . '/' . $modulo . '.' . $lang . '.po';
     if (file_exists($modulo)) {
         $PO->import_from_file($modulo);
     } elseif (file_exists($modulo2)) {
         $PO->import_from_file($modulo);
     } else {
         return false;
     }
     return $PO;
 }