/**
  * @param $name
  * @param $domain
  *
  * @return string
  */
 public function get_source_lang($name, $domain)
 {
     $domain_lang = $this->lang_of_domain->get_language($domain);
     if (!$domain_lang) {
         $flag = 0 === strpos($domain, 'admin_texts_') || 'Tagline' === $name || 'Blog Title' === $name;
         $domain_lang = $flag ? $this->sitepress->get_user_admin_language(get_current_user_id()) : 'en';
     }
     return $domain_lang;
 }
    public function render($domains)
    {
        $all_languages = $this->sitepress->get_languages($this->sitepress->get_admin_language());
        ?>
			<div id="wpml-change-domain-language-dialog"
				 class="wpml-change-language-dialog"
				 title="<?php 
        _e('Language of domains', 'wpml-string-translation');
        ?>
"
				 style="display:none"
				 data-button-text="<?php 
        _e('Apply', 'wpml-string-translation');
        ?>
" 
				 data-cancel-text="<?php 
        _e('Cancel', 'wpml-string-translation');
        ?>
" >
				<label for="wpml-domain-select">
					<?php 
        _e('Select for which domain to set the language: ', 'wpml-string-translation');
        ?>
				</label>
				<select id="wpml-domain-select">
					<option value="" selected="selected"><?php 
        _e('-- Please select --', 'wpml-string-translation');
        ?>
</option>
					<?php 
        foreach ($domains as $domain) {
            $results = $this->wpdb->get_results($this->wpdb->prepare("\r\n\t\t\t\t\t\t\t\tSELECT language, COUNT(language) AS count\r\n\t\t\t\t\t\t\t\tFROM {$this->wpdb->prefix}icl_strings s\r\n\t\t\t\t\t\t\t\tWHERE context = %s\r\n\t\t\t\t\t\t\t\t\tAND language IN (" . wpml_prepare_in(array_keys($all_languages)) . ")\r\n\t\t\t\t\t\t\t\tGROUP BY language\r\n\t\t\t\t\t\t\t\t", $domain->context), ARRAY_A);
            foreach ($results as &$result) {
                $result['display_name'] = $all_languages[$result['language']]['display_name'];
            }
            $domain_lang = $this->language_of_domain->get_language($domain->context);
            if ($domain_lang) {
                $domain_data = 'data-domain_lang="' . $domain_lang . '" ';
            } else {
                $domain_data = 'data-domain_lang="" ';
            }
            echo '<option value="' . $domain->context . '" data-langs="' . esc_attr(wp_json_encode($results)) . '"' . $domain_data . '>' . $domain->context . '</option>';
        }
        ?>
				
				</select>
				<div class="js-summary wpml-cdl-summary" style="display:none" >
					<p class="wpml-cdl-info">
						<?php 
        _e('This domain currently has the following strings:', 'wpml-string-translation');
        ?>
					</p>
					<table class="widefat striped wpml-cdl-table">
						<thead>
							<tr>
								<td class="manage-column column-cb check-column"><input class="js-all-check" type="checkbox" value="all" /></td>
								<th><?php 
        _e('Current source language', 'wpml-string-translation');
        ?>
</th>
								<th class="num"><?php 
        _e('Number of strings', 'wpml-string-translation');
        ?>
</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div class="js-lang-select-area wpml-cdl-info">
						<label for="wpml-source-domain-language-change"><?php 
        _e('Set the source language of these strings to:', 'wpml-string-translation');
        ?>
</label>
						<?php 
        $lang_selector = new WPML_Simple_Language_Selector($this->sitepress);
        echo $lang_selector->render(array('id' => 'wpml-source-domain-language-change'));
        ?>
						<label for="wpml-cdl-set-default">
							<input id="wpml-cdl-set-default" type="checkbox" class="js-default" value="use-as-default" checked="checked" />
							<?php 
        _e('Use this language as the default language for new strings in this domain', 'wpml-string-translation');
        ?>
						</label>
					</div>
				</div>
				<img src="<?php 
        echo ICL_PLUGIN_URL . '/res/img/ajax-loader.gif';
        ?>
" alt="loading" height="16" width="16" class="wpml_tt_spinner"/>
				<?php 
        wp_nonce_field('wpml_change_string_domain_language_nonce', 'wpml_change_string_domain_language_nonce');
        ?>
			</div>
		<?php 
    }
コード例 #3
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');
         $source_lang = $source_lang ? $source_lang : '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;
         }
         $existing_lang = $this->string_factory->find_by_id($res['id'])->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;
 }
コード例 #4
0
 function get_domain_language($domain)
 {
     if (WPML_SUPPORT_STRINGS_IN_DIFF_LANG) {
         global $sitepress;
         $lang_of_domain = new WPML_Language_Of_Domain($sitepress);
         $domain_lang = $lang_of_domain->get_language($domain);
         if ($domain_lang) {
             $source_lang = $domain_lang;
         } else {
             $source_lang = 'en';
         }
         return $source_lang;
     } else {
         global $sitepress_settings;
         if (isset($sitepress_settings['st']['strings_language'])) {
             return $sitepress_settings['st']['strings_language'];
         }
         return 'en';
     }
 }