/** * Recive a translated line * * __( 'some/path.to.my.label' ); * __( 'user.welcome', array( 'name' => 'Jeff' ) ) * * @param string $key * @param array $params * @return string */ public static function line($key, $params = array()) { $path = substr($key, 0, strpos($key, '.')); $key = substr($key, strpos($key, '.') + 1); // if there is a namespace replace the path with it if (isset(static::$aliases[$path])) { return static::line(static::$aliases[$path] . '.' . $key, $params); } // find the language file behind the path if (!isset(static::$data[static::$current_language][$path])) { // Autoload the language file // The load function will throw an exception if the // file doesnt exists so we dont have to care for that here. CCLang::load($path); } // Does the line exist in the language file? if (!isset(static::$data[static::$current_language][$path][$key])) { // We simply return the key to the user and log the missing language file line CCLog::add('CCLang::line - No such line "' . $key . '" (' . static::$current_language . ') in file: ' . $path, 'warning'); return $key; } $line = static::$data[static::$current_language][$path][$key]; // replace the params inside the line foreach ($params as $param => $value) { $line = str_replace(':' . $param, $value, $line); } return $line; }
/** * CCLang::wrong tests * * @expectedException CCException */ public function test_load_wrong() { CCLang::load('CCUnit::wrong'); }