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)); }
/** * Untranslate strings from a locale to english. * * @access public * @static * @param string $string The string to be untranslated. * @param string $current_language A string containing the current language. * @return string The untranslated string. */ public static function untranslate($string, $current_language, $namespace = false) { $dictionary = AkLocaleManager::getDictionary($current_language, $namespace); $untranslated_string = array_search($string, $dictionary); return $untranslated_string ? $untranslated_string : $string; }
static function setDictionary($dictionary, $language, $namespace = false, $comment = null) { $path = AkConfig::getDir('app') . DS . 'locales' . DS . ($namespace ? trim(Ak::sanitize_include($namespace, 'high'), DS) . DS : '') . basename($language) . '.php'; AkLocaleManager::getDictionary($language, $namespace, true, $dictionary); AkFileSystem::file_put_contents($path, "<?php\n/** {$comment} */\n\n\$dictionary=" . var_export((array) $dictionary, true) . ";\n"); return $path; }
function setDictionary($dictionary,$language,$namespace=false,$comment=null) { $path = AK_APP_DIR.DS.'locales'.DS.($namespace?trim(Ak::sanitize_include($namespace,'high'),DS).DS:'').basename($language).'.php'; AkLocaleManager::getDictionary($language,$namespace,true,$dictionary); return Ak::file_put_contents($path,"<?php\n/** $comment */\n\n\$dictionary=".var_export((array)$dictionary,true).";\n"); }