Example #1
0
 function test_locale_setting_getting_deleting_methods()
 {
     !defined('AK_TEST_TRANSLATIONS')?define('AK_TEST_TRANSLATIONS',true):null;
     $translation_key=Ak::randomString(8);
     $namespace = Ak::randomString(8);
     $translation=Ak::t($translation_key,null,$namespace);
     $this->assertEqual($translation_key,$translation);
     AkLocaleManager::updateLocaleFiles();
     $dictionary = AkLocaleManager::getDictionary(AK_FRAMEWORK_LANGUAGE,$namespace);
     $this->assertEqual(array($translation_key=>$translation_key),$dictionary);
     
     $dictionary[$translation_key] = 'Spanish';
     AkLocaleManager::setDictionary($dictionary,'es',$namespace);
     $dictionary = AkLocaleManager::getDictionary('es',$namespace);
     $this->assertEqual(array($translation_key=>'Spanish'),$dictionary);
     
     Ak::t('dummy',null,$namespace);
     AkLocaleManager::updateLocaleFiles();
     $dictionary = AkLocaleManager::getDictionary(AK_FRAMEWORK_LANGUAGE,$namespace);
     $this->assertEqual(array($translation_key=>$translation_key,'dummy'=>'dummy'),$dictionary);
     
     $this->assertTrue(AkLocaleManager::deleteDictionary(AK_FRAMEWORK_LANGUAGE,$namespace));
     $this->assertEqual(array(),AkLocaleManager::getDictionary(AK_FRAMEWORK_LANGUAGE,$namespace));
     
 }
Example #2
0
 /**
  * @todo Refactor this method
  */
 static function updateLocaleFiles()
 {
     if (defined('AK_LOCALE_MANAGER') && class_exists(AK_LOCALE_MANAGER) && in_array('AkLocaleManager', class_parents(AK_LOCALE_MANAGER))) {
         return;
     }
     $paths = array();
     $new_core_entries = array();
     $new_controller_entries = array();
     $new_controller_files = array();
     $used_entries = AkLocaleManager::getUsedLanguageEntries();
     list($core_locale, $core_dictionary) = AkLocaleManager::getCoreDictionary(AK_FRAMEWORK_LANGUAGE);
     $controllers_dictionaries = array();
     foreach ($used_entries as $k => $v) {
         // This is a controller file
         if (is_array($v)) {
             if (!isset($controllers_dictionaries[$k])) {
                 $controller = $k;
                 $controllers_dictionaries[$controller] = AkLocaleManager::getDictionary(AK_FRAMEWORK_LANGUAGE, $controller);
                 if (!empty($controllers_dictionaries[$controller])) {
                     $existing_controllers_dictionaries[$controller] = $controllers_dictionaries[$controller];
                 } else {
                     $new_controller_files[$controller] = true;
                 }
                 $controllers_dictionaries[$controller] = array_merge($controllers_dictionaries[$controller], (array) $v);
             }
         } else {
             if (!isset($core_dictionary[$k])) {
                 $new_core_entries[$k] = $k;
             }
         }
     }
     foreach ($new_controller_files as $controller => $true) {
         $paths[] = AkLocaleManager::setDictionary($controllers_dictionaries[$controller], AK_FRAMEWORK_LANGUAGE, $controller, "File created on: " . date("Y-m-d G:i:s", Ak::time()));
         foreach (Ak::langs() as $lang) {
             if ($lang != AK_FRAMEWORK_LANGUAGE) {
                 $dictionary = AkLocaleManager::getDictionary($lang, $controller);
                 $paths[] = AkLocaleManager::setDictionary(array_merge($controllers_dictionaries[$controller], $dictionary), $lang, $controller);
             }
         }
         unset($controllers_dictionaries[$controller]);
     }
     // Module files
     foreach ((array) $controllers_dictionaries as $controller => $controller_entries) {
         $controller_entries = AkLocaleManager::getNewEntries($controller_entries, (array) @$existing_controllers_dictionaries[$controller]);
         if (!empty($controller_entries)) {
             $dictionary = AkLocaleManager::getDictionary(AK_FRAMEWORK_LANGUAGE, $controller);
             $paths[] = AkLocaleManager::setDictionary(array_merge($dictionary, $controller_entries), AK_FRAMEWORK_LANGUAGE, $controller);
             foreach (Ak::langs() as $lang) {
                 if ($lang != AK_FRAMEWORK_LANGUAGE) {
                     $dictionary = AkLocaleManager::getDictionary($lang, $controller);
                     $paths[] = AkLocaleManager::setDictionary(array_merge($dictionary, $controller_entries), $lang, $controller);
                 }
             }
         }
     }
     // Core locale files
     $new_core_entries = AkLocaleManager::getNewEntries($new_core_entries);
     if (!empty($new_core_entries)) {
         AkLocaleManager::setCoreDictionary($core_locale, array_merge($core_dictionary, $new_core_entries), AK_FRAMEWORK_LANGUAGE);
         foreach (Ak::langs() as $lang) {
             if ($lang != AK_FRAMEWORK_LANGUAGE) {
                 list($l, $dictionary) = AkLocaleManager::getCoreDictionary($lang);
                 if (empty($l)) {
                     $l = $core_locale;
                     $l['description'] = $lang;
                     $l['locale_description'] = $lang;
                 }
                 if (empty($dictionary)) {
                     $dictionary = $core_dictionary;
                 }
                 AkLocaleManager::setCoreDictionary($l, array_merge($dictionary, $new_core_entries), $lang);
             }
         }
     }
     return $paths;
 }