Features
With this translation class you can translate string from one language to an other. The advantage of this script is that it uses a cache to store already translated strings.
Supported language
- automatic (auto)
- albanian (sq)
- arabic (ar)
- bulgarian (bg)
- catalan (ca)
- chinese (zh-CN)
- croatian (hr)
- czech (cs)
- danish (da)
- dutch (nl)
- english (en)
- estonian (et)
- filipino (tl)
- finnish (fi)
- french (fr)
- galician (gl)
- german (de)
- greek (el)
- hebrew (iw)
- hindi (hi)
- hungarian (hu)
- indonesian (id)
- italian (it)
- japanese (ja)
- korean (ko)
- latvian (lv)
- lithuanian lt()
- maltese (mt)
- norwegian (no)
- persian alpha (fa)
- polish (pl)
- portuguese (pt)
- romanian (ro)
- russian (ru)
- serbian (sr)
- slovak (sk)
- slovenian (sl)
- spanish (es)
- swedish (sv)
- thai (th)
- turkish (tr)
- ukrainian (uk)
- vietnamese (vi)
Auto: With the auto translation the translator will detect for you wich language the source is.
Use
1. Include
The first thing you need to do is including the class in your script. If the class file(translator.php) is in the same directory as your current script you can use the following line of code. The next thing you need to do is create an instance of the class. The parameter you add is the directory where the cache file can be saved.
include("translator.php");
$Translator = new Translator("C:/cache/");
For example if you want the cache directory in the same directory where your script is located you can use this line of code:
$Translator = new Translator(dirname(__FILE__) . "/cache/");
If you don't want to use caching you can leave the constructor parameter empty. The code will look like this:
$Translator = new Translator();
2. Translate a string
To translate a string you can use the Translate method. This method takes 3 parameters. The first one is de from language. The second is de to language and the third is the string you want to translate.
Example: we want to translate the string "This is a test" from english to dutch we use the following line of code:
echo $Translator->Translate("en","nl", "This is een test);
The output of this script will be "Dit is een test".
3. Complete example script
This is the complete script we made in the previous two steps.
With caching
include("translator.php");
$Translator = new Translator(dirname(__FILE__) . "/cache/");
echo $Translator->Translate("en","nl", "This is a test);
Without caching
include("translator.php");
$Translator = new Translator();
echo $Translator->Translate("en","nl", "This is a test);