Пример #1
0
 /**
  * Exports only specified add-on language data
  *
  * @param  string $addon_id       Addon ID (like: gift_certificates, buy_together)
  * @param  string $pack_path      Path to exported PO-file
  * @param  string $lang_code      2-letters language code
  * @param  array  $current_values Current lang values from DB
  * @return array  Exported data
  */
 private static function exportAddonsPo($addon_id, $pack_path, $lang_code, $current_values = array())
 {
     // Translation packs should not include "Not translated" language data
     $allow_overlap = $lang_code == 'en' ? true : false;
     $langs = self::get(array('lang_code' => $lang_code));
     $lang = $langs[$lang_code];
     fn_rm($pack_path);
     Po::createHeader($pack_path, $lang);
     $addon_scheme = SchemesManager::getScheme($addon_id);
     $values = array();
     $originals = $addon_scheme->getOriginals();
     $_addon[] = array('name' => $addon_id, 'value' => $addon_scheme->getName($lang_code), 'original_value' => $originals['name']);
     $_addon = Po::convert($_addon, array(), $allow_overlap);
     $values = array_merge($values, Po::putValues('Addons' . \I18n_Pofile::DELIMITER . 'name', $_addon, $pack_path));
     $_description[] = array('name' => $addon_id, 'value' => $addon_scheme->getDescription($lang_code), 'original_value' => $originals['description']);
     $_description = Po::convert($_description, array(), $allow_overlap);
     $values = array_merge($values, Po::putValues('Addons' . \I18n_Pofile::DELIMITER . 'description', $_description, $pack_path));
     unset($_addon, $_description, $originals);
     $language_variables = $addon_scheme->getLanguageValues(false);
     $original_variables = $addon_scheme->getLanguageValues(true);
     $_originals = array();
     foreach ($original_variables as $id => $val) {
         $_originals[$val['msgctxt']] = $val;
     }
     $original_variables = $_originals;
     unset($_originals);
     $_values = array();
     foreach ($language_variables as $variable) {
         if ($lang_code != $variable['lang_code']) {
             continue;
         }
         $key = 'Languages' . \I18n_Pofile::DELIMITER . $variable['name'];
         $_values[] = array('name' => $variable['name'], 'value' => isset($current_values[$key]) ? $current_values[$key]['value'] : $variable['value'], 'original_value' => isset($original_variables[$key]) ? $original_variables[$key]['msgid'] : '');
     }
     $_values = Po::convert($_values, array(), $allow_overlap);
     $values = array_merge($values, Po::putValues('Languages', $_values, $pack_path));
     unset($original_variables, $language_variables);
     $_tooltips = array();
     $original_tooltips = self::getOriginalValues('SettingsTooltips');
     $section = Settings::instance()->getSectionByName($addon_id, Settings::ADDON_SECTION);
     if (!empty($section)) {
         $subsections = Settings::instance()->getSectionTabs($section['section_id'], $lang_code);
         if (!empty($subsections)) {
             $_sub_sections = array();
             $original_values = self::getOriginalValues('SettingsSections');
             foreach ($subsections as $subsection) {
                 $_sub_sections[] = array('name' => $subsection['name'], 'value' => $subsection['description'], 'original_value' => isset($original_values['SettingsSections' . \I18n_Pofile::DELIMITER . $addon_id . \I18n_Pofile::DELIMITER . $subsection['name']]) ? $original_values['SettingsSections' . \I18n_Pofile::DELIMITER . $addon_id . \I18n_Pofile::DELIMITER . $subsection['name']]['msgid'] : '');
             }
             $_sub_sections = Po::convert($_sub_sections, array(), $allow_overlap);
             $values = array_merge($values, Po::putValues('SettingsSections' . \I18n_Pofile::DELIMITER . $addon_id, $_sub_sections, $pack_path));
             unset($_sub_sections, $original_values);
         }
         unset($subsections);
         $section_options = Settings::instance()->getList($section['section_id'], 0, false, null, $lang_code);
         $original_options = self::getOriginalValues('SettingsOptions');
         $original_variants = self::getOriginalValues('SettingsVariants');
         foreach ($section_options as $section_id => $options) {
             $_options = array();
             foreach ($options as $option) {
                 $_options[] = array('name' => $option['name'], 'value' => $option['description'], 'original_value' => isset($original_options['SettingsOptions' . \I18n_Pofile::DELIMITER . $addon_id . \I18n_Pofile::DELIMITER . $option['name']]) ? $original_options['SettingsOptions' . \I18n_Pofile::DELIMITER . $addon_id . \I18n_Pofile::DELIMITER . $option['name']]['msgid'] : '');
                 if (!empty($option['variants'])) {
                     $_variants = array();
                     foreach ($option['variants'] as $variant_id => $variant) {
                         $_variants[] = array('name' => $variant_id, 'value' => $variant, 'original_value' => isset($original_variants['SettingsVariants' . \I18n_Pofile::DELIMITER . $addon_id . \I18n_Pofile::DELIMITER . $option['name'] . \I18n_Pofile::DELIMITER . $variant_id]) ? $original_variants['SettingsVariants' . \I18n_Pofile::DELIMITER . $addon_id . \I18n_Pofile::DELIMITER . $option['name'] . \I18n_Pofile::DELIMITER . $variant_id]['msgid'] : '');
                     }
                     $_variants = Po::convert($_variants, array(), $allow_overlap);
                     $values = array_merge($values, Po::putValues('SettingsVariants' . \I18n_Pofile::DELIMITER . $addon_id . \I18n_Pofile::DELIMITER . $option['name'], $_variants, $pack_path));
                     unset($_variants);
                 }
                 if (!empty($option['tooltip'])) {
                     $_tooltips[] = array('name' => $option['name'], 'value' => $option['tooltip'], 'original_value' => isset($original_tooltips['SettingsTooltips' . \I18n_Pofile::DELIMITER . $addon_id . \I18n_Pofile::DELIMITER . $option['name']]) ? $original_tooltips['SettingsTooltips' . \I18n_Pofile::DELIMITER . $addon_id . \I18n_Pofile::DELIMITER . $option['name']]['msgid'] : '');
                 }
             }
             $_options = Po::convert($_options, array(), $allow_overlap);
             $values = array_merge($values, Po::putValues('SettingsOptions' . \I18n_Pofile::DELIMITER . $addon_id, $_options, $pack_path));
             unset($_options);
         }
     }
     $_tooltips = Po::convert($_tooltips, array(), $allow_overlap);
     $values = array_merge($values, Po::putValues('SettingsTooltips' . \I18n_Pofile::DELIMITER . $addon_id, $_tooltips, $pack_path));
     $values = fn_array_value_to_key($values, 'msgctxt');
     return $values;
 }
