/** * Gets meta information from the PO file * * @param string $base_path Root dir * @param string $pack_file PO file name (without .po extension) * @param bool $reinstall Use this flag, if pack was alread installed before to get META information * @return array List of lang pack meta information */ public static function getLangPacksMeta($base_path = '', $pack_file = '', $reinstall = false, $check_installed = true) { $installed_languages = $check_installed ? self::getAll(true) : array(); $path = empty($base_path) ? Registry::get('config.dir.lang_packs') : $base_path; $return = array(); if (empty($pack_file)) { $po_file_list = array(); foreach (fn_get_dir_contents($path, true, false) as $pack_directory) { if (is_dir($path . $pack_directory)) { $po_file_list[] = $pack_directory . '/core.po'; } } } else { $po_file_list = array($pack_file); } foreach ($po_file_list as $po_file_name) { $po_file_path = $path . $po_file_name; if (!file_exists($po_file_path)) { fn_set_notification('E', __('error'), __('incorrect_po_pack_structure', array('[pack_path]' => fn_get_rel_dir(dirname($po_file_path))))); continue; } $metadata = Po::getMeta($po_file_path); if (is_array($metadata)) { if (!self::isValidMeta($metadata)) { fn_set_notification('E', __('error'), __('po_file_is_incorrect', array('[file]' => fn_get_rel_dir($po_file_path)))); continue; } } else { fn_set_notification('E', __('error'), $metadata); continue; } if (isset($installed_languages[$metadata['lang_code']]) && !$reinstall) { continue; } $return[] = $metadata; } if (!empty($pack_file) && !empty($return)) { return reset($return); } return $return; }
/** * Gets meta information from the PO file * * @param string $base_path Root dir * @param string $pack_file PO file name (without .po extension) * @param bool $reinstall Use this flag, if pack was alread installed before to get META information * @return array List of lang pack meta information */ public static function getLangPacksMeta($base_path = '', $pack_file = '', $reinstall = false, $check_installed = true) { if ($check_installed) { $installed_languages = fn_get_translation_languages(true); } else { $installed_languages = array(); } $path = empty($base_path) ? Registry::get('config.dir.lang_packs') : $base_path; $langs = array(); if (!empty($pack_file)) { $langs_packs = array($pack_file); } else { $_packs = fn_get_dir_contents($path, true, false, '.po'); foreach ($_packs as $_pack) { $langs_packs[] = $_pack . '/core.po'; } } foreach ($langs_packs as $pack_name) { $pack_meta = Po::getMeta($path . $pack_name); if (!is_array($pack_meta)) { fn_set_notification('E', __('error'), $pack_meta); continue; } if (isset($installed_languages[$pack_meta['lang_code']]) && !$reinstall) { continue; } $langs[] = $pack_meta; } if (!empty($pack_file) && !empty($langs)) { return reset($langs); } return $langs; }