Aiki languages
From Aikiframework wiki
|
Before
read please this Language Support to understand basic concept of aiki translation.
Abstract
In Aiki language translation depends of two libraries: libs/site, and libs/dictionary.php.
Libs/site determines in which language aiki must translated output using the URL and determines if translation is necessary.
Libs/dictionary, add a store of abstract dictionaries to aiki object. Think in a site developed in Spanish that need be translated to French. We need almost two dictionaries: to translate aiki core from English to French, and other to translate widgets from Spanish to French.
Aiki have a static core, but you can add and remove, plugins, apps, and extension. How translate all this and where will be stored terms. Don't worry. Every extension, plugin or apps can have their own dictionaries.
A developer can add his own dictionaries with:
// when plugin is initialized
$aiki->dictionary->add("myPlugins", $dictionaryObject);
// in plugin
t("Hello","myPlugins");// see short.
dictionary Object
A dictionary Object is a object that have almost three methods:
- translateTo, get target language: all terms will be translated to this language.
- translateFrom, get original language of dictionary
- translate, the function who translate.
How works the object or where are terms stored is irrelevant for libs/dictionary. It believes in each dictionaries.
In aiki source directory libs/classes you can find two implementations of dictionaries, using arrays and a table, respectively.
Shortcut
Good thing have short names. There are some shortcut to translate a term in aiki:
// for use in aiki core It assumes english as original language and 'core' as domain'
__( term_to_translate )
__sprintf ( string, arg1, arg2,...) // sprintf translated
Examples;
__("Hello world");
__("Your name is %s. Welcome!", $name);
// for use in plugin, extension or apps
$aiki->dictionary->add("MyPluginName", $dictionary );
..
__("Hello, i'm a plugin","MyPluginName");
Aiki Core
Aiki core dictionary is load in bootstrap.php with this lines:
if ( $aiki->site->language() != "en" ) {
include_once ("$AIKI_ROOT_DIR/libs/classes/dictionaryTableClass.php");
$aiki->dictionary->add("core", new dictionaryTable($aiki->site->language()));
}
Note: Domain is "core". Dictionary object is a table (aiki_dictionaries) where terms will be stored.

