本文整理汇总了PHP中PO::import_from_file方法的典型用法代码示例。如果您正苦于以下问题:PHP PO::import_from_file方法的具体用法?PHP PO::import_from_file怎么用?PHP PO::import_from_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PO
的用法示例。
在下文中一共展示了PO::import_from_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PO
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);
}
示例2: PO
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);
}
示例3: wpll_create_mofile
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;
}
示例4: ae_fields_add_translate_string
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;
}
示例5: loadPO
/**
* 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;
}
示例6: PO
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);
}
示例7: run
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);
}
示例8: PO
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);
}
示例9: PO
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()]);
}
示例10: import
/**
* 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));
}
示例11: PO
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));
}
示例12: import
/**
* 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));
}
示例13: compilePot
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);
}
示例14: load
/**
* 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;
}
示例15: LoadPo
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;
}