当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_get_available_translations函数代码示例

本文整理汇总了PHP中wp_get_available_translations函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_available_translations函数的具体用法?PHP wp_get_available_translations怎么用?PHP wp_get_available_translations使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_get_available_translations函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getLanguageMutation

 protected function getLanguageMutation()
 {
     $i84676540daef1510ea5729a183290848a9e7accb = 0;
     $i05355412b857f5174e9a2f71b1e936a86ad60cd22621e8ed49bfcd8c8447959e1a834cd7df379456 = $i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900 = array();
     if (file_exists(ABSPATH . 'wp-admin/includes/translation-install.php')) {
         require_once ABSPATH . 'wp-admin/includes/translation-install.php';
         $i05355412b857f5174e9a2f71b1e936a86ad60cd22621e8ed49bfcd8c8447959e1a834cd7df379456 = get_available_languages();
         $i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900 = wp_get_available_translations();
     }
     if (isset($i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[SMS_DEFAULT_MUTATION]) && isset($i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[SMS_DEFAULT_MUTATION]["native_name"])) {
         $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89 = array(SMS_DEFAULT_MUTATION => $i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[SMS_DEFAULT_MUTATION]["native_name"], "en_US" => "English (United States)");
         $this->mutationColors[SMS_DEFAULT_MUTATION] = $i84676540daef1510ea5729a183290848a9e7accb++ % count(self::$colors);
         $this->mutationColors["en_US"] = $i84676540daef1510ea5729a183290848a9e7accb++ % count(self::$colors);
     } else {
         $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89 = array("en_US" => "English (United States)");
         $this->mutationColors["en_US"] = $i84676540daef1510ea5729a183290848a9e7accb++ % count(self::$colors);
     }
     foreach ($i05355412b857f5174e9a2f71b1e936a86ad60cd22621e8ed49bfcd8c8447959e1a834cd7df379456 as $i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772) {
         if ($i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772 != SMS_DEFAULT_MUTATION) {
             $this->mutationColors[$i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772] = $i84676540daef1510ea5729a183290848a9e7accb++ % count(self::$colors);
             if (isset($i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[$i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772]) && isset($i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[$i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772]["native_name"])) {
                 $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89[$i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772] = $i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[$i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772]["native_name"];
             }
         }
     }
     return $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89;
 }
开发者ID:etondeengole,项目名称:Store_Application,代码行数:27,代码来源:smsAdapter.php

示例2: activate

 /** 
  * @from 1.1
  */
 public function activate()
 {
     // initialization
     $options = get_option($this->option_name);
     $languages = $this->get_languages();
     if (empty($languages) && empty($options)) {
         require_once ABSPATH . 'wp-admin/includes/translation-install.php';
         $translations = wp_get_available_translations();
         $locale = get_locale();
         $language_name = isset($translations[$locale]['native_name']) ? $translations[$locale]['native_name'] : 'English';
         $language_slug = isset($translations[$locale]['iso']) && !empty($translations[$locale]['iso']) ? array_shift($translations[$locale]['iso']) : 'en';
         $post_id = wp_insert_post(array('post_type' => $this->language_post_type, 'post_title' => $language_name, 'post_name' => $language_slug, 'post_status' => 'publish'));
         $options = array();
         $options['main'] = $post_id;
         $options['default'] = $post_id;
         $options['show_slug'] = false;
         $options['autodetect'] = false;
         $options['current_first'] = false;
         $options['taxonomy'] = array('category');
         $options['cpt'] = array('post', 'page');
         $options['version'] = '1.2';
         update_option($this->option_name, $options);
     }
     $admins = get_role('administrator');
     $admins->add_cap('edit_language');
     $admins->add_cap('edit_languages');
     $admins->add_cap('edit_other_languages');
     $admins->add_cap('publish_languages');
     $admins->add_cap('read_language');
     $admins->add_cap('read_private_languages');
     $admins->add_cap('delete_language');
 }
开发者ID:Blueprint-Marketing,项目名称:sublanguage,代码行数:35,代码来源:admin.php

