Please enter a search term to begin your search.

Translator Plugin Pro Developer Guide

Translator Plugin Pro provides an extensive Open API to customize all aspects of the display, target or exclude content specifically from original or translated pages and more.

Content Display

Translator Plugin Pro allows you to create blocks of content which are visible only on translated pages. For example you may want to notify your readers that the translated versions of the page are machine generated and hence may not be equivalent to human translation. Now you can easily do so with the custom tags / api provided.

Translator Plugin Pro also allows you to create / specify blocks of content which are available only in the original language. For example you may want to make your comment section available only in the English version of the blog. Now you can easily do it with a simple tag / api as explained below.

How to display content only on translated pages

You can use the tags / code shown below to display content which is visible only in translated pages.

<?php if(function_exists('tgInTranslatedPage') && (tgInTranslatedPage())) { ?>
    The HTML Content here will only be visible on translated pages.
<?php } ?>

How to exclude content from translated pages

To exclude content from translated pages use the tags as shown below:

<?php if(function_exists('tgInTranslatedPage') && (!tgInTranslatedPage())) { ?>
    The HTML Content here will not be visible in translated pages.
<?php } ?>

Note: For php developers, the function tgInTranslatedPage() returns true only in translated pages.

How to skip translating certain content

You can use the skip-translation tags as shown below to skip translating certain content from translated pages.

<!--skip translation-->
Content you do not want to translate
<!--end skip translation-->

Translator Bar Display

Translator Plugin Pro provides four display format to display the hyperlinked flag icons which are used to translate a page. For example the flags in Simple Thoughts blog are displayed with CSS styling on None format. However we have also opened up the functionality with the API to allow you to fully customize the flags, associated hyperlinks, text messages… in short everything. You may not even display the flags, just provide hyperlinked text for each language.

tgGetAvailableLanguages()

tgGetAvailableLanguages returns an array containing all the available languages. The available languages is limited by the languages supported in your license (pro or gold) for your base language (language the blog is written in). Currently 14 languages are available for English (base language) in the Pro version and 33 languages are available, for English, in the Gold version. The languages are represented by short codes like ‘de’ or ‘es’. This is not necessarily the number of visible languages or languages which are currently enabled for translation. Refer to tgGetVisibleLanguages() to get an array of all visible languages. The other functions, which requires a language parameter, depends on this function to validate their argument against the set of available languages.

tgGetVisibleLanguages()

tgGetVisibleLanguages returns an array containing all the languages which are currently enabled for translation on your blog. This is a subset of tgGetAvailableLanguages(). You can limit the number of languages you want to provide translation by unchecking all the languages you want to exclude in Translator Plugin Pro engine configuration located in Advanced->Language & Engine Configuration section. tgGetVisibleLanguages() returns the languages which are used internally to display the translator flags in the display formats we provide. You should use this with functions like tgGetFlagImage(), tgGetTooltip(), tgGetTranslatedPageURL().

tgGetFlagImage($language)

This returns the flag image url for any available language. The available language *must* be one of the languages returned by tgGetAvailableLanguages().

For example tgGetFlagImage('de') will return the url for German flag. To echo it you can use:

<?php if(function_exists('tgGetFlagImage')) echo tgGetFlagImage('de'); ?>

tgGetTranslatedPageURL($language)

This identifies the current page and returns the url for translated version of the page. This function is not associated in any way with “the WordPress loop”. You can place it anywhere within the page like sidebar or header or footer etc.

The specified language *must* be one of the languages returned by tgGetAvailableLanguages().

For example tgGetTranslatedPageURL('de') will return the url for German version of the current page. To echo it you can use:

<?php if(function_exists('tgGetTranslatedPageURL')) echo tgGetTranslatedPageURL('de'); ?>

tgGetBaseLanguage()

This returns the code for the base language the blog is written in. For example for an english blog the base language returned will be en.

The following code will echo the base language of your blog:

<?php if(function_exists('tgGetBaseLanguage')) echo tgGetBaseLanguage(); } ?>

tgGetTooltip($language)

This returns the tooltip text for any available language. The tooltip text contains the translated version of “Translate to $language” along with an English text of the language. This is used to create the tooltip over the flags in display.

The available language *must* be one of the languages returned by tgGetAvailableLanguages().

Let’s wrap it up with an example. The following code will display a translator bar with all the available languages in free format. This is a simplified version of the None display format without the CSS adornments.

<?php 
if(function_exists('tgGetVisibleLanguages')) { // This ensures that the Translator Plugin Pro is active.
    $visibleLanguages = tgGetVisibleLanguages();
    foreach($visibleLanguages as $language) {
        echo "<a href='" . tgGetTranslatedPageURL($language) . "' title='" . tgGetTooltip($language) . "'><img style='border:0;' src='" . tgGetFlagImage($language). "' alt='" . tgGetTooltip($language) . "' /></a>";
    }
}
?>