本文整理汇总了PHP中PO类的典型用法代码示例。如果您正苦于以下问题:PHP PO类的具体用法?PHP PO怎么用?PHP PO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_on_translation_set
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);
}
示例2: add_translate_string
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);
}
示例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: action_on_translation_set
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: test_export_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: load_from_file
function load_from_file($ext_filename)
{
$makepot = new MakePOT();
$source = $makepot->get_first_lines($ext_filename);
$pot = '';
$po = new PO();
foreach ($this->headers as $header) {
$string = $makepot->get_addon_header($header, $source);
if (!$string) {
continue;
}
$args = array('singular' => $string, 'extracted_comments' => $header . ' of the plugin/theme');
$entry = new Translation_Entry($args);
$pot .= "\n" . $po->export_entry($entry) . "\n";
}
return $pot;
}
示例10: generate_pot
/**
* POT generator
*
* @param string $project "woocommerce" or "woocommerce-admin"
* @return bool true on success, false on error
*/
public function generate_pot($project = 'woocommerce')
{
// Unknown project
if (empty($this->projects[$project])) {
return false;
}
// Project config
$config = $this->projects[$project];
// Extract translatable strings from the WooCommerce plugin
$originals = $this->extractor->extract_from_directory($this->woocommerce_path, $config['excludes'], $config['includes']);
// Build POT file
$pot = new PO();
$pot->entries = $originals->entries;
$pot->set_header('Project-Id-Version', 'WooCommerce ' . $this->woocommerce_version() . ' ' . $config['title']);
$pot->set_header('Report-Msgid-Bugs-To', 'https://github.com/woothemes/woocommerce/issues');
$pot->set_header('POT-Creation-Date', gmdate('Y-m-d H:i:s+00:00'));
$pot->set_header('MIME-Version', '1.0');
$pot->set_header('Content-Type', 'text/plain; charset=UTF-8');
$pot->set_header('Content-Transfer-Encoding', '8bit');
$pot->set_header('PO-Revision-Date', gmdate('Y') . '-MO-DA HO:MI+ZONE');
$pot->set_header('Last-Translator', 'FULL NAME <EMAIL@ADDRESS>');
$pot->set_header('Language-Team', 'LANGUAGE <EMAIL@ADDRESS>');
// Write POT file
$result = $pot->export_to_file($config['file']);
// Add plugin header
if ($project == 'woocommerce-admin') {
$potextmeta = new PotExtMeta();
$potextmeta->append($this->woocommerce_path . 'woocommerce.php', $config['file']);
}
return $result;
}
示例11: store
/**
* Store a newly created resource in storage.
* POST /po
*
* @return Response
*/
public function store()
{
$validator = Validator::make(Input::all(), PO::$rules);
if ($validator->fails()) {
return Redirect::to('PO')->withErrors($validator)->withInput(Input::all());
} else {
$PO = new PO();
$PO->no_PO = Input::get('no_PO');
$PO->tgl_PO = Input::get('tgl_PO');
$PO->no_SPPB = Input::get('no_SPPB');
$PO->id_supp = Input::get('id_supp');
$PO->ship_to = Input::get('ship_to');
$PO->city = Input::get('city');
$PO->save();
Session::flash('message', 'Successfully created PO!');
return Redirect::to('PO');
}
}
示例12: export_as_po
function export_as_po()
{
if (!isset($this->project) || !$this->project) {
$this->project = GP::$project->get($this->project_id);
}
// TODO: rename locale column to locale_slug and use freely $this->locale as the locale object
$locale = GP_Locales::by_slug($this->locale);
$po = new PO();
// TODO: add more meta data in the project: language team, report URL
// TODO: last updated for a translation set
$po->set_header('PO-Revision-Date', gmdate('Y-m-d H:i:s+0000'));
$po->set_header('MIME-Version', '1.0');
$po->set_header('Content-Type', 'text/plain; charset=UTF-8');
$po->set_header('Content-Transfer-Encoding', '8bit');
$po->set_header('Plural-Forms', "nplurals={$locale->nplurals}; plural={$locale->plural_expression};");
$po->set_header('X-Generator', 'GlotPress/' . gp_get_option('version'));
$entries = GP::$translation->for_translation($this->project, $this, 'no-limit', array('status' => 'current'));
foreach ($entries as $entry) {
$po->add_entry($entry);
}
$po->set_header('Project-Id-Version', $this->project->name);
return $po->export();
}
示例13: generate_pot
/**
* POT generator
*
* @param string $project "redux" or "redux-admin"
* @return bool true on success, false on error
*/
public function generate_pot($project = 'redux')
{
// Unknown project
if (empty($this->projects[$project])) {
return false;
}
// Project config
$config = $this->projects[$project];
// Extract translatable strings from the ReduxFramework plugin
$originals = $this->extractor->extract_from_directory($this->redux_path, $config['excludes'], $config['includes']);
// Build POT file
$pot = new PO();
$pot->entries = $originals->entries;
$pot->set_header('Project-Id-Version', 'Redux Framework ' . $this->redux_version() . ' ' . $config['title']);
$pot->set_header('Report-Msgid-Bugs-To', 'https://github.com/ReduxFramework/ReduxFramework/issues');
$pot->set_header('POT-Creation-Date', gmdate('Y-m-d H:i:s+00:00'));
$pot->set_header('MIME-Version', '1.0');
$pot->set_header('Content-Type', 'text/plain; charset=UTF-8');
$pot->set_header('Content-Transfer-Encoding', '8bit');
$pot->set_header('PO-Revision-Date', gmdate('Y') . '-MO-DA HO:MI+ZONE');
$pot->set_header('Last-Translator', 'Dovy Paukstys <dovy@reduxframework.com>');
$pot->set_header('Language-Team', 'ReduxFramework <language@reduxframework.com>');
$pot->set_header('Language', 'en_US');
$pot->set_header('Plural-Forms', 'nplurals=2; plural=(n != 1);');
$pot->set_header('esc_html_x;_c;_nc', '');
$pot->set_header('_nx_noop;_ex;esc_attr__;esc_attr_e;esc_attr_x;esc_html__;esc_html_e;', '');
$pot->set_header('X-Poedit-KeywordsList', '__;_e;__ngettext;_n;__ngettext_noop;_n_noop;_x;_nx;');
$pot->set_header('X-Poedit-Basepath', '../../');
$pot->set_header('X-Poedit-SourceCharset', 'UTF-8');
$pot->set_header('X-Poedit-SearchPath-0', 'ReduxCore');
$pot->set_header('X-Poedit-SearchPath-1', 'ReduxCore/languages');
$pot->set_header('X-Poedit-SearchPath-2', '.');
// Write POT file
$result = $pot->export_to_file($config['file']);
// Add plugin header
if ($project == 'redux-admin') {
$potextmeta = new PotExtMeta();
$potextmeta->append($this->redux_path . 'redux-framework.php', $config['file']);
}
return $result;
}
示例14: test_import_from_file
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()]);
}
示例15: 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));
}