diff --git a/app/Tygh/Languages/Languages.php b/app/Tygh/Languages/Languages.php index 5b622a4..1370d48 100644 --- a/app/Tygh/Languages/Languages.php +++ b/app/Tygh/Languages/Languages.php @@ -516,7 +516,7 @@ class Languages if (!self::isValidMeta($lang_meta)) { // Failed to read meta data of new language - fn_set_notification('E', __('error'), __('po_file_is_incorrect', array('[file]' => fn_get_rel_dir($pack_path)))); + fn_set_notification('E', __('error'), __('check_po_file')); return false; } @@ -711,6 +711,7 @@ class Languages } } + if (!empty($original_values_query)) { self::executeLangQueries('original_values', array('msgctxt', 'msgid'), $original_values_query); } @@ -876,22 +877,21 @@ class Languages Po::createHeader($core_pack_path, $lang); + $addons_lang_vars = array(); + list($addons) = fn_get_addons(array('type' => 'installed'), 0, $lang_code); + foreach ($addons as $addon_id => $addon) { + $addons_lang_vars = array_merge($addons_lang_vars, self::exportAddonsPo($addon_id, $pack_path . 'addons/' . $addon_id . '.po', $lang_code)); + } + // Export Language values list($values) = LanguageValues::getVariables(array(), 0, $lang_code); + $original_values = self::getOriginalValues('Languages'); foreach ($values as $_id => $value) { $values[$_id]['msgctxt'] = 'Languages' . \I18n_Pofile::DELIMITER . $value['name']; } $values = fn_array_value_to_key($values, 'msgctxt'); - - $addons_lang_vars = array(); - list($addons) = fn_get_addons(array('type' => 'installed'), 0, $lang_code); - foreach ($addons as $addon_id => $addon) { - $addons_lang_vars = array_merge($addons_lang_vars, self::exportAddonsPo($addon_id, $pack_path . 'addons/' . $addon_id . '.po', $lang_code, $values)); - } - - $original_values = self::getOriginalValues('Languages'); $values = array_diff_key($values, $addons_lang_vars); foreach ($values as $_id => $value) { @@ -1050,13 +1050,12 @@ class Languages /** * 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 + * @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 * @return array Exported data */ - private static function exportAddonsPo($addon_id, $pack_path, $lang_code, $current_values = array()) + private static function exportAddonsPo($addon_id, $pack_path, $lang_code) { // Translation packs should not include "Not translated" language data $allow_overlap = $lang_code == 'en' ? true : false; @@ -1110,12 +1109,10 @@ class Languages 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'] : '', + 'value' => $variable['value'], + 'original_value' => isset($original_variables['Languages' . \I18n_Pofile::DELIMITER . $variable['name']]) ? $original_variables['Languages' . \I18n_Pofile::DELIMITER . $variable['name']]['msgid'] : '', ); } @@ -1222,28 +1219,15 @@ class Languages return true; } + /** - * This method installs language values stored at so-named "Crowdin-pack directory". - * The directory should have the following structure: - * - * / - * /core.po - Core language values. Required. - * /editions - Stores edition-specific *.po files. Optional. - * /mve.po - Multivendor-specific file. - * /addons - Stores add-ons' *.po files. Optional. - * /banners.po - * /bestsellers.po - * /{addon name}.po - * - * This methods collects relevant *.po files from given directory and executes {@see Tygh\Languages\Languages::installLanguagePack()} method for each one. - * "Relevant" means that only installed addons' po-files would be installed as well as mve.po will be installed only for Multivendor edition. - * - * @see Tygh\Languages\Languages::installLanguagePack() + * Installs PO-pack. * * @param string $path Path to directory that contains .po files (i.e. PO-pack directory) - * @param array $params Parameters passed to {@see Tygh\Languages\Languages::installLanguagePack()} function. + * @param array $params Parameters passed to {self::installLanguagePack()} function. * - * @return bool|int (bool) false on failure, (bool) true on success or (int) ID of newly created language (if it was created successfully). + * @return bool|int (bool) false on failure, (bool) true on success + * or (int) ID of newly created language (if it was created successfully). */ public static function installCrowdinPack($path, $params) { @@ -1254,7 +1238,7 @@ class Languages if (empty($lang_meta['lang_code'])) { $result = false; - fn_set_notification('E', __('error'), __('incorrect_po_pack_structure', array('[pack_path]' => fn_get_rel_dir($path)))); + fn_set_notification('E', __('error'), __('broken_po_pack')); } else { fn_copy($path, Registry::get('config.dir.lang_packs') . $lang_meta['lang_code'] . '/'); @@ -1291,7 +1275,7 @@ class Languages return $result; } else { - fn_set_notification('E', __('error'), __('incorrect_po_pack_structure', array('[pack_path]' => fn_get_rel_dir($path)))); + fn_set_notification('E', __('error'), __('broken_po_pack')); return false; }