示例3: init

 /**
  * Constructor.
  */
 public function init()
 {
     $this->load_textdomain(self::NAME);
     $this->title(__('Localization', 'debug-bar-localization'));
     add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
     add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
     if (!function_exists('wp_get_available_translations')) {
         require_once ABSPATH . 'wp-admin/includes/translation-install.php';
     }
     $this->wp_translations = wp_get_available_translations();
     $this->load_call_types = array('core' => __('WP Core', 'debug-bar-localization'), 'theme' => __('Themes', 'debug-bar-localization'), 'muplugin' => __('Must-Use Plugins', 'debug-bar-localization'), 'plugin' => __('Plugins', 'debug-bar-localization'), 'unknown' => __('Unknown', 'debug-bar-localization'));
 }
开发者ID:jrfnl,项目名称:debug-bar-localization,代码行数:15,代码来源:class-debug-bar-localization.php

示例4: language_detector_admin_notices

 public static function language_detector_admin_notices()
 {
     // Check if the nag screen has been disabled for this language
     if (self::has_language_detector_dismissed()) {
         return;
     }
     // Get the current language locale
     $language = get_locale();
     require_once ABSPATH . 'wp-admin/includes/translation-install.php';
     $translations = wp_get_available_translations();
     printf('<div id="si_language_detect_nag_dismiss" class="notice notice-info is-dismissible"><p>%s</p></div>', sprintf(__('<span class="dashicons dashicons-megaphone"></span> <b>%1$s</b> does not have a translation for <b>%2$s</b>, please help the community translate at <a href="%3$s" target="_blank">%3$s</a>. Supporting translators receive major discounts on <a href="%4$s" target="_blank">pro licenses</a> and <a href="%5$s" target="_blank">add-ons</a>.', 'sprout-invoices'), esc_html(self::PLUGIN_NAME), esc_html($translations[$language]['native_name']), esc_url('https://translate.wordpress.org/projects/wp-plugins/sprout-invoices/'), si_get_sa_link('https://sproutapps.co/sprout-invoices/purchase/', 'translation'), si_get_sa_link('https://sproutapps.co/marketplace/', 'translation')));
 }
开发者ID:danielbachhuber,项目名称:marcgratch.com,代码行数:12,代码来源:SI_l10n.php

示例5: bogo_get_language_native_name

function bogo_get_language_native_name($locale)
{
    if ('en_US' == $locale) {
        return 'English (United States)';
    }
    if (!function_exists('wp_get_available_translations')) {
        require_once ABSPATH . 'wp-admin/includes/translation-install.php';
    }
    static $available_translations = array();
    if (empty($available_translations)) {
        $available_translations = wp_get_available_translations();
    }
    if (isset($available_translations[$locale]['native_name'])) {
        return $available_translations[$locale]['native_name'];
    }
    return false;
}
开发者ID:karthikakamalanathan,项目名称:wp-cookieLawInfo,代码行数:17,代码来源:functions.php

示例6: load

 public function load($lang = null)
 {
     if (null !== $lang) {
         require_once ABSPATH . 'wp-admin/includes/translation-install.php';
         global $locale;
         if (!in_array($lang, get_available_languages())) {
             if (array_key_exists($lang, wp_get_available_translations())) {
                 $language = wp_download_language_pack($lang);
                 if ($language) {
                     load_default_textdomain($language);
                     $locale = $language;
                 }
             }
         } else {
             load_default_textdomain($lang);
             $locale = $lang;
         }
     }
     $this->init();
     $this->register_globals();
 }
开发者ID:pbearne,项目名称:contrib2core,代码行数:21,代码来源:class-wp-locale-switcher.php

