Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

qTranslate-X show available languages for posts on page WordPress

  • SOLVED

Hello
I use qTranslate-X plugin and I need languages availability to be displayed on the Blog page for each post. I have 4 languages (german, czech, english, french), so when i have english post with german translation, I need to show that there is no translation in czech and french, and that english and german are ok.

Answers (2)

2017-01-25

Found answers:

// get the post id
$post = get_post();
$post_id = $post -> ID;

// check if en is available and the current language not english
if(!qtranxf_isAvailableIn($post_id, 'en') && qtranxf_getLanguage() != 'en'){ // no En content
echo 'no english';
}

// check if the french is available and the current language not french
if(!qtranxf_isAvailableIn($post_id, 'fr') && qtranxf_getLanguage() != 'fr'){ // no FR content
echo 'no french';
}

// check if the czech is available and the current language not czech
if(!qtranxf_isAvailableIn($post_id, 'cz') && qtranxf_getLanguage() != 'cz'){ // no cz content
echo 'no czech';
}

// check if the german is available and the current language not german
if(!qtranxf_isAvailableIn($post_id, 'de') && qtranxf_getLanguage() != 'de'){ // no Ger content
echo 'no german';
}

2017-01-24

mod mi answers:

<?php
$enabled_languages = get_option('qtranslate_enabled_languages');
$language_names = get_option('qtranslate_language_names');

foreach ($enabled_languages as $enable_language) {
foreach ($language_names as $lang_code => $lang_name) {
if ($enable_language != qtrans_getLanguage()) {

$result = qtrans_use($lang_code, $post->post_content,false);

if ($result) {
echo '<a href="' . qtrans_convertURL(get_permalink(), $lang_code) . '">' . $lang_name . '</a>';
} else {
echo ‘Content not available in ’.$lang_name;
}
}
}
}
?>


Found comments:

Hello
For example I select czech language for the site and I see only posts that have czech translation on the blog page. I have post with czech and english translation, czech and german translation, english and german translation etc.
Each post have title and content, and I need only text message at the bottom of each post that this post also available on german, and unavailable on english and french. And Czech language in the example doesn't show because I select czech language. If i select german language so I need to display that post available in czech and unavailable on english and french.
Thank you


mod mi comments:

Ok Please try this:

<?php
$enabled_languages = get_option('qtranslate_enabled_languages');
$language_names = get_option('qtranslate_language_names');

foreach ($enabled_languages as $enable_language) {
foreach ($language_names as $lang_code => $lang_name) {
if ($enable_language == $lang_code && $enable_language != qtrans_getLanguage()) {
$query = "SELECT id FROM $wpdb->posts WHERE ID = $post->ID AND $wpdb->posts.post_content LIKE '%<!--:" . $lang_code . "-->%'";
$result = $wpdb->get_results($query);

if ($result) {
global $qtranslate_slug;
echo '<a href="' . qtrans_convertURL(get_permalink(), $lang_code) . '">' . $lang_name . '</a>';
} else {
echo ‘Content not available in ’.$lang_name;
}
}
}
}
?>


Found comments:

you've found this on http://stackoverflow.com/questions/23101446/wordpress-qtranslate-to-show-only-available-languages
I see this code but it doesn't work...


mod mi comments:

Yes, didn't manage to improve my answer before your comment. Please try with the new code and let me know what errors you get if any this time.


Found comments:

Nope, doesn't work
I have this error:

Uncaught TypeError: jQuery(...).pageslide is not a function
at functions.js:647
at dispatch (jquery.js?ver=1.12.4:3)
at r.handle (jquery.js?ver=1.12.4:3)
(anonymous) @ functions.js:647
dispatch @ jquery.js?ver=1.12.4:3
r.handle @ jquery.js?ver=1.12.4:3

and the i have only header on the page


mod mi comments:

Hi, many thanks for your feedback.
Those are all jquery related errors. Probably a js script is not loading.
What do you mean you only have header on the page? No get_footer(), no wp loop? Which wp template are you on?


Found comments:

I have custom theme.
That mean that I see only header of the site after I add your code.
Can we test your code somewhere on your test wordpress?


Found comments:

maybe it will helps you
I have in admin panel new column Languages where I can see available languages
Here is function that I think do this (I took it from admin php)

function qtranxf_languageColumn($column) {
global $q_config, $post;
if ($column == 'language') {
$missing_languages = null;
$available_languages = qtranxf_getAvailableLanguages($post->post_content);
if($available_languages === FALSE){
echo _x('Languages are not set', 'Appears in the column "Languages" on post listing pages, when content has no language tags yet.', 'qtranslate');
}else{
$missing_languages = array_diff($q_config['enabled_languages'], $available_languages);
$available_languages_name = array();
$language_names = null;
foreach($available_languages as $language) {
if(isset($q_config['language_name'][$language])){
$language_name = $q_config['language_name'][$language];
}else{
if(!$language_names) $language_names = qtranxf_default_language_name();
$language_name = isset($language_names[$language]) ? $language_names[$language] : __('Unknown Language', 'qtranslate');
$language_name .= ' ('.__('Not enabled', 'qtranslate').')';
}
$available_languages_name[] = $language_name;
}
$available_languages_names = join(', ', $available_languages_name);
echo apply_filters('qtranslate_available_languages_names',$available_languages_names);
}
do_action('qtranslate_languageColumn', $available_languages, $missing_languages);
}
return $column;


Found comments:

Screenshot


mod mi comments:

From the code I understand that you have qtranslatex plugin not the old qtranslate? Right? I will try to check everything out later because I'm away from office now. Thanks


Found comments:

yes, qTranslate-X, sorry - my mistake
Thank you


Found comments:

any reply?


mod mi comments:

Possible to send me login info to test?