本文整理汇总了PHP中wp_download_language_pack函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_download_language_pack函数的具体用法?PHP wp_download_language_pack怎么用?PHP wp_download_language_pack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_download_language_pack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: install_languages
protected function install_languages()
{
if (file_exists($file = ABSPATH . 'wp-admin/includes/translation-install.php')) {
require_once $file;
}
if (!function_exists('wp_download_language_pack')) {
$this->markTestSkipped('The wp_download_language_pack() function does not exist.');
return;
}
$languages = array('fr' => 'fr_FR', 'uk' => 'en_GB', 'ar' => 'ar');
foreach ($languages as $url_prefix => $lang) {
$download = wp_download_language_pack($lang);
$this->assertNotEmpty($download);
$this->langs[$lang] = $download;
}
$active_langs = array_merge(array('en' => 'en_US'), $languages);
$public_langs = array_values($active_langs);
$lang_prefs = array();
$langs = array();
$lang_prefs['en'] = (object) array('display_name' => 'en_US', 'url_prefix' => 'en');
$langs['en_US'] = (object) array('name' => 'en_US', 'code' => 'en_US', 'url_prefix' => 'en', 'text_direction' => 'ltr', 'display_name' => 'en_US');
foreach ($languages as $url_prefix => $lang) {
$lang_prefs[$url_prefix] = (object) array('display_name' => $lang, 'url_prefix' => $url_prefix);
$langs[$lang] = (object) array('name' => $lang, 'code' => $lang, 'url_prefix' => $url_prefix, 'text_direction' => 'ltr', 'display_name' => $lang);
}
$default_lang = 'en_US';
$option = get_option('babble-languages', array());
$option['langs'] = $langs;
$option['active_langs'] = $active_langs;
$option['public_langs'] = $public_langs;
$option['lang_prefs'] = $lang_prefs;
$option['default_lang'] = $default_lang;
update_option('babble-languages', $option);
Babble::get('languages')->initiate();
}
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:35,代码来源:babble-testcase.php
示例2: wpfa_activate
function wpfa_activate()
{
update_option('WPLANG', 'fa_IR');
update_option('start_of_week', '6');
update_option('timezone_string', 'Asia/Tehran');
if (WPFA_NUMS === false) {
add_option('wpfa_nums', 'on');
}
$inc = ABSPATH . 'wp-admin/includes/translation-install.php';
if (file_exists($inc)) {
require_once $inc;
wp_download_language_pack('fa_IR');
}
}
开发者ID:ehsangolshani,项目名称:mohsenGMD-website,代码行数:14,代码来源:wp-farsi.php
示例3: install
/**
* Install a given language.
*
* <language>
* : Language code to install.
*
* @subcommand install
*/
public function install($args, $assoc_args)
{
list($language_code) = $args;
$available = wp_get_installed_translations($this->obj_type);
$available = !empty($available['default']) ? array_keys($available['default']) : array();
if (in_array($language_code, $available)) {
\WP_CLI::warning("Language already installed.");
exit;
}
require_once ABSPATH . '/wp-admin/includes/translation-install.php';
$response = wp_download_language_pack($language_code);
if ($response == $language_code) {
\WP_CLI::success("Language installed.");
} else {
\WP_CLI::error("Couldn't install language.");
}
}
开发者ID:adeagboola,项目名称:wordpress-to-jekyll-exporter,代码行数:25,代码来源:CommandWithTranslation.php
示例4: bogo_load_tools_page
function bogo_load_tools_page()
{
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
$action = isset($_GET['action']) ? $_GET['action'] : '';
if ('install_translation' == $action) {
check_admin_referer('bogo-tools');
if (!current_user_can('update_core')) {
wp_die(__('You are not allowed to install translations.', 'bogo'));
}
$locale = isset($_GET['locale']) ? $_GET['locale'] : null;
if (wp_download_language_pack($locale)) {
$redirect_to = add_query_arg(array('locale' => $locale, 'message' => 'success'), menu_page_url('bogo-tools', false));
} else {
$redirect_to = add_query_arg(array('locale' => $locale, 'message' => 'failed'), menu_page_url('bogo-tools', false));
}
wp_safe_redirect($redirect_to);
exit;
}
}
开发者ID:karthikakamalanathan,项目名称:wp-cookieLawInfo,代码行数:19,代码来源:admin.php
示例5: 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
示例6: switch
}
switch ($step) {
case -1:
if (wp_can_install_language_pack() && empty($language) && ($languages = wp_get_available_translations())) {
setup_config_display_header('language-chooser');
echo '<h1 class="screen-reader-text">Select a default language</h1>';
echo '<form id="setup" method="post" action="?step=0">';
wp_install_language_form($languages);
echo '</form>';
break;
}
// Deliberately fall through if we can't reach the translations API.
// Deliberately fall through if we can't reach the translations API.
case 0:
if (!empty($language)) {
$loaded_language = wp_download_language_pack($language);
if ($loaded_language) {
load_default_textdomain($loaded_language);
$GLOBALS['wp_locale'] = new WP_Locale();
}
}
setup_config_display_header();
$step_1 = 'setup-config.php?step=1';
if (isset($_REQUEST['noapi'])) {
$step_1 .= '&noapi';
}
if (!empty($loaded_language)) {
$step_1 .= '&language=' . $loaded_language;
}
?>
<h1 class="screen-reader-text"><?php
开发者ID:akalipetis,项目名称:WordPress,代码行数:31,代码来源:setup-config.php
示例7: get_current_screen
get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Settings_Screen" target="_blank">Documentation on Network Settings</a>') . '</p>' . '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>');
if ($_POST) {
/** This action is documented in wp-admin/network/edit.php */
do_action('wpmuadminedit');
check_admin_referer('siteoptions');
$checked_options = array('menu_items' => array(), 'registrationnotification' => 'no', 'upload_space_check_disabled' => 1, 'add_new_users' => 0);
foreach ($checked_options as $option_name => $option_unchecked_value) {
if (!isset($_POST[$option_name])) {
$_POST[$option_name] = $option_unchecked_value;
}
}
$options = array('registrationnotification', 'registration', 'add_new_users', 'menu_items', 'upload_space_check_disabled', 'blog_upload_space', 'upload_filetypes', 'site_name', 'first_post', 'first_page', 'first_comment', 'first_comment_url', 'first_comment_author', 'welcome_email', 'welcome_user_email', 'fileupload_maxk', 'global_terms_enabled', 'illegal_names', 'limited_email_domains', 'banned_email_domains', 'WPLANG', 'admin_email');
// Handle translation install.
if (!empty($_POST['WPLANG']) && wp_can_install_language_pack()) {
// @todo: Skip if already installed
$language = wp_download_language_pack($_POST['WPLANG']);
if ($language) {
$_POST['WPLANG'] = $language;
}
}
foreach ($options as $option_name) {
if (!isset($_POST[$option_name])) {
continue;
}
$value = wp_unslash($_POST[$option_name]);
update_site_option($option_name, $value);
}
/**
* Fires after the network options are updated.
*
* @since MU
开发者ID:Plego,项目名称:toyoa,代码行数:31,代码来源:settings.php
示例8: strtolower
if (preg_match('|^([a-zA-Z0-9-])+$|', $blog['domain'])) {
$domain = strtolower($blog['domain']);
}
// If not a subdomain install, make sure the domain isn't a reserved word
if (!is_subdomain_install()) {
/** This filter is documented in wp-includes/ms-functions.php */
$subdirectory_reserved_names = apply_filters('subdirectory_reserved_names', array('page', 'comments', 'blog', 'files', 'feed', 'wp-admin', 'wp-content', 'wp-includes', 'wp-json'));
if (in_array($domain, $subdirectory_reserved_names)) {
wp_die(sprintf(__('The following words are reserved for use by WordPress functions and cannot be used as blog names: <code>%s</code>'), implode('</code>, <code>', $subdirectory_reserved_names)));
}
}
$title = $blog['title'];
$meta = array('public' => 1);
// Handle translation install for the new site.
if (!empty($_POST['WPLANG']) && wp_can_install_language_pack()) {
$language = wp_download_language_pack(wp_unslash($_POST['WPLANG']));
if ($language) {
$meta['WPLANG'] = $language;
}
}
if (empty($domain)) {
wp_die(__('Missing or invalid site address.'));
}
if (isset($blog['email']) && '' === trim($blog['email'])) {
wp_die(__('Missing email address.'));
}
$email = sanitize_email($blog['email']);
if (!is_email($email)) {
wp_die(__('Invalid email address.'));
}
if (is_subdomain_install()) {
开发者ID:nickbert77,项目名称:WordPress,代码行数:31,代码来源:site-new.php
示例9: languages_page
public function languages_page()
{
// prepare the list of tabs
$tabs = array('lang' => __('Languages', 'polylang'));
// only if at least one language has been created
if ($listlanguages = $this->model->get_languages_list()) {
$tabs['strings'] = __('Strings translation', 'polylang');
$tabs['settings'] = __('Settings', 'polylang');
}
// allows plugins to add tabs
$tabs = apply_filters('pll_settings_tabs', $tabs);
switch ($this->active_tab) {
case 'lang':
// prepare the list table of languages
$list_table = new PLL_Table_Languages();
$list_table->prepare_items($listlanguages);
break;
case 'strings':
// get the strings to translate
$data = PLL_Admin_Strings::get_strings();
// get the groups
foreach ($data as $key => $row) {
$groups[] = $row['context'];
}
$groups = array_unique($groups);
$selected = empty($_GET['group']) || !in_array($_GET['group'], $groups) ? -1 : $_GET['group'];
$s = empty($_GET['s']) ? '' : wp_unslash($_GET['s']);
// filter for search string
foreach ($data as $key => $row) {
if (-1 != $selected && $row['context'] != $selected || !empty($s) && stripos($row['name'], $s) === false && stripos($row['string'], $s) === false) {
unset($data[$key]);
}
}
// load translations
foreach ($listlanguages as $language) {
// filters by language if requested
if (($lg = get_user_meta(get_current_user_id(), 'pll_filter_content', true)) && $language->slug != $lg) {
continue;
}
$mo = new PLL_MO();
$mo->import_from_db($language);
foreach ($data as $key => $row) {
$data[$key]['translations'][$language->slug] = $mo->translate($row['string']);
$data[$key]['row'] = $key;
// store the row number for convenience
}
}
// get an array with language slugs as keys, names as values
$languages = array_combine(wp_list_pluck($listlanguages, 'slug'), wp_list_pluck($listlanguages, 'name'));
$string_table = new PLL_Table_String(compact('languages', 'groups', 'selected'));
$string_table->prepare_items($data);
break;
case 'settings':
$post_types = get_post_types(array('public' => true, '_builtin' => false));
$post_types = array_diff($post_types, get_post_types(array('_pll' => true)));
$post_types = array_unique(apply_filters('pll_get_post_types', $post_types, true));
$taxonomies = get_taxonomies(array('public' => true, '_builtin' => false));
$taxonomies = array_diff($taxonomies, get_taxonomies(array('_pll' => true)));
$taxonomies = array_unique(apply_filters('pll_get_taxonomies', $taxonomies, true));
break;
}
$action = isset($_REQUEST['pll_action']) ? $_REQUEST['pll_action'] : '';
switch ($action) {
case 'add':
check_admin_referer('add-lang', '_wpnonce_add-lang');
if ($this->model->add_language($_POST) && 'en_US' != $_POST['locale']) {
// attempts to install the language pack
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
if (!wp_download_language_pack($_POST['locale'])) {
add_settings_error('general', 'pll_download_mo', __('The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang'));
}
// force checking for themes and plugins translations updates
wp_clean_themes_cache();
wp_clean_plugins_cache();
}
self::redirect();
// to refresh the page ( possible thanks to the $_GET['noheader']=true )
break;
case 'delete':
check_admin_referer('delete-lang');
if (!empty($_GET['lang'])) {
$this->model->delete_language((int) $_GET['lang']);
}
self::redirect();
// to refresh the page ( possible thanks to the $_GET['noheader']=true )
break;
case 'edit':
if (!empty($_GET['lang'])) {
$edit_lang = $this->model->get_language((int) $_GET['lang']);
}
break;
case 'update':
check_admin_referer('add-lang', '_wpnonce_add-lang');
$error = $this->model->update_language($_POST);
self::redirect();
// to refresh the page ( possible thanks to the $_GET['noheader']=true )
break;
case 'default-lang':
check_admin_referer('default-lang');
if ($lang = $this->model->get_language((int) $_GET['lang'])) {
//.........这里部分代码省略.........
开发者ID:britwayresources,项目名称:website,代码行数:101,代码来源:settings.php
示例10: languages_page
public function languages_page()
{
// prepare the list of tabs
$tabs = array('lang' => __('Languages', 'polylang'));
// only if at least one language has been created
if ($listlanguages = $this->model->get_languages_list()) {
$tabs['strings'] = __('Strings translation', 'polylang');
$tabs['settings'] = __('Settings', 'polylang');
}
$tabs = apply_filters('pll_settings_tabs', $tabs);
switch ($this->active_tab) {
case 'lang':
// prepare the list table of languages
$list_table = new PLL_Table_Languages();
$list_table->prepare_items($listlanguages);
break;
case 'strings':
// get the strings to translate
$data = PLL_Admin_Strings::get_strings();
// get the groups
foreach ($data as $key => $row) {
$groups[] = $row['context'];
}
$groups = array_unique($groups);
$selected = empty($_REQUEST['group']) || !in_array($_REQUEST['group'], $groups) ? -1 : $_REQUEST['group'];
$s = empty($_REQUEST['s']) ? '' : wp_unslash($_REQUEST['s']);
// filter for search string
foreach ($data as $key => $row) {
if ($selected != -1 && $row['context'] != $selected || !empty($s) && stripos($row['name'], $s) === false && stripos($row['string'], $s) === false) {
unset($data[$key]);
}
}
// load translations
foreach ($listlanguages as $language) {
// filters by language if requested
if (($lg = get_user_meta(get_current_user_id(), 'pll_filter_content', true)) && $language->slug != $lg) {
continue;
}
$mo = new PLL_MO();
// print_r($language);
$mo->import_from_db($language);
foreach ($data as $key => $row) {
$data[$key]['translations'][$language->slug] = $mo->translate($row['string']);
$data[$key]['row'] = $key;
// store the row number for convenience
}
}
// get an array with language slugs as keys, names as values
$languages = array_combine(wp_list_pluck($listlanguages, 'slug'), wp_list_pluck($listlanguages, 'name'));
$string_table = new PLL_Table_String(compact('languages', 'groups', 'selected'));
$string_table->prepare_items($data);
break;
case 'settings':
$post_types = get_post_types(array('public' => true, '_builtin' => false));
$post_types = array_diff($post_types, get_post_types(array('_pll' => true)));
$post_types = array_unique(apply_filters('pll_get_post_types', $post_types, true));
$taxonomies = get_taxonomies(array('public' => true, '_builtin' => false));
$taxonomies = array_diff($taxonomies, get_taxonomies(array('_pll' => true)));
$taxonomies = array_unique(apply_filters('pll_get_taxonomies', $taxonomies, true));
break;
default:
break;
}
$action = isset($_REQUEST['pll_action']) ? $_REQUEST['pll_action'] : '';
switch ($action) {
case 'add':
check_admin_referer('add-lang', '_wpnonce_add-lang');
if ($this->model->add_language($_POST)) {
// backward compatibility WP < 4.0
if (version_compare($GLOBALS['wp_version'], '4.0', '<')) {
PLL_Admin::download_mo($_POST['locale']);
} elseif ('en_US' != $_POST['locale']) {
// attempts to install the language pack
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
if (!wp_download_language_pack($_POST['locale'])) {
add_settings_error('general', 'pll_download_mo', __('The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang'));
}
// force checking for themes and plugins translations updates
wp_update_themes();
wp_update_plugins();
}
}
$this->redirect();
// to refresh the page (possible thanks to the $_GET['noheader']=true)
break;
case 'delete':
check_admin_referer('delete-lang');
if (!empty($_GET['lang'])) {
$this->model->delete_language((int) $_GET['lang']);
}
$this->redirect();
// to refresh the page (possible thanks to the $_GET['noheader']=true)
break;
case 'edit':
if (!empty($_GET['lang'])) {
$edit_lang = $this->model->get_language((int) $_GET['lang']);
}
break;
case 'update':
check_admin_referer('add-lang', '_wpnonce_add-lang');
//.........这里部分代码省略.........
开发者ID:ergov2015,项目名称:rideflag.dev,代码行数:101,代码来源:settings.php
示例11: install
/**
* Install a given language.
*
* <language>
* : Language code to install.
*
* [--activate]
* : If set, the language will be activated immediately after install.
*
* @subcommand install
*/
public function install($args, $assoc_args)
{
list($language_code) = $args;
$available = $this->get_installed_languages();
if (in_array($language_code, $available)) {
\WP_CLI::warning("Language already installed.");
exit;
}
require_once ABSPATH . '/wp-admin/includes/translation-install.php';
$response = wp_download_language_pack($language_code);
if ($response == $language_code) {
\WP_CLI::success("Language installed.");
if (\WP_CLI\Utils\get_flag_value($assoc_args, 'activate')) {
$this->activate(array($language_code), array());
}
} else {
\WP_CLI::error("Couldn't install language.");
}
}
开发者ID:rohmann,项目名称:wp-cli,代码行数:30,代码来源:CommandWithTranslation.php
示例12: handle_actions
/**
* Manages the user input for the languages pages
*
* @since 1.9
*
* @param string $action
*/
public function handle_actions($action)
{
switch ($action) {
case 'add':
check_admin_referer('add-lang', '_wpnonce_add-lang');
if ($this->model->add_language($_POST) && 'en_US' !== $_POST['locale']) {
// attempts to install the language pack
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
if (!wp_download_language_pack($_POST['locale'])) {
add_settings_error('general', 'pll_download_mo', __('The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang'));
}
// force checking for themes and plugins translations updates
wp_clean_themes_cache();
wp_clean_plugins_cache();
}
self::redirect();
// to refresh the page ( possible thanks to the $_GET['noheader']=true )
break;
case 'delete':
check_admin_referer('delete-lang');
if (!empty($_GET['lang'])) {
$this->model->delete_language((int) $_GET['lang']);
}
self::redirect();
// to refresh the page ( possible thanks to the $_GET['noheader']=true )
break;
case 'update':
check_admin_referer('add-lang', '_wpnonce_add-lang');
$error = $this->model->update_language($_POST);
self::redirect();
// to refresh the page ( possible thanks to the $_GET['noheader']=true )
break;
case 'default-lang':
check_admin_referer('default-lang');
if ($lang = $this->model->get_language((int) $_GET['lang'])) {
$this->model->update_default_lang($lang->slug);
}
self::redirect();
// to refresh the page ( possible thanks to the $_GET['noheader']=true )
break;
case 'content-default-lang':
check_admin_referer('content-default-lang');
if ($nolang = $this->model->get_objects_with_no_lang()) {
if (!empty($nolang['posts'])) {
$this->model->set_language_in_mass('post', $nolang['posts'], $this->options['default_lang']);
}
if (!empty($nolang['terms'])) {
$this->model->set_language_in_mass('term', $nolang['terms'], $this->options['default_lang']);
}
}
self::redirect();
// to refresh the page ( possible thanks to the $_GET['noheader']=true )
break;
case 'activate':
check_admin_referer('pll_activate');
$this->modules[$_GET['module']]->activate();
self::redirect();
break;
case 'deactivate':
check_admin_referer('pll_deactivate');
$this->modules[$_GET['module']]->deactivate();
self::redirect();
break;
default:
/**
* Fires when a non default action has been sent to Polylang settings
*
* @since 1.8
*/
do_action("mlang_action_{$action}");
break;
}
}
开发者ID:JSreactor,项目名称:MarketCrater.com,代码行数:80,代码来源:settings.php
示例13: save_meta_box
/**
* Save meta-box.
* Hook for 'save_post'
*
* @from 1.0
*/
public function save_meta_box($post_id, $post)
{
global $sublanguage_admin;
if ($post->post_type == $sublanguage_admin->language_post_type) {
if ((!defined('DOING_AUTOSAVE') || !DOING_AUTOSAVE) && current_user_can('edit_language', $post_id)) {
// save locale (into post_content)
if (isset($_POST['language_locale_nonce'], $_POST['language_locale']) && wp_verify_nonce($_POST['language_locale_nonce'], 'language_locale_action')) {
$locale = esc_attr($_POST['language_locale']);
// download language pack
if ($post->post_content != $locale) {
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
wp_download_language_pack($locale);
wp_update_post(array('ID' => $post->ID, 'post_content' => $locale));
}
flush_rewrite_rules();
}
// save settings
if (isset($_POST['language_settings_nonce']) && wp_verify_nonce($_POST['language_settings_nonce'], 'language_settings_action')) {
if (isset($_POST['language_rtl']) && $_POST['language_rtl']) {
update_post_meta($post->ID, 'rtl', 1);
}
}
}
}
}
开发者ID:Blueprint-Marketing,项目名称:sublanguage,代码行数:31,代码来源:admin-languages.php
示例14: fallback_locale_field
/**
* Download the chosen fallback language on save and create the language dropdown similar to the default language dropdown
*/
public function fallback_locale_field()
{
$languages = get_available_languages();
$translations = wp_get_available_translations();
$fallback_locale = $this->fallback_locale;
// Handle translation install.
if (!empty($fallback_locale) && !in_array($fallback_locale, $languages) && (!is_multisite() || is_super_admin())) {
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
if (wp_can_install_language_pack()) {
$language = wp_download_language_pack($fallback_locale);
if ($language) {
$fallback_locale = $language;
}
}
}
wp_dropdown_languages(array('name' => 'fallback_locale', 'id' => 'fallback_locale', 'selected' => $fallback_locale, 'languages' => $languages, 'translations' => $translations, 'show_available_translations' => (!is_multisite() || is_super_admin()) && wp_can_install_language_pack()));
}
开发者ID:2ndkauboy,项目名称:language-fallback,代码行数:20,代码来源:language-fallback.php
示例15: ajax_language_dashboard
/**
* Lingotek
*/
function ajax_language_dashboard()
{
global $polylang;
$request_method = isset($_REQUEST['_method']) ? $_REQUEST['_method'] : (isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET');
$response = array('method' => $request_method);
switch ($request_method) {
case 'POST':
if (isset($_REQUEST['code'], $_REQUEST['native'], $_REQUEST['direction'])) {
$name = $_REQUEST['native'];
$slug = substr($_REQUEST['code'], 0, strpos($_REQUEST['code'], '_'));
// 3rd parameter of strstr needs PHP 5.3
$locale = Lingotek::map_to_wp_locale($_REQUEST['code']);
// avoid conflicts between language slugs
$existing_slugs = $polylang->model->get_languages_list(array('fields' => 'slug'));
if (!empty($existing_slugs) && in_array($slug, $existing_slugs)) {
$slug = strtolower(str_replace('_', '-', $locale));
}
$rtl = $_REQUEST['direction'] == 'RTL';
$term_group = 0;
// adds the language
$polylang->model->add_language(compact('name', 'slug', 'locale', 'rtl', 'term_group'));
// attempts to install the language pack
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
wp_download_language_pack($locale);
// force checking for themes and plugins translations updates
wp_update_themes();
wp_update_plugins();
$response = array('request' => 'POST: add target language to CMS and Lingotek Project Language', 'locale' => $_REQUEST['code'], 'xcode' => $locale, 'active' => 1, 'enabled' => 1, 'source' => self::get_counts_by_type($locale, 'sources'), 'target' => self::get_counts_by_type($locale, 'targets'));
status_header(200);
}
break;
case 'DELETE':
$body = file_get_contents("php://input");
$code = str_replace('code=', '', $body);
$lang = $polylang->model->get_language(Lingotek::map_to_wp_locale($code));
// map code to WP locales to find the language
// prevents deleting the last language as it would break the Lingotek dashboard
if (1 == count($polylang->model->get_languages_list())) {
$response = array('request' => sprintf('DELETE: remove language from CMS and project (%s)', $code), 'code' => $code, 'success' => false, 'message' => __('You must keep at least one language.', 'wp-lingotek'));
status_header(403);
} elseif (!self::has_language_content($lang)) {
$default_category = pll_get_term(get_option('default_category'), $lang->slug);
$polylang->model->delete_language((int) $lang->term_id);
wp_delete_term($default_category, 'category');
// delete the default category after the language
// Deletes the translation status so when re-adding a language the string groups translations won't display as current
$lingotek_model = new Lingotek_Model();
$strings = $lingotek_model->get_strings();
foreach ($strings as $string) {
$group = $lingotek_model->get_group('string', $string['context']);
unset($group->translations[$lang->locale]);
$group->save();
}
$response = array('request' => sprintf('DELETE: remove language from CMS and project (%s)', $code), 'code' => $code, 'active' => false, 'success' => true);
status_header(204);
} else {
$response = array('request' => sprintf('DELETE: remove language from CMS and project (%s)', $code), 'code' => $code, 'success' => false, 'message' => __('The language can only be removed when no existing content is using it. If you would like to remove this language from the site, then first remove any content assigned to this language.', 'wp-lingotek'));
status_header(403);
}
break;
case 'GET':
default:
$locale_code = isset($_REQUEST['code']) ? $_REQUEST['code'] : NULL;
$response = $response + $this->get_language_details($locale_code);
break;
}
wp_send_json($response);
}
开发者ID:Gordondalos,项目名称:expert,代码行数:71,代码来源:dashboard.php
注:本文中的wp_download_language_pack函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论