本文整理汇总了PHP中get_available_languages函数的典型用法代码示例。如果您正苦于以下问题:PHP get_available_languages函数的具体用法?PHP get_available_languages怎么用?PHP get_available_languages使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_available_languages函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pre_set_site_transient
/**
* Add language translations to update_plugins or update_themes transients.
*
* @param $transient
*
* @return mixed
*/
public function pre_set_site_transient($transient)
{
$locales = get_available_languages();
$locales = !empty($locales) ? $locales : array(get_locale());
$repos = array();
if (!isset($transient->translations)) {
return $transient;
}
if ('pre_set_site_transient_update_plugins' === current_filter()) {
$repos = Plugin::instance()->get_plugin_configs();
$translations = wp_get_installed_translations('plugins');
}
if ('pre_set_site_transient_update_themes' === current_filter()) {
$repos = Theme::instance()->get_theme_configs();
$translations = wp_get_installed_translations('themes');
}
$repos = array_filter($repos, function ($e) {
return isset($e->language_packs);
});
foreach ($repos as $repo) {
foreach ($locales as $locale) {
$lang_pack_mod = isset($repo->language_packs->{$locale}) ? strtotime($repo->language_packs->{$locale}->updated) : 0;
$translation_mod = isset($translations[$repo->repo][$locale]) ? strtotime($translations[$repo->repo][$locale]['PO-Revision-Date']) : 0;
if ($lang_pack_mod > $translation_mod) {
$transient->translations[] = (array) $repo->language_packs->{$locale};
}
}
}
$transient->translations = array_unique($transient->translations, SORT_REGULAR);
return $transient;
}
示例2: 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;
}
示例3: wp_user_profiles_language_metabox
/**
* Render the language metabox for user profile screen
*
* @since 0.1.0
*
* @param WP_User $user The WP_User object to be edited.
*/
function wp_user_profiles_language_metabox($user = null)
{
// Defaults
$languages = get_available_languages();
$user_locale = $user->locale;
$fallback = get_locale();
// Already en_US
if ('en_US' === $user->locale) {
$user_locale = false;
// Language not available
} elseif (!in_array($user->locale, $languages, true)) {
$user_locale = $fallback;
}
?>
<table class="form-table">
<tr class="user-language-wrap">
<th scope="row">
<label for="locale"><?php
esc_html_e('Language', 'wp-user-profiles');
?>
</label>
</th>
<td><?php
// Drop it down
wp_dropdown_languages(array('name' => 'locale', 'id' => 'locale', 'selected' => $user_locale, 'languages' => $languages, 'show_available_translations' => false));
?>
</td>
</tr>
</table>
<?php
}
示例4: mlang_languages
function mlang_languages()
{
$languages = get_available_languages();
if (!in_array('en', $languages)) {
array_unshift($languages, 'en');
}
return $languages;
}
示例5: getPicklistOptions
/**
*
* @return array;
*/
public function getPicklistOptions()
{
$languages = get_available_languages();
foreach ($languages as $language) {
$options[$language] = $language;
}
return $options;
}
示例6: test_get_available_languages
/**
* @ticket 35950
*/
function test_get_available_languages()
{
$array = get_available_languages();
$this->assertInternalType('array', $array);
$array = get_available_languages('.');
$this->assertEmpty($array);
$array = get_available_languages(DIR_TESTDATA . '/languages/');
$this->assertEquals(array('en_GB', 'es_ES'), $array);
}
示例7: markup
/**
* Returns the markup for the user setting.
*
* @since 3.0.0
*
* @param WP_User $user User object.
*
* @return string The markup for the user setting.
*/
public function markup(WP_User $user)
{
$languages = get_available_languages();
if (!$languages) {
return esc_html__('No languages available.', 'multilingual-press');
}
// Add English manually, because it won't get added by WordPress itself.
$languages[] = 'en_US';
return sprintf('<select name="%2$s" id="%2$s" autocomplete="off">%1$s</select>%3$s', $this->get_language_options($languages, $this->language_repository->get_user_language($user->ID)), esc_attr($this->meta_key), \Inpsyde\MultilingualPress\nonce_field($this->nonce));
}
示例8: languages_options
function languages_options()
{
// Initialization
global $locale;
$return = array(is_eng_array('Detect', 'language', ' - ') => 'Detect');
$languages = get_available_languages();
$languages_list = languages_list();
$languages_self_list = languages_self_list();
$is_en = substr($locale, 0, 2) == 'en';
foreach ($languages as $language) {
$return[] = array(isset($languages_self_list[$language]) ? $languages_self_list[$language] : $languages_list[$language] => array((isset($languages_list[$language]) ? $languages_list[$language] : $language) . ($is_en ? '' : ' - ' . $language) => $language));
}
if (!in_array('en', $languages) && !in_array('en_US', $languages) && !in_array('en_GB', $languages)) {
$return[] = array('English' => array(is_eng_array('English', 'language', ' - ') => 'en_US'));
}
return $return;
}
示例9: bogo_available_locales
function bogo_available_locales($args = '')
{
$defaults = array('exclude' => array(), 'current_user_can_access' => false);
$args = wp_parse_args($args, $defaults);
$installed_locales = get_available_languages();
$installed_locales[] = bogo_get_default_locale();
$installed_locales[] = 'en_US';
$installed_locales = array_unique($installed_locales);
$installed_locales = array_filter($installed_locales);
$available_locales = array();
foreach ($installed_locales as $locale) {
if (in_array($locale, (array) $args['exclude'])) {
continue;
}
if ($args['current_user_can_access'] && !current_user_can('bogo_access_locale', $locale)) {
continue;
}
$available_locales[] = $locale;
}
return $available_locales;
}
示例10: existing
public static function existing($all = false, $translate = false)
{
if (empty(self::$items)) {
$languages = array();
$langs = get_available_languages();
if (!in_array(get_locale(), $langs)) {
$langs[] = get_locale();
}
$i = 0;
foreach ($langs as $lang) {
$languages[$i] = new stdClass();
$languages[$i]->value = $lang;
$languages[$i]->text = $lang;
$i++;
}
self::$items = $languages;
if ($all) {
array_unshift(self::$items, new MObject(array('value' => '*', 'text' => $translate ? MText::alt('MALL', 'language') : 'MALL_LANGUAGE')));
}
}
return self::$items;
}
示例11: getLanguages
public static function getLanguages($key = 'default')
{
static $languages;
if (empty($languages)) {
// Installation uses available languages
if (MFactory::getApplication()->getClientId() == 2) {
$languages[$key] = array();
$knownLangs = MLanguage::getKnownLanguages(MPATH_BASE);
foreach ($knownLangs as $metadata) {
// Take off 3 letters iso code languages as they can't match browsers' languages and default them to en
$languages[$key][] = new MObject(array('lang_code' => $metadata['tag']));
}
} else {
$cache = MFactory::getCache('com_languages', '');
if (!($languages = $cache->get('languages'))) {
$langs = get_available_languages();
$i = 0;
$lngs = array();
foreach ($langs as $lang) {
$lngs[$i] = new stdClass();
$lngs[$i]->title = $lang;
$i++;
}
$languages['default'] = $lngs;
$languages['lang_code'] = array();
if (isset($languages['default'][0])) {
foreach ($languages['default'] as $lang) {
$languages['lang_code'][$lang->title] = $lang;
}
}
$cache->store($languages, 'languages');
}
}
}
return $languages[$key];
}
示例12: vp_register_hooks
function vp_register_hooks()
{
global $wpdb, $versionPressContainer;
/** @var Committer $committer */
$committer = $versionPressContainer->resolve(VersionPressServices::COMMITTER);
/** @var Mirror $mirror */
$mirror = $versionPressContainer->resolve(VersionPressServices::MIRROR);
/** @var DbSchemaInfo $dbSchemaInfo */
$dbSchemaInfo = $versionPressContainer->resolve(VersionPressServices::DB_SCHEMA);
/** @var VpidRepository $vpidRepository */
$vpidRepository = $versionPressContainer->resolve(VersionPressServices::VPID_REPOSITORY);
/** @var WpdbMirrorBridge $wpdbMirrorBridge */
$wpdbMirrorBridge = $versionPressContainer->resolve(VersionPressServices::WPDB_MIRROR_BRIDGE);
/**
* Hook for saving taxonomies into files
* WordPress creates plain INSERT query and executes it using wpdb::query method instead of wpdb::insert.
* It's too difficult to parse every INSERT query, that's why the WordPress hook is used.
*/
add_action('save_post', createUpdatePostTermsHook($mirror, $vpidRepository));
add_filter('update_feedback', function () {
touch(ABSPATH . 'versionpress.maintenance');
});
add_action('_core_updated_successfully', function () use($committer, $mirror) {
require ABSPATH . 'wp-includes/version.php';
// load constants (like $wp_version)
/** @var string $wp_version */
$changeInfo = new WordPressUpdateChangeInfo($wp_version);
$committer->forceChangeInfo($changeInfo);
$mirror->save('option', array('option_name' => 'db_version', 'option_value' => get_option('db_version')));
// We have to re-save the option because WP upgrader uses $wpdb->query()
if (!WpdbReplacer::isReplaced()) {
WpdbReplacer::replaceMethods();
}
});
add_action('activated_plugin', function ($pluginName) use($committer) {
$committer->forceChangeInfo(new PluginChangeInfo($pluginName, 'activate'));
});
add_action('deactivated_plugin', function ($pluginName) use($committer) {
$committer->forceChangeInfo(new PluginChangeInfo($pluginName, 'deactivate'));
});
add_action('upgrader_process_complete', function ($upgrader, $hook_extra) use($committer) {
if ($hook_extra['type'] === 'theme') {
$themes = isset($hook_extra['bulk']) && $hook_extra['bulk'] === true ? $hook_extra['themes'] : array($upgrader->result['destination_name']);
foreach ($themes as $theme) {
$themeName = wp_get_theme($theme)->get('Name');
if ($themeName === $theme && isset($upgrader->skin->api, $upgrader->skin->api->name)) {
$themeName = $upgrader->skin->api->name;
}
$action = $hook_extra['action'];
// can be "install" or "update", see WP_Upgrader and search for `'hook_extra' =>`
$committer->forceChangeInfo(new ThemeChangeInfo($theme, $action, $themeName));
}
}
if (!($hook_extra['type'] === 'plugin' && $hook_extra['action'] === 'update')) {
return;
}
// handled by different hook
if (isset($hook_extra['bulk']) && $hook_extra['bulk'] === true) {
$plugins = $hook_extra['plugins'];
} else {
$plugins = array($hook_extra['plugin']);
}
foreach ($plugins as $plugin) {
$committer->forceChangeInfo(new PluginChangeInfo($plugin, 'update'));
}
}, 10, 2);
add_action('added_option', function ($name) use($wpdb, $mirror) {
$option = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}options WHERE option_name='{$name}'", ARRAY_A);
$mirror->save("option", $option);
});
add_filter('upgrader_pre_install', function ($_, $hook_extra) use($committer) {
if (!(isset($hook_extra['type']) && $hook_extra['type'] === 'plugin' && $hook_extra['action'] === 'install')) {
return;
}
$pluginsBeforeInstallation = get_plugins();
$postInstallHook = function ($_, $hook_extra) use($pluginsBeforeInstallation, $committer, &$postInstallHook) {
if (!($hook_extra['type'] === 'plugin' && $hook_extra['action'] === 'install')) {
return;
}
wp_cache_delete('plugins', 'plugins');
$pluginsAfterInstallation = get_plugins();
$installedPlugin = array_diff_key($pluginsAfterInstallation, $pluginsBeforeInstallation);
reset($installedPlugin);
$pluginName = key($installedPlugin);
$committer->forceChangeInfo(new PluginChangeInfo($pluginName, 'install'));
remove_filter('upgrader_post_install', $postInstallHook);
};
add_filter('upgrader_post_install', $postInstallHook, 10, 2);
}, 10, 2);
add_filter('upgrader_pre_download', function ($reply, $_, $upgrader) use($committer) {
if (!isset($upgrader->skin->language_update)) {
return $reply;
}
$languages = get_available_languages();
$postInstallHook = function ($_, $hook_extra) use($committer, $languages, &$postInstallHook) {
if (!isset($hook_extra['language_update_type'])) {
return;
}
$translations = wp_get_available_translations();
$type = $hook_extra['language_update_type'];
//.........这里部分代码省略.........
示例13: change_language
/**
* change language : if language file not exist return false
* if language file not in THEME_LANGUAGE_PATH copy it from DEFAULT_LANG to THEME_LANGUAGE_PATH
* @since 1.0
*/
function change_language()
{
$lang = $_REQUEST['lang_name'];
if (!in_array($lang, $this->get_language_list())) {
wp_send_json(array('success' => false));
}
if (!in_array($lang, get_available_languages(THEME_LANGUAGE_PATH))) {
$mo = new MO();
$mo->set_header('Project-Id-Version', THEME_NAME . 'v' . ET_VERSION);
$mo->set_header('Report-Msgid-Bugs-To', ET_URL);
$mo->set_header('MO-Creation-Date', gmdate('Y-m-d H:i:s+00:00'));
$mo->set_header('MIME-Version', '1.0');
$mo->set_header('Content-Type', 'text/plain; charset=UTF-8');
$mo->set_header('Content-Transfer-Encoding', '8bit');
$mo->set_header('MO-Revision-Date', '2010-MO-DA HO:MI+ZONE');
$mo->set_header('Last-Translator', 'JOB <EMAIL@ADDRESS>');
$mo->set_header('Language-Team', 'ENGINETHEMES.COM <enginethemes@enginethemes.com>');
$mo->import_from_file(DEFAULT_LANGUAGE_PATH . '/' . $lang . '.mo');
$mo->export_to_file(THEME_LANGUAGE_PATH . '/' . $lang . '.mo');
}
$this->set_site_language($lang);
wp_send_json(array('success' => true, 'data' => array('ID' => $lang, 'lang_name' => $lang)));
}
示例14: translation_updates
public function translation_updates($locales)
{
$languages = get_available_languages();
return array_values($languages);
}
示例15: wp_update_themes
/**
* Check theme versions against the latest versions hosted on WordPress.org.
*
* A list of all themes installed in sent to WP. Checks against the
* WordPress server at api.wordpress.org. Will only check if WordPress isn't
* installing.
*
* @since 2.7.0
*
* @param array $extra_stats Extra statistics to report to the WordPress.org API.
*/
function wp_update_themes($extra_stats = array())
{
if (wp_installing()) {
return;
}
// include an unmodified $wp_version
include ABSPATH . WPINC . '/version.php';
$installed_themes = wp_get_themes();
$translations = wp_get_installed_translations('themes');
$last_update = get_site_transient('update_themes');
if (!is_object($last_update)) {
$last_update = new stdClass();
}
$themes = $checked = $request = array();
// Put slug of current theme into request.
$request['active'] = get_option('stylesheet');
foreach ($installed_themes as $theme) {
$checked[$theme->get_stylesheet()] = $theme->get('Version');
$themes[$theme->get_stylesheet()] = array('Name' => $theme->get('Name'), 'Title' => $theme->get('Name'), 'Version' => $theme->get('Version'), 'Author' => $theme->get('Author'), 'Author URI' => $theme->get('AuthorURI'), 'Template' => $theme->get_template(), 'Stylesheet' => $theme->get_stylesheet());
}
// Check for update on a different schedule, depending on the page.
switch (current_filter()) {
case 'upgrader_process_complete':
$timeout = 0;
break;
case 'load-update-core.php':
$timeout = MINUTE_IN_SECONDS;
break;
case 'load-themes.php':
case 'load-update.php':
$timeout = HOUR_IN_SECONDS;
break;
default:
if (defined('DOING_CRON') && DOING_CRON) {
$timeout = 0;
} else {
$timeout = 12 * HOUR_IN_SECONDS;
}
}
$time_not_changed = isset($last_update->last_checked) && $timeout > time() - $last_update->last_checked;
if ($time_not_changed && !$extra_stats) {
$theme_changed = false;
foreach ($checked as $slug => $v) {
if (!isset($last_update->checked[$slug]) || strval($last_update->checked[$slug]) !== strval($v)) {
$theme_changed = true;
}
}
if (isset($last_update->response) && is_array($last_update->response)) {
foreach ($last_update->response as $slug => $update_details) {
if (!isset($checked[$slug])) {
$theme_changed = true;
break;
}
}
}
// Bail if we've checked recently and if nothing has changed
if (!$theme_changed) {
return;
}
}
// Update last_checked for current to prevent multiple blocking requests if request hangs
$last_update->last_checked = time();
set_site_transient('update_themes', $last_update);
$request['themes'] = $themes;
$locales = array_values(get_available_languages());
/**
* Filter the locales requested for theme translations.
*
* @since 3.7.0
* @since 4.5.0 Changed default value of `$locales` to include all locales.
*
* @param array $locales Theme locales. Default is all available locales of the site.
*/
$locales = apply_filters('themes_update_check_locales', $locales);
$locales = array_unique($locales);
if (defined('DOING_CRON') && DOING_CRON) {
$timeout = 30;
} else {
// Three seconds, plus one extra second for every 10 themes
$timeout = 3 + (int) (count($themes) / 10);
}
$options = array('timeout' => $timeout, 'body' => array('themes' => wp_json_encode($request), 'translations' => wp_json_encode($translations), 'locale' => wp_json_encode($locales)), 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'));
if ($extra_stats) {
$options['body']['update_stats'] = wp_json_encode($extra_stats);
}
$url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/';
if ($ssl = wp_http_supports(array('ssl'))) {
$url = set_url_scheme($url, 'https');
}
//.........这里部分代码省略.........