Пример #2
0
 private function getPoValues($lang_code, $section)
 {
     $addon_id = (string) $this->_xml->id;
     $result = array();
     $pack = $this->getPoPath($lang_code);
     $default_pack = $this->getPoPath($this->getDefaultLanguage());
     if ($default_pack != $pack && file_exists($default_pack)) {
         $result = $this->parsePoContent(Po::getValues($default_pack, $section));
     }
     if (file_exists($pack)) {
         $result = fn_array_merge($result, $this->parsePoContent(Po::getValues($pack, $section)));
     }
     return $result;
 }
Пример #3
0
 /**
  * Creates PO file for specified Language
  *
  * @param string $lang_code 2-letters language code (Example: "en", "ru")
  * @param string $output    Output destination
  *      screen - Output countent direct to browser page
  *      download - Force file downloading
  *      server - upload file to the config.dir.lang_packs directory
  * @param string $output_file Default name is $lang_code . '.po'
  */
 public static function createPoFile($lang_code, $output = 'download', $output_file = '')
 {
     // Translation packs should not include "Not translated" language data
     $allow_overlap = $lang_code == 'en' ? true : false;
     $filename = fn_create_temp_file();
     if (empty($output_file)) {
         $output_file = $lang_code . '.po';
     }
     $langs = self::get(array('lang_code' => $lang_code));
     $lang = $langs[$lang_code];
     Po::createHeader($filename, $lang);
     // Export Language values
     list($values) = LanguageValues::getVariables(array(), 0, $lang_code);
     $original_values = self::getOriginalValues('Languages');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['Languages::' . $value['name']]) ? $original_values['Languages::' . $value['name']]['msgid'] : '';
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('Languages', $values, $filename);
     // Export "SettingsVariants"
     $values = Settings::instance()->getVariants('', '', '', 'all', $lang_code);
     $original_values = self::getOriginalValues('SettingsVariants');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['SettingsVariants::' . $_id]) ? $original_values['SettingsVariants::' . $_id]['msgid'] : '';
     }
     $values = Po::convert($values, array('id' => '%key'), $allow_overlap);
     Po::putValues('SettingsVariants', $values, $filename);
     // Export Settings Sections
     $values = Settings::instance()->getCoreSections($lang_code);
     $original_values = self::getOriginalValues('SettingsSections');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['SettingsSections::' . $value['section_id']]) ? $original_values['SettingsSections::' . $value['section_id']]['msgid'] : '';
     }
     $values = Po::convert($values, array('id' => 'section_id', 'value' => 'description'), $allow_overlap);
     Po::putValues('SettingsSections', $values, $filename);
     // Export Settings Options
     $values = Settings::instance()->getList(0, 0, true, null, $lang_code);
     $original_values = self::getOriginalValues('SettingsOptions');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['SettingsOptions::' . $value['name']]) ? $original_values['SettingsOptions::' . $value['name']]['msgid'] : '';
     }
     $values = Po::convert($values, array('id' => 'name', 'value' => 'description'), $allow_overlap);
     Po::putValues('SettingsOptions', $values, $filename);
     // Export Addons data (name, description)
     list($addons) = fn_get_addons(array('type' => 'installed'), 0, $lang_code);
     $values = array();
     foreach ($addons as $addon_id => $addon) {
         $values[] = array('name' => $addon_id, 'value' => $addon['name'], 'original_value' => $addon['originals']['name']);
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('Addon', $values, $filename);
     $values = array();
     foreach ($addons as $addon_id => $addon) {
         $values[] = array('name' => $addon_id, 'value' => $addon['description'], 'original_value' => $addon['originals']['description']);
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('AddonDescription', $values, $filename);
     // Export Profile fields
     $profile_fields = fn_get_profile_fields('ALL', array(), $lang_code);
     $original_values = self::getOriginalValues('ProfileFields');
     $values = array();
     foreach ($profile_fields as $zone => $fields) {
         foreach ($fields as $field_id => $field) {
             $values[] = array('name' => $field['field_name'], 'value' => $field['description'], 'original_value' => isset($original_values['ProfileFields::' . $field['field_name']]) ? $original_values['ProfileFields::' . $field['field_name']]['msgid'] : '');
         }
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('ProfileFields', $values, $filename);
     switch ($output) {
         case 'screen':
             header("Content-type: text/plain");
             readfile($filename);
             exit;
             break;
         case 'server':
             fn_copy($filename, Registry::get('config.dir.lang_packs') . $output_file);
             break;
         case 'download':
             fn_get_file($filename, $output_file);
             break;
     }
 }