private function build_label_array($singular_label, $label) { global $sitepress, $wpdb; $return = array(); $str_name_singular = 'taxonomy singular name: ' . $singular_label; $return['id_singular'] = icl_get_string_id($singular_label, 'WordPress', $str_name_singular); if (!$return['id_singular']) { $return['id_singular'] = icl_register_string('WordPress', $str_name_singular, $singular_label); } $str_name_general = 'taxonomy general name: ' . $label; $return['id_general'] = icl_get_string_id($label, 'WordPress', $str_name_general); if (!$return['id_general']) { $return['id_general'] = icl_register_string('WordPress', $str_name_general, $label); } $active_lang_codes = array_keys($sitepress->get_active_languages(true)); foreach ($active_lang_codes as $language) { $exists_singular = null; $translated_label = icl_translate('WordPress', $str_name_singular, $singular_label, false, $exists_singular, $language); if ($exists_singular) { $return[$language]['singular'] = $translated_label; } $exists_plural = null; $translated_label = icl_translate('WordPress', $str_name_general, $label, false, $exists_plural, $language); if ($exists_plural) { $return[$language]['general'] = $translated_label; } } $string = new WPML_ST_String($return['id_singular'], $wpdb); $return[$string->get_language()] = array('singular' => $singular_label, 'general' => $label, 'original' => true); $return['st_default_lang'] = $string->get_language(); return $return; }
function get_string_language($value, $context, $name = false) { if (WPML_SUPPORT_STRINGS_IN_DIFF_LANG) { global $wpdb; if ($name !== false) { $string_language = apply_filters('wpml_get_string_language', null, $context, $name); } else { $string_id = icl_get_string_id($value, $context, $name); $string_object = new WPML_ST_String($string_id, $wpdb); $string_language = $string_object->get_language(); } return $string_language; } else { global $sitepress_settings; if (isset($sitepress_settings['st']['strings_language'])) { return $sitepress_settings['st']['strings_language']; } return 'en'; } }
static function save_sync_options() { global $sitepress, $wpdb; $slug_settings = $sitepress->get_setting('posts_slug_translation'); if (isset($slug_settings['on']) && $slug_settings['on'] && !empty($_POST['translate_slugs'])) { foreach ($_POST['translate_slugs'] as $type => $data) { $slug_settings['types'][$type] = isset($data['on']) ? intval(!empty($data['on'])) : false; if (empty($slug_settings['types'][$type])) { continue; } $post_type_obj = get_post_type_object($type); $slug = trim($post_type_obj->rewrite['slug'], '/'); $string_id = $wpdb->get_var(self::get_sql_to_get_string_id($type)); $string_id = empty($string_id) ? self::register_string_for_slug($type, $slug) : $string_id; if ($string_id) { if (!isset($data['original'])) { $data['original'] = $sitepress->get_default_language(); } $string = new WPML_ST_String($string_id, $wpdb); if ($string->get_language() != $data['original']) { $string->set_language($data['original']); } if (isset($data['langs'])) { foreach ($sitepress->get_active_languages() as $lang) { if ($lang['code'] != $data['original']) { $data['langs'][$lang['code']] = join('/', array_map(array('WPML_Slug_Translation', 'sanitize'), explode('/', $data['langs'][$lang['code']]))); $data['langs'][$lang['code']] = urldecode($data['langs'][$lang['code']]); icl_add_string_translation($string_id, $lang['code'], $data['langs'][$lang['code']], ICL_TM_COMPLETE); } } } icl_update_string_status($string_id); } } } $sitepress->set_setting('posts_slug_translation', $slug_settings, true); }
public function render($post_type, $custom_post) { $_has_slug = isset($custom_post->rewrite['slug']) && $custom_post->rewrite['slug']; $_on = $this->settings->is_on() && $_has_slug && $this->post_sync_setting->is_sync($post_type); $is_hidden = $_on ? '' : 'hidden'; $_translate = $this->settings->is_translate($post_type); $string_id = null; if ($_has_slug) { list($string_id, $_slug_translations) = WPML_Slug_Translation::get_translations($post_type); if ($this->settings->is_on() && $_translate && !$string_id) { $message = sprintf(__("%s slugs are set to be translated, but they are missing their translation", 'sitepress'), $custom_post->labels->name); ICL_AdminNotifier::displayInstantMessage($message, 'error', 'below-h2', false); } } else { $_slug_translations = false; } if ($_has_slug && $this->settings->is_on()) { ?> <div class="icl_slug_translation_choice <?php echo $is_hidden; ?> "> <p> <label> <input name="translate_slugs[<?php echo $post_type; ?> ][on]" type="checkbox" value="1" <?php checked(1, $_translate, true); ?> /> <?php printf(__('Use different slugs in different languages for %s.', 'sitepress'), $custom_post->labels->name); ?> </label> </p> <table class="js-cpt-slugs <?php if (empty($_translate)) { ?> hidden<?php } ?> "> <?php if ($string_id) { $string = new WPML_ST_String($string_id, $this->wpdb); $string_lang = $string->get_language(); } else { $string_lang = ''; } $string_lang = $string_lang ? $string_lang : $this->sitepress->get_default_language(); $languages = $this->sitepress->get_active_languages(); if (!in_array($string_lang, array_keys($languages))) { $all_languages = $this->sitepress->get_languages(); $languages[$string_lang] = $all_languages[$string_lang]; } $original_slug = WPML_Slug_Translation::get_slug_by_type($post_type); $original_slug = $original_slug ? $original_slug : (isset($custom_post->slug) ? $custom_post->slug : $custom_post->rewrite['slug']); foreach ($languages as $language) { $slug_translation_value = !empty($_slug_translations[$language['code']]['value']) ? $_slug_translations[$language['code']]['value'] : ''; $slug_translation_sample = $original_slug . ' @' . $language['code']; ?> <tr<?php if ($language['code'] == $string_lang) { echo ' style="display:none"'; } ?> > <td> <label for="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]"><?php echo $this->sitepress->get_flag_img($language['code']) . ' ' . $language['display_name']; ?> </label> </td> <td> <input id="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]" class="js-translate-slug" name="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]" type="text" value="<?php echo $slug_translation_value; ?> " placeholder="<?php echo $slug_translation_sample; ?> " data-lang="<?php echo $language['code']; ?> " /> <?php if (isset($_slug_translations[$language['code']]) && $_slug_translations[$language['code']]['status'] != ICL_TM_COMPLETE) { ?> <em class="icl_st_slug_tr_warn"><?php _e("Not marked as 'complete'. Press 'Save' to enable.", 'sitepress'); ?> </em> <?php } ?> </td> </tr> <?php if ($language['code'] == $string_lang) { ?> <tr> <td> <?php $lang_selector = new WPML_Simple_Language_Selector($this->sitepress); $lang_selector->render(array('name' => 'translate_slugs[' . $post_type . '][original]', 'selected' => $language['code'], 'show_please_select' => false, 'echo' => true, 'class' => 'js-translate-slug-original', 'data' => array('slug' => $post_type))); ?> <label for="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]"> <em><?php _e("(original)", 'sitepress'); ?> </em></label> </td> <td><input disabled="disabled" class="disabled" id="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]" name="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]" type="text" value="<?php echo $original_slug; ?> "/> </td> </tr> <?php } } ?> </table> </div> <?php } }
public function register_string($context, $name, $value, $allow_empty_value = false, $source_lang = '') { global $WPML_Sticky_Links; $name = trim($name) ? $name : md5($value); /* cpt slugs - do not register them when scanning themes and plugins * if name starting from 'URL slug: ' * and context is different from 'WordPress' */ if (substr($name, 0, 10) === 'URL slug: ' && 'WordPress' !== $context) { return false; } list($domain, $context, $key) = $this->key_by_name_and_context($name, $context); list($name, $context) = $this->truncate_name_and_context($name, $context); if ($source_lang == '') { $lang_of_domain = new WPML_Language_Of_Domain($this->sitepress); $domain_lang = $lang_of_domain->get_language($domain); $source_lang = $domain_lang ? $domain_lang : (strpos($domain, 'admin_texts_') === 0 || $name === 'Tagline' || $name === 'Blog Title' ? $this->sitepress->get_user_admin_language(get_current_user_id()) : 'en'); } $res = $this->get_registered_string($domain, $context, $name); if ($res) { $string_id = $res['id']; /* * If Sticky Links plugin is active and set to change links in Strings, * we need to process $value and change links into sticky before comparing * with saved in DB $res->value. * Otherwise after every String Translation screen refresh status of this string * will be changed into 'needs update' */ $alp_settings = get_option('alp_settings'); if (!empty($alp_settings['sticky_links_strings']) && $alp_settings['sticky_links_strings'] && defined('WPML_STICKY_LINKS_VERSION')) { // sticky links plugin is active? require_once ICL_PLUGIN_PATH . '/inc/absolute-links/absolute-links.class.php'; $absolute_links_object = new AbsoluteLinks(); $alp_broken_links = array(); $value = $absolute_links_object->_process_generic_text($value, $alp_broken_links); } $update_string = array(); if ($value != $res['value']) { $update_string['value'] = $value; } $string_object = new WPML_ST_String($res['id'], $this->wpdb); $existing_lang = $string_object->get_language(); if (!empty($update_string)) { if ($existing_lang == $source_lang) { $this->wpdb->update($this->wpdb->prefix . 'icl_strings', $update_string, array('id' => $string_id)); $this->wpdb->update($this->wpdb->prefix . 'icl_string_translations', array('status' => ICL_TM_NEEDS_UPDATE), array('string_id' => $string_id)); icl_update_string_status($string_id); } else { $orig_data = array('string_id' => $string_id, 'language' => $source_lang); $update_string['status'] = ICL_TM_COMPLETE; if ($this->wpdb->get_var($this->wpdb->prepare("SELECT COUNT(*)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM {$this->wpdb->prefix}icl_string_translations\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE string_id = %d\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \tAND language = %s", $string_id, $source_lang))) { $this->wpdb->update($this->wpdb->prefix . 'icl_string_translations', $update_string, $orig_data); } else { $this->wpdb->insert($this->wpdb->prefix . 'icl_string_translations', array_merge($update_string, $orig_data)); } icl_update_string_status($string_id); } } } else { $string_id = $this->save_string($value, $allow_empty_value, $source_lang, $domain, $context, $name); } if (defined('WPML_TM_PATH') && !empty($WPML_Sticky_Links) && $WPML_Sticky_Links->settings['sticky_links_strings']) { require_once WPML_TM_PATH . '/inc/translation-proxy/wpml-pro-translation.class.php'; WPML_Pro_Translation::_content_make_links_sticky($string_id, 'string', false); } if (!isset($this->name_cache[$key])) { $this->name_cache[$key] = $value; } return $string_id; }