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; }
public function filterOverrideLoadTextdomain($override, $domain, $mofile) { global $l10n; $key = md5($mofile); $data = $this->getCacheFileContent($key); $mo = new \MO(); if (!$data) { if (is_file($mofile) && $mo->import_from_file($mofile)) { $data = ['entries' => $mo->entries, 'headers' => $mo->headers]; $this->setCacheFileContent($key, $data); } else { return false; } } else { if (isset($data['entries'])) { $mo->entries = $data['entries']; } if (isset($data['headers'])) { $mo->headers = $data['headers']; } } if (isset($l10n[$domain])) { $mo->merge_with($l10n[$domain]); } $l10n[$domain] =& $mo; return true; }
function &load_translations($mo_filename) { if (is_readable($mo_filename)) { $translations = new MO(); $translations->import_from_file($mo_filename); } else { $translations = new Translations(); } return $translations; }
function load_textdomain($domain, $mofile) { global $l10n; if (!is_readable($mofile)) { return; } $mo = new MO(); $mo->import_from_file($mofile); if (isset($l10n[$domain])) { $mo->merge_with($l10n[$domain]); } $l10n[$domain] =& $mo; }
function __i18n_load_db_mo( $lang, $mofile ) { global $__i18n; if ( ! is_readable($mofile) ) return false; $mo = new MO(); if ( ! $mo->import_from_file($mofile) ) return false; if ( isset($__i18n[$lang]) ) { $mo->merge_with($__i18n[$lang]); } $__i18n[$lang] = &$mo; return true; }
static function load_textdomain($domain, $mofile) { if (!is_readable($mofile)) { return false; } $mo = new MO(); if (!$mo->import_from_file($mofile)) { return false; } if (isset(self::$l10n[$domain])) { $mo->merge_with(self::$l10n[$domain]); } self::$l10n[$domain] =& $mo; return true; }
function import_from_reader($reader) { $reader->setEndian('little'); $endian = MO::get_byteorder($reader->readint32()); if (false === $endian) { return false; } $reader->setEndian($endian); $revision = $reader->readint32(); $total = $reader->readint32(); // get addresses of array of lenghts and offsets for original string and translations $originals_lo_addr = $reader->readint32(); $translations_lo_addr = $reader->readint32(); $reader->seekto($originals_lo_addr); $originals_lo = $reader->readint32array($total * 2); // each of $reader->seekto($translations_lo_addr); $translations_lo = $reader->readint32array($total * 2); $length = create_function('$i', 'return $i * 2 + 1;'); $offset = create_function('$i', 'return $i * 2 + 2;'); for ($i = 0; $i < $total; ++$i) { $reader->seekto($originals_lo[$offset($i)]); $original = $reader->read($originals_lo[$length($i)]); $reader->seekto($translations_lo[$offset($i)]); $translation = $reader->read($translations_lo[$length($i)]); if ('' == $original) { $this->set_headers($this->make_headers($translation)); } else { $this->add_entry($this->make_entry($original, $translation)); } } return true; }
function load_textdomain($domain, $mofile) { $l10n = get_i18n_cache(); if (!is_readable($mofile)) { return false; } $mo = new MO(); if (!$mo->import_from_file($mofile)) { return false; } if (isset($l10n[$domain])) { $mo->merge_with($l10n[$domain]); } $l10n[$domain] =& $mo; set_i18n_cache($l10n); return true; }
/** * Load a .mo file into the text domain $domain. * * If the text domain already exists, the translations will be merged. If both * sets have the same string, the translation from the original value will be taken. * * On success, the .mo file will be placed in the $l10n global by $domain * and will be a MO object. * * @param string $domain Text domain. Unique identifier for retrieving translated strings. * @param string $mofile Path to the .mo file. * * @return boolean True on success, false on failure. * * Inspired from Luna <http://getluna.org> */ function translate($mofile, $domain = 'featherbb', $language = false) { global $l10n; if (!$language) { $mofile = ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/' . $mofile . '.mo'; } else { $mofile = ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . $language . '/' . $mofile . '.mo'; } if (!is_readable($mofile)) { return false; } $mo = new MO(); if (!$mo->import_from_file($mofile)) { return false; } if (isset($l10n[$domain])) { $mo->merge_with($l10n[$domain]); } $l10n[$domain] =& $mo; return true; }
function load_textdomain($domain, $mofile) { global $l10n; $plugin_override = apply_filters('override_load_textdomain', false, $domain, $mofile); if (true == $plugin_override) { return true; } do_action('load_textdomain', $domain, $mofile); $mofile = apply_filters('load_textdomain_mofile', $mofile, $domain); if (!is_readable($mofile)) { return false; } $mo = new MO(); if (!$mo->import_from_file($mofile)) { return false; } if (isset($l10n[$domain])) { $mo->merge_with($l10n[$domain]); } $l10n[$domain] =& $mo; return true; }
private function get_translations_for_domain($domain = "default") { if ($this->entries != null) { return true; } $mo = new MO(); $current_language = JFactory::getLanguage(); $mo_file = JPATH_COMPONENT . DIRECTORY_SEPARATOR . "language" . DIRECTORY_SEPARATOR . $domain . "-" . $current_language->getTag() . ".mo"; if (!file_exists($mo_file)) { $mo_file = JPATH_COMPONENT . DIRECTORY_SEPARATOR . "language" . DIRECTORY_SEPARATOR . $domain . "-" . str_replace("-", "_", $current_language->getTag()) . ".mo"; if (!file_exists($mo_file)) { return false; } } if (!$mo->import_from_file($mo_file)) { return false; } if (!isset($lang[$domain])) { $lang[$domain] = $mo; } $this->merge_with($lang[$domain]); }
/** * Load a .mo file into the text domain $domain. * * If the text domain already exists, the translations will be merged. If both * sets have the same string, the translation from the original value will be taken. * * On success, the .mo file will be placed in the $l10n global by $domain * and will be a MO object. * * @since 1.5.0 * * @global array $l10n * * @param string $domain Text domain. Unique identifier for retrieving translated strings. * @param string $mofile Path to the .mo file. * @return bool True on success, false on failure. */ function load_textdomain($domain, $mofile) { global $l10n; /** * Filter text domain and/or MO file path for loading translations. * * @since 2.9.0 * * @param bool $override Whether to override the text domain. Default false. * @param string $domain Text domain. Unique identifier for retrieving translated strings. * @param string $mofile Path to the MO file. */ $plugin_override = apply_filters('override_load_textdomain', false, $domain, $mofile); if (true == $plugin_override) { return true; } /** * Fires before the MO translation file is loaded. * * @since 2.9.0 * * @param string $domain Text domain. Unique identifier for retrieving translated strings. * @param string $mofile Path to the .mo file. */ do_action('load_textdomain', $domain, $mofile); /** * Filter MO file path for loading translations for a specific text domain. * * @since 2.9.0 * * @param string $mofile Path to the MO file. * @param string $domain Text domain. Unique identifier for retrieving translated strings. */ $mofile = apply_filters('load_textdomain_mofile', $mofile, $domain); if (!is_readable($mofile)) { return false; } $mo = new MO(); if (!$mo->import_from_file($mofile)) { return false; } if (isset($l10n[$domain])) { $mo->merge_with($l10n[$domain]); } $l10n[$domain] =& $mo; return true; }
/** * 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 <*****@*****.**>'); $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))); }
/** * Load a Text Domain * @author Howard <*****@*****.**> * @static * @global array $l10n * @param string $domain * @param string $mofile * @return boolean */ public static function load_textdomain($domain, $mofile) { global $l10n; unset($l10n[$domain]); if (!is_readable($mofile)) { return false; } $mo = new MO(); if (!$mo->import_from_file($mofile)) { return false; } $l10n[$domain] =& $mo; return true; }
header("Content-Length: 0"); ob_end_flush(); flush(); // set memory limit to the same as WP. if (function_exists('memory_get_usage') && inbytes(@ini_get('memory_limit')) < inbytes($STATIC['WP']['MEMORY_LIMIT'])) { @ini_set('memory_limit', $STATIC['WP']['MEMORY_LIMIT']); } //check existing Logfile if (empty($STATIC) or !is_file($STATIC['LOGFILE'])) { delete_working_file(); die('No logfile found!'); } //load translation if (is_file(dirname(__FILE__) . '/../lang/backwpup-' . $STATIC['WP']['WPLANG'] . '.mo')) { require $STATIC['WP']['ABSPATH'] . $STATIC['WP']['WPINC'] . '/pomo/mo.php'; $TRANSLATE = new MO(); $TRANSLATE->import_from_file(dirname(__FILE__) . '/../lang/backwpup-' . $STATIC['WP']['WPLANG'] . '.mo'); } else { require $STATIC['WP']['ABSPATH'] . $STATIC['WP']['WPINC'] . '/pomo/translations.php'; $TRANSLATE = new NOOP_Translations(); } //set ticks declare (ticks=1); //set timezone date_default_timezone_set('UTC'); // set charakter encoding if (!@mb_internal_encoding($STATIC['WP']['CHARSET'])) { mb_internal_encoding('UTF-8'); } //set function for PHP user defineid error handling set_error_handler('joberrorhandler', E_ALL | E_STRICT);
private function load_translations_from_mo($mo_file) { $translations = array(); $mo = new MO(); $pomo_reader = new POMO_CachedFileReader($mo_file); $mo->import_from_reader($pomo_reader); foreach ($mo->entries as $str => $v) { $str = str_replace("\n", '\\n', $v->singular); $translations[] = array('orig' => $str, 'trans' => $v->translations[0], 'context' => $v->context); if ($v->is_plural) { $str = str_replace("\n", '\\n', $v->plural); $translation = !empty($v->translations[1]) ? $v->translations[1] : $v->translations[0]; $translations[] = array('orig' => $str, 'trans' => $translation, 'context' => $v->context); } } return $translations; }
function get_translation_from_woocommerce_mo_file($string, $language, $return_original = true) { global $sitepress; $original_string = $string; if (!isset($this->translations_from_mo_file[$original_string][$language])) { if (!isset($this->translations_from_mo_file[$original_string])) { $this->translations_from_mo_file[$original_string] = array(); } if (!isset($this->mo_files[$language])) { $mo = new MO(); $mo_file = WP_LANG_DIR . '/plugins/woocommerce-' . $sitepress->get_locale($language) . '.mo'; if (!file_exists($mo_file)) { return $return_original ? $string : null; } $mo->import_from_file($mo_file); $this->mo_files[$language] =& $mo->entries; } if (in_array($string, array('product', 'product-category', 'product-tag'))) { $string = 'slug' . chr(4) . $string; } if (isset($this->mo_files[$language][$string])) { $this->translations_from_mo_file[$original_string][$language] = $this->mo_files[$language][$string]->translations[0]; } else { $this->translations_from_mo_file[$original_string][$language] = $return_original ? $original_string : null; } } return $this->translations_from_mo_file[$original_string][$language]; }
/** * @param bool $override Whether to override the .mo file loading. Default false. * @param string $domain Text domain. Unique identifier for retrieving translated strings. * @param string $file Path to the MO file. * @return bool */ function _override_load_textdomain_filter($override, $domain, $file) { global $l10n; if (!is_readable($file)) { return false; } $mo = new MO(); if (!$mo->import_from_file($file)) { return false; } if (isset($l10n[$domain])) { $mo->merge_with($l10n[$domain]); } $l10n[$domain] =& $mo; return true; }
function icl_st_load_translations_from_mo($mo_file) { $translations = array(); $mo = new MO(); $mo->import_from_file($mo_file); foreach ($mo->entries as $str => $v) { $str = str_replace("\n", '\\n', $str); $translations[$str] = $v->translations[0]; } return $translations; }
/** * Load a collection of `.mo` files into the text domain $domain. * * If the text domain already exists, the translations will be merged. If both * sets have the same string, the translation from the original value will be taken. * * On success, the `.mo` files are placed in the $pll_l10n global by $domain * and will be a MO object. * * @param string $domain Text domain. Unique identifier for retrieving translated strings. * @return bool True on success, false on failure. * * @package WordPress\Skeleton\Polylang * @see WordPress\load_textdomain */ function pll_load_textdomain($domain) { global $polylang, $pll_domains, $pll_l10n; if (!is_object($polylang)) { return false; } if (empty($pll_domains[$domain])) { return false; } $pll_domain = $pll_domains[$domain]; $languages_list = $polylang->model->get_languages_list(); foreach ($languages_list as $language) { $locale = $language->locale; $mo = new MO(); foreach ($pll_domain as $dirname => $basename) { $mofile = $dirname . '/' . sprintf($basename, $locale); if (!is_readable($mofile)) { continue; } if (!$mo->import_from_file($mofile)) { continue; } if (isset($pll_l10n[$domain][$language->slug])) { $mo->merge_with($pll_l10n[$domain][$language->slug]); } $pll_l10n[$domain][$language->slug] = $mo; } } return true; }
function test_load_pot_file() { $mo = new MO(); $this->assertEquals(false, $mo->import_from_file(DIR_TESTDATA . '/pomo/mo.pot')); }
public function language($langid = 'default') { if (!function_exists('gettext')) { $this->language_status = 'user'; $mofile = $this->dir_root . 'langs/' . $langid . '/LC_MESSAGES/' . $this->app_id . '.mo'; if (!is_readable($mofile)) { return false; } include $this->dir_phpok . 'libs/pomo/mo.php'; $this->lang = new NOOP_Translations(); $mo = new MO(); if (!$mo->import_from_file($mofile)) { return false; } $mo->merge_with($this->lang); $this->lang =& $mo; } else { $this->language_status = 'gettext'; if ($langid != 'default' && $langid != 'cn') { putenv('LANG=' . $langid); setlocale(LC_ALL, $langid); bindtextdomain($this->app_id, $this->dir_root . 'langs'); textdomain($this->app_id); } else { putenv('LANG=zh_CN'); setlocale(LC_ALL, 'zh_CN'); bindtextdomain($this->app_id, $this->dir_root . 'langs'); textdomain($this->app_id); } } }
function admin_init() { $options = get_option('polylang'); if (version_compare($options['version'], POLYLANG_VERSION, '<')) { if (version_compare($options['version'], '0.4', '<')) { $options['hide_default'] = 0; } // option introduced in 0.4 // translation model changed in V0.5 if (version_compare($options['version'], '0.5', '<')) { $ids = get_posts(array('numberposts' => -1, 'fields' => 'ids', 'post_type' => 'any', 'post_status' => 'any')); $this->upgrade_translations('post', $ids); $ids = get_terms($this->taxonomies, array('get' => 'all', 'fields' => 'ids')); $this->upgrade_translations('term', $ids); } // translation model changed in V0.5 // deleting the old one has been delayed in V0.6 (just in case...) if (version_compare($options['version'], '0.6', '<')) { $listlanguages = $this->get_languages_list(); $ids = get_posts(array('numberposts' => -1, 'fields' => 'ids', 'post_type' => 'any', 'post_status' => 'any')); foreach ($ids as $id) { foreach ($listlanguages as $lang) { delete_post_meta($id, '_lang-' . $lang->slug); } } $ids = get_terms($this->taxonomies, array('get' => 'all', 'fields' => 'ids')); foreach ($ids as $id) { foreach ($listlanguages as $lang) { delete_metadata('term', $id, '_lang-' . $lang->slug); } } } if (version_compare($options['version'], '0.7', '<')) { $options['force_lang'] = 0; } // option introduced in 0.7 // string translation storage model changed and option added in 0.8 if (version_compare($options['version'], '0.8dev1', '<')) { if (function_exists('base64_decode')) { $mo = new MO(); foreach ($this->get_languages_list() as $language) { $reader = new POMO_StringReader(base64_decode(get_option('polylang_mo' . $language->term_id))); $mo->import_from_reader($reader); $this->mo_export($mo, $language); } } $options['redirect_lang'] = 0; // option introduced in 0.8 } if (version_compare($options['version'], '0.8.8', '<')) { flush_rewrite_rules(); } // rewrite rules have been modified in 0.8.8 if (version_compare($options['version'], '0.9', '<')) { $options['sync'] = defined('PLL_SYNC') && !PLL_SYNC ? 0 : 1; } // the option replaces PLL_SYNC in 0.9 $options['version'] = POLYLANG_VERSION; update_option('polylang', $options); } }
function test_load_pot_file() { $mo = new MO(); $this->assertEquals(false, $mo->import_from_file('data/mo.pot')); }
/** * Loads MO file into the list of domains * * If the domain already exists, the inclusion will fail. If the * MO file is not readable, the inclusion will fail. * * @since 1.0 * @uses CacheFileReader Reads the MO file * @uses gettext_reader Allows for retrieving translated strings * * @param string $domain Unique identifier for retrieving translated strings * @param string $mofile Path to the .mo file * @return bool Successfulness of loading textdomain */ public static function load($domain, $mofile) { if (!is_readable($mofile)) { return; } $mo = new MO(); $mo->import_from_file($mofile); if (isset(self::$translations[$domain])) { $mo->merge_with(self::$translations[$domain]); } self::$translations[$domain] =& $mo; }
function import_from_reader($reader) { $endian_string = MO::get_byteorder($reader->readint32()); if (false === $endian_string) { return false; } $reader->setEndian($endian_string); $endian = ('big' == $endian_string)? 'N' : 'V'; $header = $reader->read(24); if ($reader->strlen($header) != 24) return false; $header = unpack("{$endian}revision/{$endian}total/{$endian}originals_lenghts_addr/{$endian}translations_lenghts_addr/{$endian}hash_length/{$endian}hash_addr", $header); if (!is_array($header)) return false; extract( $header ); if ($revision != 0) return false; $reader->seekto($originals_lenghts_addr); $originals_lengths_length = $translations_lenghts_addr - $originals_lenghts_addr; if ( $originals_lengths_length != $total * 8 ) return false; $originals = $reader->read($originals_lengths_length); if ( $reader->strlen( $originals ) != $originals_lengths_length ) return false; $translations_lenghts_length = $hash_addr - $translations_lenghts_addr; if ( $translations_lenghts_length != $total * 8 ) return false; $translations = $reader->read($translations_lenghts_length); if ( $reader->strlen( $translations ) != $translations_lenghts_length ) return false; $originals = $reader->str_split( $originals, 8 ); $translations = $reader->str_split( $translations, 8 ); $strings_addr = $hash_addr + $hash_length * 4; $reader->seekto($strings_addr); $strings = $reader->read_all(); $reader->close(); for ( $i = 0; $i < $total; $i++ ) { $o = unpack( "{$endian}length/{$endian}pos", $originals[$i] ); $t = unpack( "{$endian}length/{$endian}pos", $translations[$i] ); if ( !$o || !$t ) return false; $o['pos'] -= $strings_addr; $t['pos'] -= $strings_addr; $original = $reader->substr( $strings, $o['pos'], $o['length'] ); $translation = $reader->substr( $strings, $t['pos'], $t['length'] ); if ('' === $original) { $this->set_headers($this->make_headers($translation)); } else { $entry = &$this->make_entry($original, $translation); $this->entries[$entry->key()] = &$entry; } } return true; }
function get_translations($language, $args = array()) { global $wpdb; $translations = array(); // defaults $defaults = array('types' => array('core')); extract($defaults); extract($args, EXTR_OVERWRITE); if (!class_exists('WP_Http')) { include_once ABSPATH . WPINC . '/class-http.php'; } $client = new WP_Http(); foreach ($types as $type) { if (isset($this->translation_files[$language][$type]['url'])) { $response = $client->request($this->translation_files[$language][$type]['url'], array('timeout' => 15)); if (is_wp_error($response)) { $err = __('Error getting the translation file. Please go back and try again.', 'wordpress-language'); if (isset($response->errors['http_request_failed'][0])) { $err .= '<br />' . $response->errors['http_request_failed'][0]; } echo '<div class="error"><p>' . $err . '</p></div>'; return false; } $mo = new MO(); $pomo_reader = new POMO_StringReader($response['body']); $mo->import_from_reader($pomo_reader); foreach ($mo->entries as $key => $v) { $tpairs = array(); $v->singular = str_replace("\n", '\\n', $v->singular); $tpairs[] = array('string' => $v->singular, 'translation' => $v->translations[0], 'name' => !empty($v->context) ? $v->context . ': ' . $v->singular : md5($v->singular)); if ($v->is_plural) { $v->plural = str_replace("\n", '\\n', $v->plural); $tpairs[] = array('string' => $v->plural, 'translation' => !empty($v->translations[1]) ? $v->translations[1] : $v->translations[0], 'name' => !empty($v->context) ? $v->context . ': ' . $v->plural : md5($v->singular)); } foreach ($tpairs as $pair) { $existing_translation = $wpdb->get_var($wpdb->prepare("\n SELECT st.value \n FROM {$wpdb->prefix}icl_string_translations st\n JOIN {$wpdb->prefix}icl_strings s ON st.string_id = s.id\n WHERE s.context = %s AND s.name = %s AND st.language = %s \n ", self::CONTEXT, $pair['name'], $language)); if (empty($existing_translation)) { $translations['new'][] = array('string' => $pair['string'], 'translation' => '', 'new' => $pair['translation'], 'name' => $pair['name']); } else { if (strcmp($existing_translation, $pair['translation']) !== 0) { $translations['updated'][] = array('string' => $pair['string'], 'translation' => $existing_translation, 'new' => $pair['translation'], 'name' => $pair['name']); } } } } } } return $translations; }
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); }
/** * @param POMO_FileReader $reader */ function import_from_reader($reader) { $endian_string = MO::get_byteorder($reader->readint32()); if (false === $endian_string) { return false; } $reader->setEndian($endian_string); $endian = 'big' == $endian_string ? 'N' : 'V'; $header = $reader->read(24); if ($reader->strlen($header) != 24) { return false; } // parse header $header = unpack("{$endian}revision/{$endian}total/{$endian}originals_lenghts_addr/{$endian}translations_lenghts_addr/{$endian}hash_length/{$endian}hash_addr", $header); if (!is_array($header)) { return false; } // support revision 0 of MO format specs, only if ($header['revision'] != 0) { return false; } // seek to data blocks $reader->seekto($header['originals_lenghts_addr']); // read originals' indices $originals_lengths_length = $header['translations_lenghts_addr'] - $header['originals_lenghts_addr']; if ($originals_lengths_length != $header['total'] * 8) { return false; } $originals = $reader->read($originals_lengths_length); if ($reader->strlen($originals) != $originals_lengths_length) { return false; } // read translations' indices $translations_lenghts_length = $header['hash_addr'] - $header['translations_lenghts_addr']; if ($translations_lenghts_length != $header['total'] * 8) { return false; } $translations = $reader->read($translations_lenghts_length); if ($reader->strlen($translations) != $translations_lenghts_length) { return false; } // transform raw data into set of indices $originals = $reader->str_split($originals, 8); $translations = $reader->str_split($translations, 8); // skip hash table $strings_addr = $header['hash_addr'] + $header['hash_length'] * 4; $reader->seekto($strings_addr); $strings = $reader->read_all(); $reader->close(); for ($i = 0; $i < $header['total']; $i++) { $o = unpack("{$endian}length/{$endian}pos", $originals[$i]); $t = unpack("{$endian}length/{$endian}pos", $translations[$i]); if (!$o || !$t) { return false; } // adjust offset due to reading strings to separate space before $o['pos'] -= $strings_addr; $t['pos'] -= $strings_addr; $original = $reader->substr($strings, $o['pos'], $o['length']); $translation = $reader->substr($strings, $t['pos'], $t['length']); if ('' === $original) { $this->set_headers($this->make_headers($translation)); } else { $entry =& $this->make_entry($original, $translation); $this->entries[$entry->key()] =& $entry; } } return true; }
/** * Loads a MO file into the domain $domain. * * If the domain already exists, the translations will be merged. If both * sets have the same string, the translation from the original value will be taken. * * On success, the .mo file will be placed in the $yourls_l10n global by $domain * and will be a MO object. * * @since 1.6 * @uses $yourls_l10n Gets list of domain translated string objects * * @param string $domain Unique identifier for retrieving translated strings * @param string $mofile Path to the .mo file * @return bool True on success, false on failure */ function yourls_load_textdomain($domain, $mofile) { global $yourls_l10n; $plugin_override = yourls_apply_filter('override_load_textdomain', false, $domain, $mofile); if (true == $plugin_override) { return true; } yourls_do_action('load_textdomain', $domain, $mofile); $mofile = yourls_apply_filter('load_textdomain_mofile', $mofile, $domain); if (!is_readable($mofile)) { trigger_error('Cannot read file ' . str_replace(YOURLS_ABSPATH . '/', '', $mofile) . '.' . ' Make sure there is a language file installed. More info: http://yourls.org/translations'); return false; } $mo = new MO(); if (!$mo->import_from_file($mofile)) { return false; } if (isset($yourls_l10n[$domain])) { $mo->merge_with($yourls_l10n[$domain]); } $yourls_l10n[$domain] =& $mo; return true; }