示例7: flagatar_admin_bar

 public function flagatar_admin_bar()
 {
     global $wp_admin_bar, $blog_id;
     // This is functionality for WP 4.0+ only
     if (version_compare(get_bloginfo('version'), '4.0', '>=')) {
         // Get native language names
         if (file_exists(ABSPATH . 'wp-admin/includes/translation-install.php')) {
             require_once ABSPATH . 'wp-admin/includes/translation-install.php';
         }
         $translations = function_exists('wp_get_available_translations') ? wp_get_available_translations() : array();
     } else {
         $translations = array();
     }
     // Loop user's blogs trough
     foreach ((array) $wp_admin_bar->user->blogs as $blog) {
         $node_id = 'blog-' . $blog->userblog_id;
         $node = $wp_admin_bar->get_node($node_id);
         if ($node) {
             // We'll put it back...
             $wp_admin_bar->remove_node($node_id);
             // Get language
             $lang = is_multisite() ? get_blog_option($blog->userblog_id, 'WPLANG', 'en_US') : get_bloginfo('language');
             // Oh, just sometimes language returns empty on WP 4.0, try different key
             if (empty($lang) && is_multisite()) {
                 $lang = get_blog_option($blog->userblog_id, 'language', 'en_US');
             }
             // Still no language? Default to US.
             if (empty($lang)) {
                 $lang = 'en_US';
             }
             // Blog name - and is this blog currently active?
             $blogname = $blog_id == $blog->userblog_id ? '<strong class="current">' . $blog->blogname . '</strong>' : $blog->blogname;
             // Update node and put it back
             $node->title = '<div class="blavatar flagatar" style="background-image:url(' . plugins_url('flags/' . strtoupper(substr($lang, -2)) . '.png', __FILE__) . ')"></div> ' . $blogname;
             // If we have name for this language, show it as title. Fall back to locale.
             $node->meta['title'] = isset($translations[$lang]) ? esc_attr($translations[$lang]['english_name'] . ' (' . $translations[$lang]['native_name'] . ')') : esc_attr($lang);
             $wp_admin_bar->add_node($node);
         }
     }
 }
开发者ID:simison,项目名称:WP-admin-bar-languages,代码行数:40,代码来源:admin-bar-languages.php

示例8: _vp_get_language_name_by_code

 function _vp_get_language_name_by_code($code)
 {
     require_once ABSPATH . 'wp-admin/includes/translation-install.php';
     $translations = wp_get_available_translations();
     return isset($translations[$code]) ? $translations[$code]['native_name'] : 'English (United States)';
 }
开发者ID:versionpress,项目名称:versionpress,代码行数:6,代码来源:setup-hooks.php

示例9: _vp_get_language_name_by_code

 function _vp_get_language_name_by_code($code)
 {
     $translations = wp_get_available_translations();
     return isset($translations[$code]) ? $translations[$code]['native_name'] : 'English (United States)';
 }
开发者ID:wp-cpm,项目名称:versionpress,代码行数:5,代码来源:versionpress.php

示例10: hw_dropdown_languages

 /**
  * display list of language in dropdown
  * @param array $args
  */
 public static function hw_dropdown_languages($args = array())
 {
     $avaibles_languages = self::get_available_languages();
     //avaiable languages
     $args = wp_parse_args($args, array('id' => '', 'name' => '', 'languages' => array(), 'translations' => array(), 'selected' => '', 'show_available_translations' => true));
     $translations = $args['translations'];
     if (empty($translations)) {
         require_once ABSPATH . 'wp-admin/includes/translation-install.php';
         $translations = wp_get_available_translations();
     }
     if (empty($args['languages'])) {
         $args['languages'] = self::hw_get_available_languages();
     }
     /*
      * $args['languages'] should only contain the locales. Find the locale in
      * $translations to get the native name. Fall back to locale.
      */
     $languages = array();
     foreach ($args['languages'] as $locale) {
         //check lang for avaiable
         if (in_array($locale, $avaibles_languages)) {
             continue;
         }
         //exists installed this language
         $found_uninstalled = true;
         if (isset($translations[$locale])) {
             $translation = $translations[$locale];
             $languages[] = array('language' => $translation['language'], 'native_name' => $translation['native_name'], 'lang' => $translation['iso'][1]);
             // Remove installed language from available translations.
             unset($translations[$locale]);
         } else {
             $languages[] = array('language' => $locale, 'native_name' => $locale, 'lang' => '');
         }
     }
     if (!isset($found_uninstalled)) {
         return false;
     }
     //no avaible uninstalled languages in wp system
     printf('<select name="%s" id="%s" multiple style="max-height:200px;width:200px">', esc_attr($args['name']), esc_attr($args['id']));
     // Holds the HTML markup.
     $structure = array();
     foreach ($languages as $language) {
         $structure[] = sprintf('<option value="%s" lang="%s"%s data-installed="1">%s</option>', esc_attr($language['language']), esc_attr($language['lang']), selected($language['language'], $args['selected'], false), esc_html($language['native_name']));
     }
     echo join("\n", $structure);
     echo '</select>';
     return true;
 }
