... Elxis version 2009.3 codename Aphrodite is out, download it from Elxis Download Center (EDC) ...

Automatic translation

From Elxis Official Documentation

Jump to: navigation, search
Translations Translations: 

English  • Ελληνικά

Elxis allows you to automatic translate any text from one language to an other. This system is based on Google's online translation service. The Elxis translation API usage is extremely simple and you can use it in your own extensions for Elxis CMS. On Elxis 2009.2 this system was updated and more languages were added to it (91 languages are supported). Elxis uses this system to translate content items and autonomous pages.


The API in the form that is presented here is available on Elxis 2009.2 or newer and requires PHP 5.2 or newer.


Translation API guide

Let's say you want to translate a text (plain or html text, does nt matter, the original html format is being preserved to the translated text) from english to spanish.

Include the elxis translation class and initialize the object:

require_once($mainframe->getCfg('absolute_path').'/administrator/includes/translator.class.php');
$metafrasi = new translator();
metafrasi means translation in Greek. Off course you can name your translator instance what ever you like.

The language identifier for English is en and for Spanish es. To translate the $text from English to Spanish all you have to do is:

$spanish_text = $metafrasi->translate($text, 'en', 'es');

That's it, PHP for dummies!!

If the translation, for any reason, fails the translated text will be false (boolean) and an error message will be available.

if ($spanish_text === false) {
    echo $metafrasi->geterror();
}

If you dont know the Google's language identifiers (uses the ISO standard names) you can use the API to convert the Elxis language names to Google compatibles.

$metafrasi->elxisToGoogle('greek');
//the above will return: el

So you can also use the translate method as following:

$spanish_text = $metafrasi->translate(
$text, 
$metafrasi->elxisToGoogle('english'), 
$metafrasi->elxisToGoogle('spanish')
);

The result will be the same.

You can also convert a Google language identifier to an Elxis compatible one.

$metafrasi->googleToElxis('fr');
//the above will return: french

An implementation of the Elxis translation API you will find at the Translate bot.

Personal tools