Filepath: phork/php/core/CoreLanguage.class.php and phork/php/app/AppLanguage.class.php

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.


Language translations can be cached so they don't need to be parsed from files for each page load. The location of the language file cache can be defined in global.config.php. Cache files should be in array format with the array key being the string to translate and the value being the translation.

$arrConfig['LangCache'] = AppConfig::get('FilesDir') . 'app/lang';

Example Translation

//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);

Example Initialization (from the bootstrap)

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->setCachePath(AppConfig::get('LangCache', false));

Example *.lang File

default: Permission denied
replace: Permission denied, dude

default: Error: %s in %s on line %d
replace: Error: %s in %s on line %d, dude

Example Cache File

return array(
    'Permission denied' => 'Permission denied, dude',
    'Error: %s in %s on line %d' => 'Error: %s in %s on line %d, dude'