开发者ID:hoangsoft90,项目名称:hw-hoangweb-plugin,代码行数:52,代码来源:class.wp.languages.php

示例11: qtranxf_updateGettextDatabasesEx

/**
 * 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 = '')
{
    if (empty($only_for_language)) {
        if (!$force) {
            $next_update = get_option('qtranslate_next_update_mo');
            if (time() < $next_update) {
                return true;
            }
        }
        update_option('qtranslate_next_update_mo', time() + 7 * 24 * 60 * 60);
    }
    if (!is_dir(WP_LANG_DIR)) {
        if (!@mkdir(WP_LANG_DIR)) {
            return false;
        }
    }
    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_warning(__('Gettext databases <strong>not</strong> updated:', 'qtranslate') . ' ' . $result->get_error_message());
    //	return false;
    //}
    //$translations = $result['translations'];
    $translations = wp_get_available_translations();
    if (empty($translations)) {
        qtranxf_add_warning(__('Gettext databases <strong>not</strong> updated:', 'qtranslate') . ' ' . __('Failed to fetch the list of available translations.', 'qtranslate'));
        return false;
    }
    set_time_limit(300);
    if (empty($only_for_language)) {
        global $q_config;
        $langs = $q_config['enabled_languages'];
        $locales = $q_config['locale'];
    } else {
        $langs = array($only_for_language);
        $locales = qtranxf_language_configured('locale');
    }
    $errcnt = 0;
    /*
    	//qtranxf_dbg_log('qtranxf_updateGettextDatabasesEx: count($translations): ',count($translations));
    	//qtranxf_dbg_log('qtranxf_updateGettextDatabasesEx: $translations: ',$translations);
    	foreach ( $translations as $loc => $translation ) {
    		$locale = $translation['language'];
    		$lang = null;
    		foreach($langs as $lng) {
    			if(!isset($locales[$lng])){
    				$locales = qtranxf_language_configured('locale');
    				if(!isset($locales[$lng])) continue;
    			}
    			if($locales[$lng] != $locale) continue;
    			$lang = $lng;
    			break;
    		}
    		if(!$lang) continue;
    */
    foreach ($langs as $lang) {
        $loc = $locales[$lang];
        if (!isset($translations[$loc])) {
            continue;
        }
        $mo = WP_LANG_DIR . '/' . $loc . '.mo';
        $mo_ok = file_exists($mo);
        //qtranxf_dbg_log('qtranxf_updateGettextDatabasesEx: $mo_ok for '.$mo.': ',$mo_ok);
        if ($mo_ok) {
            continue;
        }
        //WP now takes care of translations updates on its own
        $translation = (object) $translations[$loc];
        $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_warning(sprintf(__('Failed to update gettext database for "%s": %s', 'qtranslate'), $lang, $result->get_error_message()));
            ++$errcnt;
        }
    }
    return $errcnt;
}
开发者ID:dmitriyvi,项目名称:qtranslate-x,代码行数:88,代码来源:qtx_update_gettext_db.php

示例12: qtranxf_default_enabled_languages

/**
 * since 3.2.9.2
 */
