本文整理汇总了PHP中icl_add_string_translation函数的典型用法代码示例。如果您正苦于以下问题:PHP icl_add_string_translation函数的具体用法?PHP icl_add_string_translation怎么用?PHP icl_add_string_translation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了icl_add_string_translation函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: migrate_strings
private function migrate_strings()
{
global $wpdb, $sitepress;
$languages = $sitepress->get_active_languages();
$count = 0;
$strings = $wpdb->get_results("SELECT id, context, value, name, language FROM {$wpdb->prefix}icl_strings WHERE context LIKE 'gravity_form-%'");
foreach ($strings as $string) {
if (!$this->endswith($string->name, '-value')) {
$translations = $wpdb->get_results("SELECT language, status FROM {$wpdb->prefix}icl_string_translations WHERE string_id={$string->id}");
foreach ($languages as $language) {
$found = false;
foreach ($translations as $translation) {
if ($translation->language == $language['code'] && $translation->status == 10) {
$found = true;
break;
}
}
if (!$found) {
$possible_translation = $this->find_translation($string->value, substr($string->context, strlen('gravity_form-')), $language['code']);
if ($possible_translation && $possible_translation != $string->value) {
$count++;
icl_add_string_translation($string->id, $language['code'], $possible_translation, 10);
}
}
}
}
}
return $count;
}
示例2: translation_send_strings_local
public static function translation_send_strings_local($string_ids, $target, $translator = null, $basket_name = null)
{
global $wpdb;
static $site_translators;
if (!isset($site_translators)) {
$site_translators = TranslationManagement::get_blog_translators();
}
$mkey = $wpdb->prefix . 'strings_notification';
$lkey = $wpdb->prefix . 'language_pairs';
$slang = TranslationProxy_Basket::get_source_language();
foreach ($string_ids as $string_id) {
$batch_id = TranslationProxy_Batch::update_translation_batch($basket_name);
$added = icl_add_string_translation($string_id, $target, null, ICL_TM_WAITING_FOR_TRANSLATOR, $translator, 'local', $batch_id);
if ($added) {
foreach ($site_translators as $key => $st) {
$ulangs = isset($st->{$lkey}) ? $st->{$lkey} : false;
if (!empty($ulangs) && !empty($ulangs[$slang][$target])) {
$enot = isset($st->{$mkey}) ? $st->{$mkey} : false;
if (empty($enot[$slang][$target])) {
self::translator_notification($st, $slang, $target);
$enot[$slang][$target] = 1;
$site_translators[$key]->{$mkey} = $enot;
update_option($wpdb->prefix . 'icl_translators_cached', $site_translators);
}
}
}
}
}
return 1;
}
示例3: save_label_translations
/**
* Ajax handler for saving label translations from the WPML Taxonomy Translations menu.
*/
public function save_label_translations()
{
if (!wpml_is_action_authenticated('wpml_tt_save_labels_translation')) {
wp_send_json_error('Wrong Nonce');
}
$general = isset($_POST['plural']) ? sanitize_text_field($_POST['plural']) : false;
$singular = isset($_POST['singular']) ? sanitize_text_field($_POST['singular']) : false;
$taxonomy = isset($_POST['taxonomy']) ? sanitize_text_field($_POST['taxonomy']) : false;
$language = isset($_POST['taxonomy_language_code']) ? sanitize_text_field($_POST['taxonomy_language_code']) : false;
if ($singular && $general && $taxonomy && $language) {
$tax_label_data = $this->get_label_translations(false, $taxonomy);
if (isset($tax_label_data['id_singular']) && $tax_label_data['id_singular'] && isset($tax_label_data['id_general']) && $tax_label_data['id_general']) {
$original_id_singular = $tax_label_data['id_singular'];
$original_id_plural = $tax_label_data['id_general'];
icl_add_string_translation($original_id_singular, $language, $singular, ICL_TM_COMPLETE);
$singular_result = (string) icl_get_string_by_id($original_id_singular, $language);
icl_add_string_translation($original_id_plural, $language, $general, ICL_TM_COMPLETE);
$plural_result = (string) icl_get_string_by_id($original_id_plural, $language);
if ($singular_result && $plural_result) {
$result = array('singular' => $singular_result, 'general' => $plural_result, 'lang' => $language);
wp_send_json_success($result);
}
}
}
wp_send_json_error();
}
示例4: test_get_translated_tax_slug
function test_get_translated_tax_slug()
{
$category_base = !empty($this->wc_permalinks['category_base']) ? trim($this->wc_permalinks['category_base'], '/') : 'product-category';
$name = $this->url_translation->url_string_name('product_cat');
do_action('wpml_register_single_string', $this->url_translation->url_strings_context(), $name, $category_base);
$string_id = icl_get_string_id($category_base, $this->url_translation->url_strings_context(), $name);
icl_add_string_translation($string_id, 'es', 'categoria-producto', ICL_TM_COMPLETE);
$translated_tax = $this->url_translation->get_translated_tax_slug('product_cat', 'es');
$this->assertTrue((bool) has_filter('wpml_translate_single_string'));
$this->assertEquals('categoria-producto', $translated_tax['translated_slug']);
}
示例5: test_translate_attributes_label_in_wp_taxonomies
function test_translate_attributes_label_in_wp_taxonomies()
{
global $wp_taxonomies, $sitepress, $WPML_String_Translation;
$WPML_String_Translation->init_active_languages();
$label = 'Test attr';
$name = wc_attribute_taxonomy_name($label);
$taxonomy_data = array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'labels' => array('name' => $label, 'singular_name' => $label, 'search_items' => sprintf(__('Search %s', 'woocommerce'), $label), 'all_items' => sprintf(__('All %s', 'woocommerce'), $label), 'parent_item' => sprintf(__('Parent %s', 'woocommerce'), $label), 'parent_item_colon' => sprintf(__('Parent %s:', 'woocommerce'), $label), 'edit_item' => sprintf(__('Edit %s', 'woocommerce'), $label), 'update_item' => sprintf(__('Update %s', 'woocommerce'), $label), 'add_new_item' => sprintf(__('Add New %s', 'woocommerce'), $label), 'new_item_name' => sprintf(__('New %s', 'woocommerce'), $label)), 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'meta_box_cb' => false, 'query_var' => 1, 'rewrite' => false, 'sort' => false, 'public' => 1, 'show_in_nav_menus' => 1, 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'));
$taxonomy_data['rewrite'] = array('slug' => empty($permalinks['attribute_base']) ? '' : trailingslashit($permalinks['attribute_base']) . sanitize_title($label), 'with_front' => false, 'hierarchical' => true);
do_action('wpml_register_single_string', 'WordPress', 'taxonomy singular name: ' . $label, $label);
$string_id = icl_get_string_id($label, 'WordPress', 'taxonomy singular name: ' . $label);
icl_add_string_translation($string_id, 'es', 'Test attr es', ICL_TM_COMPLETE);
$WPML_String_Translation->clear_string_filter('es');
$sitepress->switch_lang('es');
register_taxonomy($name, apply_filters("woocommerce_taxonomy_objects_{$name}", array('product')), apply_filters("woocommerce_taxonomy_args_{$name}", $taxonomy_data));
$this->assertTrue((bool) has_filter('wpml_translate_single_string'));
$this->assertEquals('Test attr es', $wp_taxonomies[$name]->labels->name);
}
示例6: update_translation
/**
*
* @param string $option_name
* @param string $language
* @param string $new_value
* @param int|bool $status
* @param int $translator_id
* @param int $rec_level
*
* @return boolean|mixed
*/
public function update_translation($option_name, $language, $new_value = null, $status = false, $translator_id = null, $rec_level = 0)
{
$new_value = (array) $new_value;
$updated = array();
foreach ($new_value as $index => $value) {
if (is_array($value)) {
$name = "[" . $option_name . "][" . $index . "]";
$result = $this->update_translation($name, $language, $value, $status, $translator_id, $rec_level + 1);
$updated[] = array_sum(explode(",", $result));
} else {
if (is_string($index)) {
$name = ($rec_level == 0 ? "[" . $option_name . "]" : $option_name) . $index;
} else {
$name = $option_name;
}
$original_string_id = $this->wpdb->get_var($this->wpdb->prepare("\tSELECT id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM {$this->wpdb->prefix}icl_strings\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE name = %s\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND language != %s", $name, $language));
if ($original_string_id) {
$updated[] = icl_add_string_translation($original_string_id, $language, $value, $status, $translator_id);
}
}
}
return array_sum($updated) > 0 ? join(",", $updated) : false;
}
示例7: send_strings_to_translation_service
function send_strings_to_translation_service($string_ids, $target_language, $translator_id)
{
/** @var WPML_String_Translation $WPML_String_Translation */
global $WPML_String_Translation;
if (sizeof($string_ids) > 0) {
$project = $this->basket->get_project();
$strings = array();
$word_count = 0;
$source_language = $this->basket->get_source_language();
foreach ($string_ids as $string_id) {
$string_data_query = "SELECT id, context, name, value FROM {$this->wpdb->prefix}icl_strings WHERE id=%d";
$string_data_prepare = $this->wpdb->prepare($string_data_query, $string_id);
$string_data = $this->wpdb->get_row($string_data_prepare);
$word_count += $WPML_String_Translation->estimate_word_count($string_data->value, $source_language);
$strings[] = $string_data;
}
$xliff = new WPML_TM_Xliff_Writer($this->job_factory);
$res = $project->send_to_translation_batch_mode($xliff->get_strings_xliff_file($strings, $source_language, $target_language), 'String Translations', '', '', $source_language, $target_language, $word_count);
if ($res) {
foreach ($strings as $string_data) {
$translation_service = TranslationProxy_Service::get_translator_data_from_wpml($translator_id);
$added = icl_add_string_translation($string_data->id, $target_language, null, ICL_TM_WAITING_FOR_TRANSLATOR, $translation_service['translator_id'], $translation_service['translation_service'], TranslationProxy_Batch::update_translation_batch($this->basket->get_name()));
if ($added) {
$data = array('rid' => $res, 'string_translation_id' => $added, 'timestamp' => date('Y-m-d H:i:s'), 'md5' => md5($string_data->value));
$this->wpdb->insert($this->wpdb->prefix . 'icl_string_status', $data);
//insert rid
}
}
$this->wpdb->insert($this->wpdb->prefix . 'icl_core_status', array('rid' => $res, 'module' => '', 'origin' => $source_language, 'target' => $target_language, 'status' => ICL_TM_WAITING_FOR_TRANSLATOR));
if ($project->errors && count($project->errors)) {
$res['errors'] = $project->errors;
}
return $res;
}
}
return 0;
}
示例8: ajax_calls
function ajax_calls($call, $data)
{
require_once WPML_ST_PATH . '/inc/admin-texts/wpml-admin-text-configuration.php';
switch ($call) {
case 'icl_st_save_translation':
$icl_st_complete = isset($data['icl_st_translation_complete']) && $data['icl_st_translation_complete'] ? ICL_TM_COMPLETE : ICL_TM_NOT_TRANSLATED;
if (get_magic_quotes_gpc()) {
$data = stripslashes_deep($data);
}
if (icl_st_is_translator()) {
$translator_id = get_current_user_id() > 0 ? get_current_user_id() : null;
} else {
$translator_id = null;
}
echo icl_add_string_translation($data['icl_st_string_id'], $data['icl_st_language'], stripslashes($data['icl_st_translation']), $icl_st_complete, $translator_id);
echo '|';
$ts = icl_update_string_status($data['icl_st_string_id']);
if (icl_st_is_translator()) {
$ts = icl_get_relative_translation_status($data['icl_st_string_id']);
}
echo WPML_ST_String_Statuses::get_status($ts);
break;
case 'icl_st_delete_strings':
$arr = explode(',', $data['value']);
__icl_unregister_string_multi($arr);
break;
case 'icl_st_option_writes_form':
if (!empty($data['icl_admin_options'])) {
$wpml_admin_text = wpml_st_load_admin_texts();
$wpml_admin_text->icl_register_admin_options($data['icl_admin_options']);
echo '1|';
} else {
echo '0' . __('No strings selected', 'wpml-string-translation');
}
break;
case 'icl_st_ow_export':
// filter empty options out
do {
list($data['icl_admin_options'], $empty_found) = _icl_st_filter_empty_options_out($data['icl_admin_options']);
} while ($empty_found);
if (!empty($data['icl_admin_options'])) {
foreach ($data['icl_admin_options'] as $k => $opt) {
if (!$opt) {
unset($data['icl_admin_options'][$k]);
}
}
$wpml_admin_text_config = new WPML_Admin_Text_Configuration();
$message = __('Save the following to a wpml-config.xml in the root of your theme or plugin.', 'wpml-string-translation') . "<textarea wrap=\"soft\" spellcheck=\"false\">" . htmlentities($wpml_admin_text_config->get_wpml_config_file($data['icl_admin_options'])) . "</textarea>";
} else {
$message = __('Error: no strings selected', 'wpml-string-translation');
}
echo json_encode(array('error' => 0, 'message' => $message));
break;
}
}
示例9: tl_rescan_p
function tl_rescan_p()
{
global $wpdb, $sitepress_settings;
set_time_limit(0);
if (preg_replace('#M$#', '', ini_get('memory_limit')) < 128) {
ini_set('memory_limit', '128M');
}
$plugins = array();
if (!empty($_POST['plugin'])) {
foreach ($_POST['plugin'] as $plugin) {
$plugins[] = array('file' => $plugin, 'mu' => 0);
// regular plugins
}
}
if (!empty($_POST['mu-plugin'])) {
foreach ($_POST['mu-plugin'] as $plugin) {
$plugins[] = array('file' => $plugin, 'mu' => 1);
//mu plugins
}
}
$scan_stats = '';
foreach ($plugins as $p) {
$plugin = $p['file'];
if (false !== strpos($plugin, '/') && !$p['mu']) {
$plugin = dirname($plugin);
}
if ($p['mu']) {
$plugin_path = WPMU_PLUGIN_DIR . '/' . $plugin;
} else {
$plugin_path = WP_PLUGIN_DIR . '/' . $plugin;
}
$scan_stats .= icl_st_scan_plugin_files($plugin_path);
if ($_POST['icl_load_mo'] && !$p['mu']) {
$mo_files = icl_st_get_mo_files($plugin_path);
foreach ($mo_files as $m) {
$i = preg_match('#[-]([a-z_]+)\\.mo$#i', $m, $matches);
if ($i && ($lang = $wpdb->get_var("SELECT code FROM {$wpdb->prefix}icl_locale_map WHERE locale='" . $matches[1] . "'"))) {
$tr_pairs = icl_st_load_translations_from_mo($m);
foreach ($tr_pairs as $original => $translation) {
$string_id = icl_get_string_id($original, 'plugin ' . basename($plugin_path));
if (!$wpdb->get_var("SELECT id FROM {$wpdb->prefix}icl_string_translations WHERE string_id={$string_id} AND language='{$lang}'")) {
icl_add_string_translation($string_id, $lang, $translation, ICL_STRING_TRANSLATION_COMPLETE);
}
}
}
}
}
}
echo '1|' . $scan_stats;
exit;
}
示例10: translate_product_slug
function translate_product_slug()
{
global $sitepress, $wpdb, $woocommerce, $sitepress_settings;
if (!defined('WOOCOMMERCE_VERSION') || (!isset($GLOBALS['ICL_Pro_Translation']) || is_null($GLOBALS['ICL_Pro_Translation']))) {
return;
}
$permalinks = get_option('woocommerce_permalinks', array('product_base' => ''));
$slug = get_option('woocommerce_product_slug') != false ? get_option('woocommerce_product_slug') : 'product';
$string = $wpdb->get_row($wpdb->prepare("SELECT id,status FROM {$wpdb->prefix}icl_strings WHERE name = %s AND value = %s ", 'URL slug: ' . $slug, $slug));
if (!$string) {
icl_register_string('WordPress', 'URL slug: ' . $slug, $slug);
$string = $wpdb->get_row($wpdb->prepare("SELECT id,status FROM {$wpdb->prefix}icl_strings WHERE name = %s AND value = %s ", 'URL slug: ' . $slug, $slug));
}
if (isset($sitepress_settings['posts_slug_translation']['types'])) {
$iclsettings['posts_slug_translation']['types'] = $sitepress_settings['posts_slug_translation']['types'];
}
if (!empty($permalinks['product_base']) && isset($sitepress_settings['posts_slug_translation']['types'][$slug])) {
$iclsettings['posts_slug_translation']['types'][$slug] = 0;
$sitepress->save_settings($iclsettings);
}
if (empty($sitepress_settings['theme_localization_type']) || $sitepress_settings['theme_localization_type'] != 1) {
$sitepress->save_settings(array('theme_localization_type' => 1));
}
if ($string->status != ICL_STRING_TRANSLATION_COMPLETE) {
//get translations from .mo files
$current_language = $sitepress->get_current_language();
$default_language = $sitepress->get_default_language();
$active_languages = $sitepress->get_active_languages();
$string_id = $string->id;
if (empty($string_id)) {
$string_id = icl_register_string('WordPress', 'URL slug: ' . $slug, $slug);
}
foreach ($active_languages as $language) {
if ($language['code'] != $sitepress_settings['st']['strings_language']) {
$sitepress->switch_lang($language['code']);
$context = 'slug';
$domain = 'woocommerce';
$woocommerce->load_plugin_textdomain();
$string_text = _x($slug, $context, $domain);
unload_textdomain($domain);
icl_add_string_translation($string_id, $language['code'], $string_text, ICL_STRING_TRANSLATION_COMPLETE, null);
$sitepress->switch_lang($current_language);
}
}
$woocommerce->load_plugin_textdomain();
$wpdb->update($wpdb->prefix . 'icl_strings', array('status' => ICL_STRING_TRANSLATION_COMPLETE), array('id' => $string_id));
}
$iclsettings['posts_slug_translation']['on'] = 1;
$iclsettings['posts_slug_translation']['types'][$slug] = 1;
$sitepress->save_settings($iclsettings);
}
示例11: save_translation
function save_translation($data)
{
global $wpdb, $sitepress, $sitepress_settings, $ICL_Pro_Translation;
$new_post_id = false;
$is_incomplete = false;
foreach ($data['fields'] as $field) {
$this->_save_translation_field($field['tid'], $field);
if (!isset($field['finished']) || !$field['finished']) {
$is_incomplete = true;
}
}
//check if translation job still exists
$job_count = $wpdb->get_var($wpdb->prepare("SELECT count(1) FROM {$wpdb->prefix}icl_translate_job WHERE job_id=%d", $data['job_id']));
if ($job_count == 0) {
wp_redirect(admin_url(sprintf('admin.php?page=%s', WPML_TM_FOLDER . '/menu/translations-queue.php', 'job-cancelled')));
exit;
}
if (!empty($data['complete']) && !$is_incomplete) {
$wpdb->update($wpdb->prefix . 'icl_translate_job', array('translated' => 1), array('job_id' => $data['job_id']));
$rid = $wpdb->get_var($wpdb->prepare("SELECT rid FROM {$wpdb->prefix}icl_translate_job WHERE job_id=%d", $data['job_id']));
$translation_id = $wpdb->get_var($wpdb->prepare("SELECT translation_id FROM {$wpdb->prefix}icl_translation_status WHERE rid=%d", $rid));
$wpdb->update($wpdb->prefix . 'icl_translation_status', array('status' => ICL_TM_COMPLETE, 'needs_update' => 0), array('rid' => $rid));
list($element_id, $trid) = $wpdb->get_row($wpdb->prepare("SELECT element_id, trid FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", $translation_id), ARRAY_N);
$job = $this->get_translation_job($data['job_id'], true);
$parts = explode('_', $job->original_doc_id);
if ($parts[0] == 'external') {
// Translations are saved in the string table for 'external' types
$id = array_pop($parts);
unset($parts[0]);
$type = implode('_', $parts);
$type = apply_filters('WPML_get_package_type', $type, $job->original_doc_id);
foreach ($job->elements as $field) {
if ($field->field_translate) {
if (function_exists('icl_st_is_registered_string')) {
$string_id = icl_st_is_registered_string($type, $id . '_' . $field->field_type);
if (!$string_id) {
icl_register_string($type, $id . '_' . $field->field_type, self::decode_field_data($field->field_data, $field->field_format));
$string_id = icl_st_is_registered_string($type, $id . '_' . $field->field_type);
}
if ($string_id) {
icl_add_string_translation($string_id, $job->language_code, self::decode_field_data($field->field_data_translated, $field->field_format), ICL_STRING_TRANSLATION_COMPLETE);
}
}
}
}
} else {
if (!is_null($element_id)) {
$postarr['ID'] = $_POST['post_ID'] = $element_id;
}
foreach ($job->elements as $field) {
switch ($field->field_type) {
case 'title':
$postarr['post_title'] = self::decode_field_data($field->field_data_translated, $field->field_format);
break;
case 'body':
$postarr['post_content'] = self::decode_field_data($field->field_data_translated, $field->field_format);
break;
case 'excerpt':
$postarr['post_excerpt'] = self::decode_field_data($field->field_data_translated, $field->field_format);
break;
case 'URL':
$postarr['post_name'] = self::decode_field_data($field->field_data_translated, $field->field_format);
break;
default:
break;
}
}
$original_post = get_post($job->original_doc_id);
$postarr['post_author'] = $original_post->post_author;
$postarr['post_type'] = $original_post->post_type;
if ($sitepress_settings['sync_comment_status']) {
$postarr['comment_status'] = $original_post->comment_status;
}
if ($sitepress_settings['sync_ping_status']) {
$postarr['ping_status'] = $original_post->ping_status;
}
if ($sitepress_settings['sync_page_ordering']) {
$postarr['menu_order'] = $original_post->menu_order;
}
if ($sitepress_settings['sync_private_flag'] && $original_post->post_status == 'private') {
$postarr['post_status'] = 'private';
}
if ($sitepress_settings['sync_post_date']) {
$postarr['post_date'] = $original_post->post_date;
}
//set as draft or the same status as original post
$postarr['post_status'] = !$sitepress_settings['translated_document_status'] ? 'draft' : $original_post->post_status;
if ($original_post->post_parent) {
$post_parent_trid = $wpdb->get_var("SELECT trid FROM {$wpdb->prefix}icl_translations\n\t\t\t\t\t\tWHERE element_type='post_{$original_post->post_type}' AND element_id='{$original_post->post_parent}'");
if ($post_parent_trid) {
$parent_id = $wpdb->get_var("SELECT element_id FROM {$wpdb->prefix}icl_translations\n\t\t\t\t\t\t\tWHERE element_type='post_{$original_post->post_type}' AND trid='{$post_parent_trid}' AND language_code='{$job->language_code}'");
}
}
if (isset($parent_id) && $sitepress_settings['sync_page_parent']) {
$_POST['post_parent'] = $postarr['post_parent'] = $parent_id;
$_POST['parent_id'] = $postarr['parent_id'] = $parent_id;
}
$_POST['trid'] = $trid;
$_POST['lang'] = $job->language_code;
$_POST['skip_sitepress_actions'] = true;
//.........这里部分代码省略.........
示例12: add_default_slug_translations
function add_default_slug_translations($slug, $name)
{
global $woocommerce_wpml, $sitepress, $wpdb;
$string_id = icl_get_string_id($slug, $this->url_strings_context(), $name);
if (WPML_SUPPORT_STRINGS_IN_DIFF_LANG) {
$string_language = $woocommerce_wpml->strings->get_string_language($slug, $this->url_strings_context(), $name);
// will use a filter in the future wpmlst-529
$string_object = new WPML_ST_String($string_id, $wpdb);
$string_translation_statuses = $string_object->get_translation_statuses();
} else {
$string_language = $wpdb->get_var($wpdb->prepare("SELECT language FROM {$wpdb->prefix}icl_strings WHERE id=%d", $string_id));
$string_translation_statuses = $wpdb->get_results($wpdb->prepare("SELECT language, status FROM {$wpdb->prefix}icl_string_translations WHERE string_id=%d", $string_id));
}
foreach ($string_translation_statuses as $s) {
$string_translations[$s->language] = $s->status;
}
$languages = $sitepress->get_active_languages();
foreach ($languages as $language => $language_info) {
if ($language != $string_language) {
// check if there's an existing translation
if (!isset($string_translations[$language])) {
$slug_translation = $woocommerce_wpml->strings->get_translation_from_woocommerce_mo_file($slug, $language, false);
if ($slug_translation) {
// add string translation
icl_add_string_translation($string_id, $language, $slug_translation, ICL_STRING_TRANSLATION_COMPLETE);
}
}
}
}
}
示例13: save_labels_translation
/**
* Ajax handler for saving label translations from the WPML Taxonomy Translations menu.
*/
public static function save_labels_translation()
{
$general = isset($_POST['plural']) ? $_POST['plural'] : false;
$singular = isset($_POST['singular']) ? $_POST['singular'] : false;
$taxonomy = isset($_POST['taxonomy']) ? $_POST['taxonomy'] : false;
$language = isset($_POST['taxonomy_language_code']) ? $_POST['taxonomy_language_code'] : false;
if ($singular && $general && $taxonomy && $language) {
$tax_label_data = WPML_Taxonomy_Translation_Table_Display::get_label_translations($taxonomy);
if (isset($tax_label_data['id_singular']) && $tax_label_data['id_singular'] && isset($tax_label_data['id_general']) && $tax_label_data['id_general']) {
$original_id_singular = $tax_label_data['id_singular'];
$original_id_plural = $tax_label_data['id_general'];
icl_add_string_translation($original_id_singular, $language, $singular, ICL_STRING_TRANSLATION_COMPLETE);
$singular_result = (string) icl_get_string_by_id($original_id_singular, $language);
icl_add_string_translation($original_id_plural, $language, $general, ICL_STRING_TRANSLATION_COMPLETE);
$plural_result = (string) icl_get_string_by_id($original_id_plural, $language);
if ($singular_result && $plural_result) {
$result = array('singular' => $singular_result, 'general' => $plural_result, 'lang' => $language);
wp_send_json_success($result);
}
}
}
wp_send_json_error();
}
示例14: add_translated_document
function add_translated_document($translation_id, $request_id)
{
global $sitepress_settings, $wpdb, $sitepress;
$iclq = new ICanLocalizeQuery($sitepress_settings['site_id'], $sitepress_settings['access_key']);
$tinfo = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", $translation_id));
$_lang = $sitepress->get_language_details($tinfo->language_code);
$translation = $iclq->cms_do_download($request_id, $this->server_languages_map($_lang['english_name']));
$translation = apply_filters('icl_data_from_pro_translation', $translation);
$ret = false;
if (!empty($translation)) {
$language_code = $wpdb->get_var($wpdb->prepare("\n SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", $translation_id));
$parts = explode('_', $translation['original_id']);
if ($parts[0] == 'external') {
// Translations are saved in the string table for 'external' types
$id = array_pop($parts);
unset($parts[0]);
$type = implode('_', $parts);
unset($translation['original_id']);
foreach ($translation as $field => $value) {
if (function_exists('icl_st_is_registered_string')) {
$value = str_replace('�A;', "\n", $value);
$string_id = icl_st_is_registered_string($type, $id . '_' . $field);
if (!$string_id) {
icl_register_string($type, $id . '_' . $field, $value);
$string_id = icl_st_is_registered_string($type, $id . '_' . $field);
}
if ($string_id) {
icl_add_string_translation($string_id, $language_code, $value, ICL_STRING_TRANSLATION_COMPLETE);
}
}
}
$ret = true;
} else {
$ret = $this->save_post_translation($translation_id, $translation);
}
if ($ret) {
$lang_details = $sitepress->get_language_details($language_code);
$language_server = $this->server_languages_map($lang_details['english_name']);
$iclq->cms_update_request_status($request_id, CMS_TARGET_LANGUAGE_DONE, $language_server);
$translations = $sitepress->get_element_translations($tinfo->trid, $tinfo->element_type);
if (isset($translations[$tinfo->language_code])) {
$iclq->report_back_permalink($request_id, $language_server, $translations[$tinfo->language_code]);
}
}
}
return $ret;
}
示例15: save_translations
function save_translations($data, $language, $version = false)
{
set_time_limit(0);
if (false === $version) {
global $wp_version;
$version = preg_replace('#-(.+)$#', '', $wp_version);
}
foreach ($data as $key => $string) {
$string_id = icl_register_string(self::CONTEXT, $string['name'], $string['string']);
if ($string_id) {
icl_add_string_translation($string_id, $language, $string['translation'], ICL_STRING_TRANSLATION_COMPLETE);
}
}
$version_projects = explode(';', $version);
foreach ($version_projects as $project) {
$exp = explode('|', $project);
$this->settings['translations'][$language][$exp[0]]['time'] = time();
$this->settings['translations'][$language][$exp[0]]['installed'] = $exp[1];
}
$this->save_settings();
}