Include the Class
First, you have to include the class :
include("XatTranslation.class.php");
Instance the Class
To instance the class, use :
$source = "en"; // English
$target = "fr"; // French
$tr = new XatTranslation($source,$target);
You can use also :
$source = XatTranslation::ENGLISH; // English
$target = XatTranslation::FRENCH; // French
$tr = new XatTranslation($source,$target);
But this way limit the possibilities because most of the languages aren't usable with this way.
Translate the Sentences
Then, you have to write the translations, you have to do that before the strings displaying
$tr->set("Hello","Bonjour"); // Insert the translation of "Hello"
You can also write (PHP 5.3 min) :
$tr("Hello","Bonjour"); // Insert the translation of "Hello"
Display the Sentences
Now you have translated the sentences, you have to display them like that :
echo $tr->tr("Hello");
This will display the translation if the language go with the user language, else, it will be the untranslated string which will be displayed.
Know what is the used Language
To know the used lanugage by XatTranslation on your website, use this :
echo $tr->getLang();
Scan your Translations
You can scan your translations to search if you made some mistakes (punctuation) :
$tr->scan();
List your Translations
You can list all of your translations with : (the first argument is the name of the object, here "tr"
$tr->listTranslations('tr');
You can show the results with the "short" method by adding this (PHP 5.3 min) :
$tr->listTranslations('tr',true);
List untranslated Strings
You can miss some strings to translate, with this, you'll be able to list every untranslated strings :
$tr->listUntranslated('tr');
You can show the results with the "short" method by adding this (PHP 5.3 min) :
$tr->listUntranslated('tr',true);
Force a Language
Some browsers aren't compatible with the auto-detection feature, you can force a language so.
$tr->forceLang('fr');
Insert this before any string displaying.