コード例 #1
0
 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;
 }
コード例 #2
0
 function set_string_language($value, $context, $name, $language)
 {
     if (WPML_SUPPORT_STRINGS_IN_DIFF_LANG) {
         global $wpdb;
         $string_id = icl_get_string_id($value, $context, $name);
         $string_object = new WPML_ST_String($string_id, $wpdb);
         $string_language = $string_object->set_language($language);
         return $string_language;
     } else {
         return false;
     }
 }
 public function change_language_of_strings($domain, $langs, $to_lang, $set_as_default)
 {
     $package_translation = new WPML_Package_Helper();
     $package_translation->change_language_of_strings_in_domain($domain, $langs, $to_lang);
     if (!empty($langs)) {
         foreach ($langs as &$lang) {
             $lang = "'" . $lang . "'";
         }
         $langs = implode(',', $langs);
         $update_query = "UPDATE {$this->wpdb->prefix}icl_strings SET language=%s WHERE context=%s AND language IN ({$langs})";
         $update_prepare = $this->wpdb->prepare($update_query, $to_lang, $domain);
         $this->wpdb->query($update_prepare);
     }
     if ($set_as_default) {
         $lang_of_domain = new WPML_Language_Of_Domain($this->sitepress);
         $lang_of_domain->set_language($domain, $to_lang);
     }
     $string_ids = $this->wpdb->get_col($this->wpdb->prepare("SELECT id FROM {$this->wpdb->prefix}icl_strings WHERE context = %s", $domain));
     foreach ($string_ids as $strid) {
         $string = new WPML_ST_String($strid, $this->wpdb);
         $string->update_status();
     }
     return array('success' => true);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
    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 
        }
    }
コード例 #6
0
 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);
                 }
             }
         }
     }
 }
コード例 #7
0
function icl_add_string_translation($string_id, $language, $value = null, $status = false, $translator_id = null, $translation_service = null, $batch_id = null)
{
    global $wpdb;
    $string = new WPML_ST_String($string_id, $wpdb);
    return $string->set_translation($language, $value, $status, $translator_id, $translation_service, $batch_id);
}
コード例 #8
0
 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;
 }
コード例 #9
0
ファイル: functions.php プロジェクト: SayenkoDesign/ividf
function icl_add_string_translation($string_id, $language, $value = null, $status = false, $translator_id = null, $translation_service = null, $batch_id = null)
{
    global $wpdb, $WPML_String_Translation;
    $string = new WPML_ST_String($string_id, $wpdb);
    $translated_string_id = $string->set_translation($language, $value, $status, $translator_id, $translation_service, $batch_id);
    $string_filter = $WPML_String_Translation->get_string_filter($language);
    if ($string_filter) {
        $string_filter->clear_cache();
    }
    return $translated_string_id;
}