function qtranxf_default_enabled_languages()
{
    //$languages = get_available_languages();
    //qtranxf_dbg_log('qtranxf_default_enabled_languages: count(languages): ',count($languages));
    //qtranxf_dbg_log('qtranxf_default_enabled_languages: get_available_languages: ',$languages);
    $locale = get_locale();
    if (!$locale) {
        $locale = 'en_US';
    }
    $lang = null;
    $locales = qtranxf_default_locale();
    foreach ($locales as $ln => $lo) {
        if ($lo != $locale) {
            continue;
        }
        $lang = $ln;
        break;
    }
    if (!$lang) {
        require_once ABSPATH . 'wp-admin/includes/translation-install.php';
        $translations = wp_get_available_translations();
        //qtranxf_dbg_log('qtranxf_default_enabled_languages: count(available_translations): ',count($translations));
        //qtranxf_dbg_log('qtranxf_default_enabled_languages: wp_get_available_translations: ',$translations);
        if (empty($translations[$locale])) {
            $lang = substr($locale, 0, 2);
            $name = 'Unknown';
        } else {
            $translation = $translations[$locale];
            $lang = current($translation['iso']);
            if (!$lang) {
                $lang = substr($locale, 0, 2);
            }
            $name = empty($translation['native_name']) ? 'Unknown' : $translation['native_name'];
        }
        $flag_location = WP_CONTENT_DIR . '/' . qtranxf_flag_location_default();
        do {
            $p = strpos($locale, '_');
            if ($p > 0) {
                $fn = strtolower(substr($locale, $p, 2));
                $flag = $fn . '.png';
                if (file_exists($flag_location . $flag)) {
                    break;
                }
                $flag = $fn . '.gpg';
                if (file_exists($flag_location . $flag)) {
                    break;
                }
            }
            $fn = strtolower(substr($locale, 0, 2));
            $flag = $fn . '.png';
            if (file_exists($flag_location . $flag)) {
                break;
            }
            $flag = $fn . '.gpg';
            if (file_exists($flag_location . $flag)) {
                break;
            }
            $flag = 'aa.png';
        } while (false);
        $props = array('language_name' => $name, 'flag' => $flag, 'locale' => $locale, 'date_format' => __('F j, Y'), 'time_format' => __('g:i a'), 'not_available' => 'Sorry, this entry is only available in %LANG:, : and %.');
        qtranxf_set_default_options($qtranslate_options);
        qtranxf_save_languages(array($lang => $props), $qtranslate_options);
        //qtranxf_dbg_log('qtranxf_default_enabled_languages: $props: ',$props);
    }
    $enabled_languages = array($lang);
    if ($lang != 'en') {
        $enabled_languages[] = 'en';
    }
    //qtranxf_dbg_log('qtranxf_default_enabled_languages: $lang="'.$lang.'"; $locale="'.$locale.'"; $enabled_languages: ',$enabled_languages);
    return $enabled_languages;
}
开发者ID:razik440,项目名称:qtranslate-x,代码行数:74,代码来源:qtx_activation_hook.php

示例13: wp_download_language_pack

/**
 * Download a language pack.
 *
 * @since 4.0.0
 *
 * @see wp_get_available_translations()
 *
 * @param string $download Language code to download.
 * @return string|bool Returns the language code if successfully downloaded
 *                     (or already installed), or false on failure.
 */
function wp_download_language_pack($download)
{
    // Check if the translation is already installed.
    if (in_array($download, get_available_languages())) {
        return $download;
    }
    if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
        return false;
    }
    // Confirm the translation is one we can download.
    $translations = wp_get_available_translations();
    if (!$translations) {
        return false;
    }
    foreach ($translations as $translation) {
        if ($translation['language'] === $download) {
            $translation_to_load = true;
            break;
        }
    }
    if (empty($translation_to_load)) {
        return false;
    }
    $translation = (object) $translation;
    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $skin = new Automatic_Upgrader_Skin();
    $upgrader = new Language_Pack_Upgrader($skin);
    $translation->type = 'core';
    $result = $upgrader->upgrade($translation, array('clear_update_cache' => false));
    if (!$result || is_wp_error($result)) {
        return false;
    }
    return $translation->language;
}
开发者ID:johnpbloch,项目名称:wordpress,代码行数:45,代码来源:translation-install.php

示例14: wp_dropdown_languages

/**
 * Language selector.
 *
 * @since 4.0.0
 * @since 4.3.0 Introduced the `echo` argument.
 *
 * @see get_available_languages()
 * @see wp_get_available_translations()
 *
 * @param string|array $args {
 *     Optional. Array or string of arguments for outputting the language selector.
 *
 *     @type string   $id                           ID attribute of the select element. Default empty.
 *     @type string   $name                         Name attribute of the select element. Default empty.
 *     @type array    $languages                    List of installed languages, contain only the locales.
 *                                                  Default empty array.
 *     @type array    $translations                 List of available translations. Default result of
 *                                                  wp_get_available_translations().
 *     @type string   $selected                     Language which should be selected. Default empty.
 *     @type bool|int $echo                         Whether to echo or return the generated markup. Accepts 0, 1, or their
 *                                                  bool equivalents. Default 1.
 *     @type bool     $show_available_translations  Whether to show available translations. Default true.
 * }
 * @return string HTML content only if 'echo' argument is 0.
 */
