The CoreLanguage class is used to translate alerts and messages into different languages. The language to use is defined in the global configuration as $arrConfig['Language'] and set up in the bootstrap. If no language is defined (which is the default) then nothing is translated.
The global translation files are in phork/lang/[language]/, however each site can also have their own translation files in phork/sites/[sitetype]/lang/[language]/. Site-specific translations override global translations.
Any file in the language directories named with a .lang extension will be loaded into the translator. The core Phork translations are in phork/lang/[language]/phork.lang which shouldn't be edited. Currently the only translation is English which can be used as a template for other language replacements.
It's possible to reset the language at any point of the application by re-calling the setLanguage() method. Any translations done before resetting the language won't be changed to the new language.
The language class is a singleton meaning there can only be one instance of it at a time.
//standard translation
$strTranslation = AppLanguage::translate('Permission denied');
//translation with variables
$strTranslation = AppLanguage::translate('Error: %s in %s on line %d', 'Permission denied', 'foo.php', 42);
if ($strLanguage = AppConfig::get('Language', false)) {
$arrFilePaths = array();
if ($strInstallDir = AppConfig::get('InstallDir')) {
$arrFilePaths[] = "{$strInstallDir}/lang/";
}
if ($strLangDir = AppConfig::get('LangDir')) {
$arrFilePaths[] = $strLangDir;
}
$objLanguage = AppLanguage::getInstance();
$objLanguage->setFilePath($arrFilePaths);
$objLanguage->setLanguage($strLanguage);
}
default: Permission denied
replace: Permission denied
default: Error: %s in %s on line %d
replace: Error: %s in %s on line %d