本文整理汇总了PHP中MO::export_to_file方法的典型用法代码示例。如果您正苦于以下问题:PHP MO::export_to_file方法的具体用法?PHP MO::export_to_file怎么用?PHP MO::export_to_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MO
的用法示例。
在下文中一共展示了MO::export_to_file方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: array
function test_export_mo_file()
{
$entries = array();
$entries[] = new Translation_Entry(array('singular' => 'pink', 'translations' => array('розов')));
$no_translation_entry = new Translation_Entry(array('singular' => 'grey'));
$entries[] = new Translation_Entry(array('singular' => 'green', 'plural' => 'greens', 'translations' => array('зелен', 'зелени')));
$entries[] = new Translation_Entry(array('singular' => 'red', 'context' => 'color', 'translations' => array('червен')));
$entries[] = new Translation_Entry(array('singular' => 'red', 'context' => 'bull', 'translations' => array('бик')));
$entries[] = new Translation_Entry(array('singular' => 'maroon', 'plural' => 'maroons', 'context' => 'context', 'translations' => array('пурпурен', 'пурпурни')));
$mo = new MO();
$mo->set_header('Project-Id-Version', 'Baba Project 1.0');
foreach ($entries as $entry) {
$mo->add_entry($entry);
}
$mo->add_entry($no_translation_entry);
$temp_fn = $this->temp_filename();
$mo->export_to_file($temp_fn);
$again = new MO();
$again->import_from_file($temp_fn);
$this->assertEquals(count($entries), count($again->entries));
foreach ($entries as $entry) {
$this->assertEquals($entry, $again->entries[$entry->key()]);
}
}
示例3: MO
/**
* change language : if language file not exist return false
* if language file not in THEME_LANGUAGE_PATH copy it from DEFAULT_LANG to THEME_LANGUAGE_PATH
* @since 1.0
*/
function change_language()
{
$lang = $_REQUEST['lang_name'];
if (!in_array($lang, $this->get_language_list())) {
wp_send_json(array('success' => false));
}
if (!in_array($lang, get_available_languages(THEME_LANGUAGE_PATH))) {
$mo = new MO();
$mo->set_header('Project-Id-Version', THEME_NAME . 'v' . ET_VERSION);
$mo->set_header('Report-Msgid-Bugs-To', ET_URL);
$mo->set_header('MO-Creation-Date', gmdate('Y-m-d H:i:s+00:00'));
$mo->set_header('MIME-Version', '1.0');
$mo->set_header('Content-Type', 'text/plain; charset=UTF-8');
$mo->set_header('Content-Transfer-Encoding', '8bit');
$mo->set_header('MO-Revision-Date', '2010-MO-DA HO:MI+ZONE');
$mo->set_header('Last-Translator', 'JOB <EMAIL@ADDRESS>');
$mo->set_header('Language-Team', 'ENGINETHEMES.COM <enginethemes@enginethemes.com>');
$mo->import_from_file(DEFAULT_LANGUAGE_PATH . '/' . $lang . '.mo');
$mo->export_to_file(THEME_LANGUAGE_PATH . '/' . $lang . '.mo');
}
$this->set_site_language($lang);
wp_send_json(array('success' => true, 'data' => array('ID' => $lang, 'lang_name' => $lang)));
}
示例4: array
function test_export_should_not_include_empty_translations()
{
$entries = array();
$mo = new MO();
$mo->add_entry(array('singular' => 'baba', 'translations' => array('', '')));
$temp_fn = $this->temp_filename();
$mo->export_to_file($temp_fn);
$again = new MO();
$again->import_from_file($temp_fn);
$this->assertEquals(0, count($again->entries));
}
示例5: compilePo
public static function compilePo($po_file, $mo_file)
{
$po = new \PO();
$po->import_from_file($po_file);
$mo = new \MO();
$mo->headers = $po->headers;
$mo->entries = $po->entries;
$mo->export_to_file($mo_file);
}
示例6: export
/**
* Save the PO file and compile corresponding MO file.
*
* @since 1.2.0 Removed .bak creation, added destination directory generating.
* @since 1.0.0
*
* @uses \PO::export_to_file() to save the updated PO file.
* @uses \MO::export_to_file() to compile the MO file.
*
* @param string $file Optional The file path/name to use.
*/
public function export($file = null)
{
// Override file property with provided filename
if ($file) {
$this->filename = $file;
}
// Fail if no filename is available
if (!$this->filename) {
throw new Exception('No path specified to save to.');
}
// Load necessary libraries
require_once ABSPATH . WPINC . '/pomo/mo.php';
$mo = new \MO();
// Create the .po and .mo filenames appropriately
if (substr($this->filename, -3) == '.po') {
// .po extension exists...
$po_file = $this->filename;
// ...replace with .mo
$mo_file = substr($this->filename, 0, -3) . '.mo';
} else {
// No extension, add each
$po_file = $this->filename . '.po';
$mo_file = $this->filename . '.mo';
}
// Copy all properties from the PO interface to the MO one
foreach (get_object_vars($this->po) as $key => $val) {
$mo->{$key} = $val;
}
// Ensure the parent directory exists
wp_mkdir_p(dirname($po_file));
// Export the PO file
$this->po->export_to_file($po_file);
// Compile the MO file
$mo->export_to_file($mo_file);
}