function wp_dropdown_languages($args = array())
{
    $args = wp_parse_args($args, array('id' => '', 'name' => '', 'languages' => array(), 'translations' => array(), 'selected' => '', 'echo' => 1, 'show_available_translations' => true));
    $translations = $args['translations'];
    if (empty($translations)) {
        require_once ABSPATH . 'wp-admin/includes/translation-install.php';
        $translations = wp_get_available_translations();
    }
    /*
     * $args['languages'] should only contain the locales. Find the locale in
     * $translations to get the native name. Fall back to locale.
     */
    $languages = array();
    foreach ($args['languages'] as $locale) {
        if (isset($translations[$locale])) {
            $translation = $translations[$locale];
            $languages[] = array('language' => $translation['language'], 'native_name' => $translation['native_name'], 'lang' => current($translation['iso']));
            // Remove installed language from available translations.
            unset($translations[$locale]);
        } else {
            $languages[] = array('language' => $locale, 'native_name' => $locale, 'lang' => '');
        }
    }
    $translations_available = !empty($translations) && $args['show_available_translations'];
    $output = sprintf('<select name="%s" id="%s">', esc_attr($args['name']), esc_attr($args['id']));
    // Holds the HTML markup.
    $structure = array();
    // List installed languages.
    if ($translations_available) {
        $structure[] = '<optgroup label="' . esc_attr_x('Installed', 'translations') . '">';
    }
    $structure[] = '<option value="" lang="en" data-installed="1">English (United States)</option>';
    foreach ($languages as $language) {
        $structure[] = sprintf('<option value="%s" lang="%s"%s data-installed="1">%s</option>', esc_attr($language['language']), esc_attr($language['lang']), selected($language['language'], $args['selected'], false), esc_html($language['native_name']));
    }
    if ($translations_available) {
        $structure[] = '</optgroup>';
    }
    // List available translations.
    if ($translations_available) {
        $structure[] = '<optgroup label="' . esc_attr_x('Available', 'translations') . '">';
        foreach ($translations as $translation) {
            $structure[] = sprintf('<option value="%s" lang="%s"%s>%s</option>', esc_attr($translation['language']), esc_attr(current($translation['iso'])), selected($translation['language'], $args['selected'], false), esc_html($translation['native_name']));
        }
        $structure[] = '</optgroup>';
    }
    $output .= join("\n", $structure);
    $output .= '</select>';
    if ($args['echo']) {
        echo $output;
    }
    return $output;
}
开发者ID:s4mobile,项目名称:WordPressTech,代码行数:78,代码来源:l10n.php

示例15: edd_lp_language_dropdown

/**
 * Renders an HTML Dropdown of all the available languages
 *
 * @param  array  $args   Arguments for the dropdown
 *
 * @return string $output Languages dropdown
 *
 * @since 0.1.0
 */
function edd_lp_language_dropdown($args = array())
{
    $defaults = array('name' => 'languages', 'id' => 'languages', 'class' => '', 'multiple' => false, 'selected' => 0, 'chosen' => false, 'placeholder' => __('Select a language', 'edd-language-packs'));
    $args = wp_parse_args($args, $defaults);
    require_once ABSPATH . 'wp-admin/includes/translation-install.php';
    $translations = wp_get_available_translations();
    $options = array();
    if ($translations) {
        $options[0] = __('Select a language', 'edd-language-packs');
        foreach ($translations as $translation) {
            $options[$translation['language']] = esc_html($translation['english_name']);
        }
    } else {
        $options[0] = __('No languages found', 'edd-language-packs');
    }
    // This ensures that any selected products are included in the drop down
    if (is_array($args['selected'])) {
        foreach ($args['selected'] as $language => $english_name) {
            if (!in_array($language, $options)) {
                $options[$language] = $english_name;
            }
        }
    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
        if (!in_array($args['selected'], $options)) {
            $options[key($args['selected'])] = $args['selected'];
        }
    }
    $output = EDD()->html->select(array('name' => $args['name'], 'selected' => $args['selected'], 'id' => $args['id'], 'class' => $args['class'], 'options' => $options, 'chosen' => $args['chosen'], 'multiple' => $args['multiple'], 'placeholder' => $args['placeholder'], 'show_option_all' => false, 'show_option_none' => false));
    return $output;
}
开发者ID:fxbenard,项目名称:edd-language-packs,代码行数:39,代码来源:metabox.php


注:本文中的wp_get_available_translations函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。