qtranslate conditional tags

Having Problems? Need Help? Post here!

qtranslate conditional tags

Postby maxk » Sat Aug 15, 2009 4:24 am

Would like to check for the language through the widget logic plugin.
Something like is_language(en). what's the conditional tag to use there? in gengo it was is_language what is it in qtranslate?
maxk
 
Posts: 8
Joined: Sat Aug 15, 2009 4:19 am

Re: qtranslate conditional tags

Postby jimdaly » Thu Sep 24, 2009 6:09 am

You can use get_bloginfo('language')=='xy-XY' where xy-XY is the language code

For example, get_bloginfo('language')=='pl-PL' will return TRUE for pages in Polish

Note: get_bloginfo() is a function in the WordPress core. It is not part of either qTranslate or Widget Logic
jimdaly
 
Posts: 1
Joined: Thu Sep 24, 2009 6:00 am

Re: qtranslate conditional tags

Postby nicksoper » Tue Oct 06, 2009 1:01 pm

Say you were doing a website in German, English and French, and your default language was set to German, you could use this kind of if statement.

<?php if (qtrans_getLanguage() == 'en') {echo 'en';}elseif (qtrans_getLanguage() == 'fr') {echo 'fr';}else {echo 'de';} ?>
nicksoper
 
Posts: 5
Joined: Tue Oct 06, 2009 12:56 pm

Re: qtranslate conditional tags

Postby moonoo » Thu Jun 24, 2010 12:58 pm

Is there a way to echo urls to the opposite language for a 2 language setup?

i.e

Code: Select all
<?php if (qtrans_getLanguage() == 'en') {echo 'current page?lang=cy';}elseif (qtrans_getLanguage() == 'cy') {echo 'current_page?lang=en';} ?>


So that I get a link to switch rather than just text?

Or even this maybe :
Code: Select all
<?php if (qtrans_getLanguage() == 'en') {echo '<a href="' . '<?php bloginfo('url'); ?>' . '/?lang=cy" title="Cymraeg">Cymraeg</a>';}elseif (qtrans_getLanguage() == 'cy') {echo '<a href="' . ' <?php bloginfo('url'); ?>' . '/?lang=en" title="English">English</a>';} ?>
moonoo
 
Posts: 9
Joined: Wed May 19, 2010 2:57 pm

Re: qtranslate conditional tags

Postby amoss » Mon Jun 28, 2010 12:42 pm

Hopefully someone can help me along the same lines as this thread...

I have a two language site - en and fr - and need to hardcode some links into the template we are using.

Site is at www.clubexcellence.ocm

The current code looks like this:

<h2 class="feat-title"><?php echo stripslashes($wp_launch_cat_box_1_title); ?> <span class="moreposts">(<a href="http://www.clubexcellence.com/<?php if ( get_option('category_base') ) { ?><?php echo get_option('category_base'); ?><?php } else { ?>category<?php } ?>/<?php echo $wp_launch_cat_box_1; ?>/"><?php _e("more"); ?></a>)</span></h2>

I need to code that looks at the chosen language and then shows the correct link (en="more" fr="plus") AND directs the link to the appropriate URL - ie. if language is en then link goes to www.clubexcellence.com/category/blog/?lang=en and if the language is french then the link goes to www.clubexcellence.com/category/blog/?lang=fr

Help would be most appreciated!

Andrew
amoss
 
Posts: 1
Joined: Mon Jun 28, 2010 12:35 pm

Re: qtranslate conditional tags

Postby SWD » Fri Jul 09, 2010 4:38 am

Hi Andrew,

I am setting up an English/French site too. I see you have your site working as per your request. How did you get correct urls depending on language of page?

Thank you.
SWD
 
Posts: 4
Joined: Wed Jul 07, 2010 6:08 pm

Re: qtranslate conditional tags

Postby Person » Fri Jul 09, 2010 2:32 pm

If you're hardcoding the link in the template, you can add something along these lines (note: this method is better for external links):
Code: Select all
<?php
   if(qtrans_getLanguage() == "en")
      echo ('<a href="http://www.englishwebsite.com">TITLE</a>');
   else if(qtrans_getLanguage() == "fr")
      echo ('<a href="http://www.sitewebfrancais.com">TITRE</a>');
?>


An alternative way is to take the tag approach:
Code: Select all
<?php
   _e('<!--:en--><a href="http://www.englishwebsite.com">TITLE</a><!--:--><!--:fr--><a href="http://www.sitewebfrancais.com">TITRE</a><!--:-->');
?>


If you're trying to link to a specific page in your own website, you can use qTranslate's convert url function:
Code: Select all
<?php echo '<a href="' . qtrans_convertURL('http://mywebsite.com/post') . '">TITLE</a>'; ?>


If you just want to link your home page, you could do this:
Code: Select all
<?php echo '<a href="' . qtrans_convertURL(get_option('home')) . '">' . __('Home') . '</a>'; ?>


If you're trying to get the links to the other languages of the current page, I strongly recommend that you use the qTranslate widget, and customize it using the appropriate css. Or by using the select code function and customize it using css.
Code: Select all
<?php qtrans_generateLanguageSelectCode('dropdown'); ?>

Note: you can replace 'dropdown' with 'image', 'text', or 'both'
Person
 
Posts: 165
Joined: Tue Jul 21, 2009 6:25 pm

Re: qtranslate conditional tags

Postby moonoo » Sun Jul 11, 2010 10:52 pm

Which of the above solutions would work in this scenario then?
Code: Select all
<?php

// lot of code before hand

if(!empty($row["link"])) {
            $linkP = '
               <div class="discogPanel">
                  <h3><a href="'.$row["link"].'" target="_blank">Website</a></h3>
               </div>
            ';
         }
// Quite a bit of code after this text



I wan to make the word Website Bi-lingual..
moonoo
 
Posts: 9
Joined: Wed May 19, 2010 2:57 pm

Re: qtranslate conditional tags

Postby moonoo » Sun Jul 11, 2010 11:12 pm

Figured it out!

cheers

Code: Select all
if(!empty($row["link"])) {
                                $linkP = (__('<!--:en-->Website<!--:--><!--:cy-->Wefan<!--:-->'));
            $linkP = '
               <div class="discogPanel">
                  <h3><a href="'.$row["link"].'" target="_blank">'.$linkP.'</a></h3>
               </div>
            ';
         }
moonoo
 
Posts: 9
Joined: Wed May 19, 2010 2:57 pm


Return to qTranslate Support Forum

Who is online

Users browsing this forum: No registered users and 7 guests