예제 #1
0
function qtranxf_trim_words($text, $num_words, $more, $original_text)
{
    global $q_config;
    //qtranxf_dbg_log('qtranxf_trim_words: $text: ',$text);
    //qtranxf_dbg_log('qtranxf_trim_words: $original_text: ',$original_text);
    $blocks = qtranxf_get_language_blocks($original_text);
    //qtranxf_dbg_log('qtranxf_trim_words: $blocks: ',$blocks);
    if (count($blocks) <= 1) {
        return $text;
    }
    $lang = $q_config['language'];
    $texts = qtranxf_split_blocks($blocks);
    foreach ($texts as $key => $txt) {
        $texts[$key] = wp_trim_words($txt, $num_words, $more);
    }
    return qtranxf_join_b($texts);
    //has to be 'b', because 'c' gets stripped in /wp-admin/includes/nav-menu.php:182: esc_html( $item->description )
}
예제 #2
0
function qtranxf_use_block($lang, $blocks, $show_available = false, $show_empty = false)
{
    //qtranxf_dbg_log('qtranxf_use_block:('.$lang.') $blocks: ', $blocks);
    $available_langs = array();
    $content = qtranxf_split_blocks($blocks, $available_langs);
    //qtranxf_dbg_log('qtranxf_use_block: $content: ',$content);
    //qtranxf_dbg_log('qtranxf_use_block: $available_langs: ',$available_langs);
    return qtranxf_use_content($lang, $content, $available_langs, $show_available, $show_empty);
}
예제 #3
0
function qtranxf_use_block($lang, $blocks, $show_available = false, $show_empty = false)
{
    global $q_config;
    $available_langs = array();
    //$content = qtranxf_split_blocks($blocks);
    $content = qtranxf_split_blocks($blocks, $available_langs);
    //qtranxf_dbg_log('qtranxf_use_block: $available_langs: ',$available_langs);
    // if content is available show the content in the requested language
    //if(!empty($content[$lang])) return $content[$lang];
    if (!empty($available_langs[$lang])) {
        return $content[$lang];
    } elseif ($show_empty) {
        return '';
    }
    // content is not available in requested language (bad!!) what now?
    // find available and alternative languages
    //if(empty($content[$q_config['default_language']])){
    if (empty($available_langs[$q_config['default_language']])) {
        $alt_lang = null;
        $alt_content = null;
        $alt_lang_is_default = false;
        foreach ($available_langs as $language => $b) {
            if (!qtranxf_isEnabled($language)) {
                continue;
            }
            $alt_lang = $language;
            $alt_content = $content[$language];
            break;
        }
    } else {
        $alt_lang = $q_config['default_language'];
        $alt_content = $content[$alt_lang];
        $alt_lang_is_default = true;
    }
    /*
    	$available_languages = array();
    	foreach($content as $language => $lang_text) {
    		if(empty($lang_text)) continue;
    		if(!qtranxf_isEnabled($language)) continue;
    		$available_languages[] = $language;
    		if(empty($alt_lang)){
    			$alt_lang = $language;
    			$alt_content = $lang_text;
    		}
    	}
    */
    if (!$alt_lang) {
        return '';
    }
    if (!$show_available) {
        if ($q_config['show_displayed_language_prefix']) {
            return '(' . $q_config['language_name'][$alt_lang] . ') ' . $alt_content;
        } else {
            return $alt_content;
        }
    }
    //qtranxf_dbg_log('$alt_content=',$alt_content);
    // display selection for available languages
    $language_list = '';
    if (preg_match('/%LANG:([^:]*):([^%]*)%/', $q_config['not_available'][$lang], $match)) {
        $normal_separator = $match[1];
        $end_separator = $match[2];
        // build available languages string backward
        $translations = get_translations_for_domain('qtranslate');
        $english_names = qtranxf_default_windows_locale();
        //todo: load enabled only
        $i = 0;
        //foreach($available_languages as $language) {
        foreach ($available_langs as $language => $b) {
            if ($i == 1) {
                $language_list = $end_separator . $language_list;
            } elseif ($i > 1) {
                $language_list = $normal_separator . $language_list;
            }
            if (!empty($english_names[$language]) && isset($translations->entries[$english_names[$language]])) {
                $language_name = $translations->entries[$english_names[$language]]->translations[0];
            } else {
                $language_name = $q_config['language_name'][$language];
            }
            $language_list = '<a href="' . qtranxf_convertURL('', $language, false, true) . '" class="qtranxs-available-language-link qtranxs-available-language-link-' . $language . '">' . $language_name . '</a>' . $language_list;
            ++$i;
        }
    }
    //qtranxf_dbg_log('$language_list=',$language_list);
    $msg = '';
    if (!empty($q_config['show_alternative_content']) && $q_config['show_alternative_content']) {
        // show content in  alternative language
        //if(sizeof($available_languages) > 1){
        if (sizeof($available_langs) > 1) {
            if ($alt_lang_is_default) {
                //$fmt = __('For the sake of viewer convenience, the content is shown below in this site default language %s.', 'qtranslate');
                $msg = __('For the sake of viewer convenience, the content is shown below in this site default language.', 'qtranslate');
            } else {
                //$fmt = __('For the sake of viewer convenience, the content is shown below in an available alternative language %s.', 'qtranslate');
                $msg = __('For the sake of viewer convenience, the content is shown below in one of the available alternative languages.', 'qtranslate');
            }
            //$msg = sprintf($fmt, '<a href="'.qtranxf_convertURL('', $language, false, true).'">'.$q_config['language_name'][$alt_lang].'</a>');
            $msg .= ' ' . __('You may click one of the links to switch the site language to another available language.', 'qtranslate');
        } else {
            $msg = __('For the sake of viewer convenience, the content is shown below in the alternative language.', 'qtranslate');
            $msg .= ' ' . __('You may click the link to switch the active language.', 'qtranslate');
        }
        $altlanguagecontent = ' ' . $msg . '</p>' . $alt_content;
    } else {
        //by default, do not show alternative content
        $altlanguagecontent = '</p>';
    }
    $output = '<p class="qtranxs-available-languages-message qtranxs-available-languages-message-' . $lang . '">' . preg_replace('/%LANG:([^:]*):([^%]*)%/', $language_list, $q_config['not_available'][$lang]) . $altlanguagecontent;
    /* todo documentation
     */
    return apply_filters('i18n_content_translation_not_available', $output, $lang, $language_list, $alt_lang, $alt_content, $msg, $q_config);
}
예제 #4
0
/**
 * @since 3.4.6.5
*/
function qtranxf_translate_post($post, $lang)
{
    foreach (get_object_vars($post) as $key => $txt) {
        switch ($key) {
            //the quickest way to proceed
            //known to skip
            case 'ID':
                //int
            //int
            case 'post_author':
            case 'post_date':
            case 'post_date_gmt':
            case 'post_status':
            case 'comment_status':
            case 'ping_status':
            case 'post_password':
            case 'post_name':
                //slug!
            //slug!
            case 'to_ping':
            case 'pinged':
            case 'post_modified':
            case 'post_modified_gmt':
            case 'post_parent':
                //int
            //int
            case 'guid':
            case 'menu_order':
                //int
            //int
            case 'post_type':
            case 'post_mime_type':
            case 'comment_count':
            case 'filter':
                continue;
                //known to translate
            //known to translate
            case 'post_content':
                $post->{$key} = qtranxf_use_language($lang, $txt, true);
                break;
            case 'post_title':
            case 'post_excerpt':
            case 'post_content_filtered':
                $blocks = qtranxf_get_language_blocks($txt);
                if (count($blocks) > 1) {
                    //value is multilingual
                    $key_ml = $key . '_ml';
                    $post->{$key_ml} = $txt;
                    $langs = array();
                    $content = qtranxf_split_blocks($blocks, $langs);
                    $post->{$key} = qtranxf_use_content($lang, $content, $langs, false);
                    //$post->$key = qtranxf_use_block($lang, $blocks, false);
                    $key_langs = $key . '_langs';
                    $post->{$key_langs} = $langs;
                }
                break;
                //other maybe, if it is a string, most likely it never comes here
            //other maybe, if it is a string, most likely it never comes here
            default:
                $post->{$key} = qtranxf_use($lang, $txt, false);
        }
    }
}
예제 #5
0
function qtranxf_use_block($lang, $blocks, $show_available = false, $show_empty = false)
{
    global $q_config;
    //qtranxf_dbg_log('qtranxf_use_language('.$lang.') $text: ', $text);
    //qtranxf_dbg_log('qtranxf_use_language: $blocks: ', $blocks);
    $available_langs = array();
    $content = qtranxf_split_blocks($blocks, $available_langs);
    //qtranxf_dbg_log('qtranxf_use_block: $content: ',$content);
    //qtranxf_dbg_log('qtranxf_use_block: $available_langs: ',$available_langs);
    // if content is available show the content in the requested language
    if (!empty($available_langs[$lang])) {
        return $content[$lang];
    } elseif ($show_empty) {
        return '';
    }
    // content is not available in requested language (bad!!) what now?
    //remove available languages that are not enabled and sort them in the order of enabled languages
    //foreach($available_langs as $language => $b) {
    //	if(qtranxf_isEnabled($language)) continue;
    //	unset($available_langs[$language]);
    //}
    $alangs = array();
    foreach ($q_config['enabled_languages'] as $language) {
        if (empty($available_langs[$language])) {
            continue;
        }
        $alangs[] = $language;
    }
    if (empty($alangs)) {
        return '';
    }
    $available_langs = $alangs;
    // set alternative language to the first available in the order of enabled languages
    $alt_lang = current($available_langs);
    $alt_content = $content[$alt_lang];
    $alt_lang_is_default = $alt_lang == $q_config['default_language'];
    //if(empty($available_langs[$q_config['default_language']])){
    //	$alt_lang = null;
    //	$alt_content = null;
    //		$alt_lang_is_default = false;
    //	foreach($available_langs as $language) {
    //		$alt_lang = $language;
    //		$alt_content = $content[$language];
    //		break;
    //	}
    //}else{
    //	$alt_lang = $q_config['default_language'];
    //	$alt_content = $content[$alt_lang];
    //	$alt_lang_is_default = true;
    //}
    //if(!$alt_lang) return '';
    if (!$show_available) {
        if ($q_config['show_displayed_language_prefix']) {
            return '(' . $q_config['language_name'][$alt_lang] . ') ' . $alt_content;
        } else {
            return $alt_content;
        }
    }
    //qtranxf_dbg_log('$alt_content=',$alt_content);
    // display selection for available languages
    $language_list = '';
    if (preg_match('/%LANG:([^:]*):([^%]*)%/', $q_config['not_available'][$lang], $match)) {
        $normal_separator = $match[1];
        $end_separator = $match[2];
        // build available languages string backward
        $i = 0;
        foreach (array_reverse($available_langs) as $language) {
            if ($i == 1) {
                $language_list = $end_separator . $language_list;
            } elseif ($i > 1) {
                $language_list = $normal_separator . $language_list;
            }
            $language_name = qtranxf_getLanguageName($language);
            //$language_list = '&ldquo;<a href="'.qtranxf_convertURL('', $language, false, true).'" class="qtranxs-available-language-link qtranxs-available-language-link-'.$language.'">'.$language_name.'</a>&rdquo;'.$language_list;
            $language_list = '<a href="' . qtranxf_convertURL('', $language, false, true) . '" class="qtranxs-available-language-link qtranxs-available-language-link-' . $language . '" title="' . $q_config['language_name'][$language] . '">' . $language_name . '</a>' . $language_list;
            ++$i;
        }
    }
    //qtranxf_dbg_log('$language_list=',$language_list);
    $msg = '';
    if (!empty($q_config['show_alternative_content']) && $q_config['show_alternative_content']) {
        // show content in  alternative language
        if (sizeof($available_langs) > 1) {
            if ($alt_lang_is_default) {
                //$fmt = __('For the sake of viewer convenience, the content is shown below in this site default language %s.', 'qtranslate');
                $msg = __('For the sake of viewer convenience, the content is shown below in this site default language.', 'qtranslate');
            } else {
                //$fmt = __('For the sake of viewer convenience, the content is shown below in an available alternative language %s.', 'qtranslate');
                $msg = __('For the sake of viewer convenience, the content is shown below in one of the available alternative languages.', 'qtranslate');
            }
            //$msg = sprintf($fmt, '<a href="'.qtranxf_convertURL('', $language, false, true).'">'.$q_config['language_name'][$alt_lang].'</a>');
            $msg .= ' ' . __('You may click one of the links to switch the site language to another available language.', 'qtranslate');
        } else {
            $msg = __('For the sake of viewer convenience, the content is shown below in the alternative language.', 'qtranslate');
            $msg .= ' ' . __('You may click the link to switch the active language.', 'qtranslate');
        }
        $altlanguagecontent = ' ' . $msg . '</p>' . $alt_content;
    } else {
        //by default, do not show alternative content
        $altlanguagecontent = '</p>';
    }
    $output = '<p class="qtranxs-available-languages-message qtranxs-available-languages-message-' . $lang . '">' . preg_replace('/%LANG:([^:]*):([^%]*)%/', $language_list, $q_config['not_available'][$lang]) . $altlanguagecontent;
    /* todo documentation
     */
    return apply_filters('i18n_content_translation_not_available', $output, $lang, $language_list, $alt_lang, $alt_content, $msg, $q_config);
}
예제 #6
0
function qtranxf_use_block($lang, $blocks, $show_available = false, $show_empty = false)
{
    global $q_config;
    $content = qtranxf_split_blocks($blocks);
    // if content is available show the content in the requested language
    if (!empty($content[$lang])) {
        return $content[$lang];
    } elseif ($show_empty) {
        return '';
    }
    // content is not available in requested language (bad!!) what now?
    // find available and alternative languages
    if (empty($content[$q_config['default_language']])) {
        $alt_lang = null;
        $alt_content = null;
        $alt_lang_is_default = false;
    } else {
        $alt_lang = $q_config['default_language'];
        $alt_content = $content[$alt_lang];
        $alt_lang_is_default = true;
    }
    $available_languages = array();
    foreach ($content as $language => $lang_text) {
        if (empty($lang_text)) {
            continue;
        }
        if (!qtranxf_isEnabled($language)) {
            continue;
        }
        $available_languages[] = $language;
        if (empty($alt_lang)) {
            $alt_lang = $language;
            $alt_content = $lang_text;
        }
    }
    if (!$alt_lang) {
        return '';
    }
    if (!$show_available) {
        if ($q_config['show_displayed_language_prefix']) {
            return '(' . $q_config['language_name'][$alt_lang] . ') ' . $alt_content;
        } else {
            return $alt_content;
        }
        /*
        	// check if content is available in default language, if not return first language found. (prevent empty result)
        	$language = $q_config['default_language'];
        	if(!isset($available_languages[$language])){
        		
        	}
        	if($lang!=$q_config['default_language']){
        		$language = $q_config['default_language'];
        		$lang_text = $content[$language];
        		//$lang_text = trim($lang_text);
        		if(!empty($lang_text)){
        			if ($q_config['show_displayed_language_prefix'])
        				return '('.$q_config['language_name'][$language].') '.$lang_text;
        			else
        				return $lang_text;
        		}
        	}
        	foreach($content as $language => $lang_text) {
        		$lang_text = trim($lang_text);
        		if(empty($lang_text)) continue;
        		if ($q_config['show_displayed_language_prefix'])
        			return '('.$q_config['language_name'][$language].') '.$lang_text;
        		else
        			return $lang_text;
        	}
        */
    }
    // display selection for available languages
    //$available_languages = array_unique($available_languages);
    $language_list = '';
    if (preg_match('/%LANG:([^:]*):([^%]*)%/', $q_config['not_available'][$lang], $match)) {
        $normal_separator = $match[1];
        $end_separator = $match[2];
        // build available languages string backward
        $i = 0;
        foreach ($available_languages as $language) {
            if ($i == 1) {
                $language_list = $end_separator . $language_list;
            }
            if ($i > 1) {
                $language_list = $normal_separator . $language_list;
            }
            $language_list = '<a href="' . qtranxf_convertURL('', $language, false, true) . '">' . $q_config['language_name'][$language] . '</a>' . $language_list;
            ++$i;
        }
    }
    //qtranxf_dbg_echo('$language_list=',$language_list,true);
    //if(isset($post)){
    //	//qtranxf_dbg_echo('$post='.$post);
    //}
    if (!empty($q_config['show_alternative_content']) && $q_config['show_alternative_content']) {
        // show content in  alternative language
        if (sizeof($available_languages) > 1) {
            if ($alt_lang_is_default) {
                //$fmt = __('For the sake of viewer convenience, the content is shown below in this site default language %s.', 'qtranslate');
                $msg = __('For the sake of viewer convenience, the content is shown below in this site default language.', 'qtranslate');
            } else {
                //$fmt = __('For the sake of viewer convenience, the content is shown below in an available alternative language %s.', 'qtranslate');
                $msg = __('For the sake of viewer convenience, the content is shown below in one of the available alternative languages.', 'qtranslate');
            }
            //$msg = sprintf($fmt, '<a href="'.qtranxf_convertURL('', $language, false, true).'">'.$q_config['language_name'][$alt_lang].'</a>');
            $msg .= ' ' . __('You may click one of the links to switch the site language to another available language.', 'qtranslate');
        } else {
            $msg = __('For the sake of viewer convenience, the content is shown below in the alternative language.', 'qtranslate');
            $msg .= ' ' . __('You may click the link to switch the active language.', 'qtranslate');
        }
        $altlanguagecontent = ' ' . $msg . '</p>' . $alt_content;
    } else {
        //by default, do not show alternative content
        $altlanguagecontent = '</p>';
    }
    return '<p>' . preg_replace('/%LANG:([^:]*):([^%]*)%/', $language_list, $q_config['not_available'][$lang]) . $altlanguagecontent;
}
예제 #7
0
function qtranxf_use_block($lang, $blocks, $show_available = false, $show_empty = false)
{
    global $q_config;
    //qtranxf_dbg_log('qtranxf_use_language('.$lang.') $text: ', $text);
    //qtranxf_dbg_log('qtranxf_use_language: $blocks: ', $blocks);
    $available_langs = array();
    $content = qtranxf_split_blocks($blocks, $available_langs);
    //qtranxf_dbg_log('qtranxf_use_block: $content: ',$content);
    //qtranxf_dbg_log('qtranxf_use_block: $available_langs: ',$available_langs);
    // if content is available show the content in the requested language
    if (!empty($available_langs[$lang])) {
        return $content[$lang];
    } elseif ($show_empty) {
        return '';
    }
    // content is not available in requested language (bad!!) what now?
    //remove available languages that are not enabled
    foreach ($available_langs as $language => $b) {
        if (qtranxf_isEnabled($language)) {
            continue;
        }
        unset($available_langs[$language]);
    }
    // set alternative language
    if (empty($available_langs[$q_config['default_language']])) {
        $alt_lang = null;
        $alt_content = null;
        $alt_lang_is_default = false;
        foreach ($available_langs as $language => $b) {
            $alt_lang = $language;
            $alt_content = $content[$language];
            break;
        }
    } else {
        $alt_lang = $q_config['default_language'];
        $alt_content = $content[$alt_lang];
        $alt_lang_is_default = true;
    }
    if (!$alt_lang) {
        return '';
    }
    if (!$show_available) {
        if ($q_config['show_displayed_language_prefix']) {
            return '(' . $q_config['language_name'][$alt_lang] . ') ' . $alt_content;
        } else {
            return $alt_content;
        }
    }
    //qtranxf_dbg_log('$alt_content=',$alt_content);
    // display selection for available languages
    $language_list = '';
    if (preg_match('/%LANG:([^:]*):([^%]*)%/', $q_config['not_available'][$lang], $match)) {
        $normal_separator = $match[1];
        $end_separator = $match[2];
        if (!is_textdomain_loaded('language-names')) {
            //is not loaded by default, since this place should not be hit frequently
            $locale = $q_config['locale'][$q_config['language']];
            load_textdomain('language-names', QTRANSLATE_DIR . '/lang/language-names/language-' . $locale . '.mo');
        }
        $translations = get_translations_for_domain('language-names');
        // build available languages string backward
        $i = 0;
        foreach ($available_langs as $language => $b) {
            if ($i == 1) {
                $language_list = $end_separator . $language_list;
            } elseif ($i > 1) {
                $language_list = $normal_separator . $language_list;
            }
            $locale = $q_config['locale'][$language];
            while (!isset($translations->entries[$locale])) {
                if ($locale[2] == '_') {
                    $locale = substr($locale, 0, 2);
                    if (isset($translations->entries[$locale])) {
                        break;
                    }
                }
                $locale = null;
                break;
            }
            if ($locale) {
                $language_name = $translations->entries[$locale]->translations[0];
                $language_name = mb_convert_case($language_name, MB_CASE_TITLE);
            } else {
                $language_name = $q_config['language_name'][$language];
            }
            $language_list = '&ldquo;<a href="' . qtranxf_convertURL('', $language, false, true) . '" class="qtranxs-available-language-link qtranxs-available-language-link-' . $language . '">' . $language_name . '</a>&rdquo;' . $language_list;
            ++$i;
        }
    }
    //qtranxf_dbg_log('$language_list=',$language_list);
    $msg = '';
    if (!empty($q_config['show_alternative_content']) && $q_config['show_alternative_content']) {
        // show content in  alternative language
        if (sizeof($available_langs) > 1) {
            if ($alt_lang_is_default) {
                //$fmt = __('For the sake of viewer convenience, the content is shown below in this site default language %s.', 'qtranslate');
                $msg = __('For the sake of viewer convenience, the content is shown below in this site default language.', 'qtranslate');
            } else {
                //$fmt = __('For the sake of viewer convenience, the content is shown below in an available alternative language %s.', 'qtranslate');
                $msg = __('For the sake of viewer convenience, the content is shown below in one of the available alternative languages.', 'qtranslate');
            }
            //$msg = sprintf($fmt, '<a href="'.qtranxf_convertURL('', $language, false, true).'">'.$q_config['language_name'][$alt_lang].'</a>');
            $msg .= ' ' . __('You may click one of the links to switch the site language to another available language.', 'qtranslate');
        } else {
            $msg = __('For the sake of viewer convenience, the content is shown below in the alternative language.', 'qtranslate');
            $msg .= ' ' . __('You may click the link to switch the active language.', 'qtranslate');
        }
        $altlanguagecontent = ' ' . $msg . '</p>' . $alt_content;
    } else {
        //by default, do not show alternative content
        $altlanguagecontent = '</p>';
    }
    $output = '<p class="qtranxs-available-languages-message qtranxs-available-languages-message-' . $lang . '">' . preg_replace('/%LANG:([^:]*):([^%]*)%/', $language_list, $q_config['not_available'][$lang]) . $altlanguagecontent;
    /* todo documentation
     */
    return apply_filters('i18n_content_translation_not_available', $output, $lang, $language_list, $alt_lang, $alt_content, $msg, $q_config);
}