/**
 * return 'true', if no update needed,
 * or 'false', if update is impossible to do,
 * or 0, if all languages were updated successfully,
 * or positive integer number of errors occurred on languages update.
 */
function qtranxf_updateGettextDatabasesEx($force = false, $only_for_language = '')
{
    global $q_config;
    if ($only_for_language && !qtranxf_isEnabled($only_for_language)) {
        return false;
    }
    if (!is_dir(WP_LANG_DIR)) {
        if (!@mkdir(WP_LANG_DIR)) {
            return false;
        }
    }
    $next_update = get_option('qtranslate_next_update_mo');
    if (time() < $next_update && !$force) {
        return true;
    }
    update_option('qtranslate_next_update_mo', time() + 7 * 24 * 60 * 60);
    require_once ABSPATH . 'wp-admin/includes/translation-install.php';
    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    require_once ABSPATH . 'wp-admin/includes/file.php';
    include ABSPATH . WPINC . '/version.php';
    // include an unmodified $wp_version
    $result = translations_api('core', array('version' => $wp_version));
    if (is_wp_error($result)) {
        qtranxf_add_error(__('Gettext databases <strong>not</strong> updated:', 'qtranslate') . ' ' . $result->get_error_message());
        return false;
    }
    set_time_limit(300);
    $langs = empty($only_for_language) ? $q_config['enabled_languages'] : array($only_for_language);
    $errcnt = 0;
    foreach ($result['translations'] as $translation) {
        $locale = $translation['language'];
        $lang = null;
        foreach ($langs as $lng) {
            if ($q_config['locale'][$lng] != $locale) {
                continue;
            }
            $lang = $lng;
            break;
        }
        if (!$lang) {
            continue;
        }
        $translation = (object) $translation;
        $skin = new Automatic_Upgrader_Skin();
        $upgrader = new Language_Pack_Upgrader($skin);
        $translation->type = 'core';
        $result = $upgrader->upgrade($translation, array('clear_update_cache' => false));
        if (is_wp_error($result)) {
            qtranxf_add_error(sprintf(__('Failed to update gettext database for "%s": %s', 'qtranslate'), $q_config['language_name'][$lang], $result->get_error_message()));
            ++$errcnt;
        }
    }
    return $errcnt;
}
 /**
  * List all languages available.
  *
  * [--fields=<fields>]
  * : Limit the output to specific fields.
  *
  * [--format=<format>]
  * : Accepted values: table, csv, json. Default: table
  *
  * ## AVAILABLE FIELDS
  *
  * These fields will be displayed by default for each translation:
  *
  * * language
  * * english_name
  * * native_name
  * * status
  * * updated
  *
  * These fields are optionally available:
  *
  * * version
  * * package
  *
  * @subcommand list
  */
 public function list_($args, $assoc_args)
 {
     require_once ABSPATH . '/wp-admin/includes/translation-install.php';
     $response = translations_api($this->obj_type);
     $translations = !empty($response['translations']) ? $response['translations'] : array();
     $available = wp_get_installed_translations($this->obj_type);
     $available = !empty($available['default']) ? array_keys($available['default']) : array();
     $current_locale = get_locale();
     $translations = array_map(function ($translation) use($available, $current_locale) {
         $translation['status'] = in_array($translation['language'], $available) ? 'installed' : 'uninstalled';
         if ($current_locale == $translation['language']) {
             $translation['status'] = 'active';
         }
         return $translation;
     }, $translations);
     $formatter = $this->get_formatter($assoc_args);
     $formatter->display_items($translations);
 }
Beispiel #3
0
function wpcf7_l10n()
{
    static $l10n = array();
    if (!empty($l10n)) {
        return $l10n;
    }
    if (!is_admin()) {
        return $l10n;
    }
    require_once ABSPATH . 'wp-admin/includes/translation-install.php';
    $api = translations_api('plugins', array('slug' => 'contact-form-7', 'version' => WPCF7_VERSION));
    if (is_wp_error($api) || empty($api['translations'])) {
        return $l10n;
    }
    foreach ((array) $api['translations'] as $translation) {
        if (!empty($translation['language']) && !empty($translation['english_name'])) {
            $l10n[$translation['language']] = $translation['english_name'];
        }
    }
    return $l10n;
}
function qtranxf_updateGettextDatabasesEx($force = false, $only_for_language = '')
{
    global $q_config;
    if ($only_for_language && !qtranxf_isEnabled($only_for_language)) {
        return false;
    }
    if (!is_dir(WP_LANG_DIR)) {
        if (!@mkdir(WP_LANG_DIR)) {
            return false;
        }
    }
    $next_update = get_option('qtranslate_next_update_mo');
    if (time() < $next_update && !$force) {
        return true;
    }
    update_option('qtranslate_next_update_mo', time() + 7 * 24 * 60 * 60);
    require_once ABSPATH . 'wp-admin/includes/translation-install.php';
    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    require_once ABSPATH . 'wp-admin/includes/file.php';
    include ABSPATH . WPINC . '/version.php';
    // include an unmodified $wp_version
    $result = translations_api('core', array('version' => $wp_version));
    if (is_wp_error($result)) {
        return $result;
    } else {
        foreach ($result['translations'] as $translation) {
            $locale = substr($translation['language'], 0, 2);
            if (isset($q_config['locale'][$locale]) && $q_config['locale'][$locale] == $translation['language'] && qtranxf_isEnabled($locale)) {
                $translation = (object) $translation;
                $skin = new Automatic_Upgrader_Skin();
                $upgrader = new Language_Pack_Upgrader($skin);
                $translation->type = 'core';
                $result = $upgrader->upgrade($translation, array('clear_update_cache' => false));
            }
        }
        return true;
    }
}
/**
 * Get available translations from the WordPress.org API.
 *
 * @since 4.0.0
 *
 * @see translations_api()
 *
 * @return array Array of translations, each an array of data. If the API response results
 *               in an error, an empty array will be returned.
 */
function wp_get_available_translations()
{
    if (!wp_installing() && false !== ($translations = get_site_transient('available_translations'))) {
        return $translations;
    }
    include ABSPATH . WPINC . '/version.php';
    // include an unmodified $wp_version
    $api = translations_api('core', array('version' => $wp_version));
    if (is_wp_error($api) || empty($api['translations'])) {
        return array();
    }
    $translations = array();
    // Key the array with the language code for now.
    foreach ($api['translations'] as $translation) {
        $translations[$translation['language']] = $translation;
    }
    if (!defined('WP_INSTALLING')) {
        set_site_transient('available_translations', $translations, 3 * HOUR_IN_SECONDS);
    }
    return $translations;
}
 /**
  * Return a list of all languages
  *
  * @return array
  */
 protected function get_all_languages()
 {
     require_once ABSPATH . '/wp-admin/includes/translation-install.php';
     $response = translations_api($this->obj_type);
     $translations = !empty($response['translations']) ? $response['translations'] : array();
     $en_us = array('language' => 'en_US', 'english_name' => 'English (United States)', 'native_name' => 'English (United States)', 'updated' => '');
     array_push($translations, $en_us);
     uasort($translations, array($this, 'sort_translations_callback'));
     return $translations;
 }