I have a static class like this.
<?php
class Language
{
public static $language = array();
var $config;
function __construct($config)
{
switch(strtoupper($config['LANGUAGE']))
{
case 'ENGLISH':
self::setEnglish();
break;
case 'TURKISH':
self::setTurkish();
break;
default:
self::setEnglish();
}
}
public static function setEnglish()
{
self::$language = array(
'CHAIN_VALIDATOR_INITIALIZED' => 'ChainValidator initialized!',
'ERROR_FUNCTION_RETURNED_FALSE' => 'A function returned false.',
);
}
public static function setTurkish()
{
self::$language = array(
'CHAIN_VALIDATOR_INITIALIZED' => 'ChainValidator çalışıyor!',
'ERROR_FUNCTION_RETURNED_FALSE' => 'Bir fonksiyon false döndürdü.',
);
}
public static function getLanguage($key)
{
return isset(self::$language[$key]) ? self::$language[$key] : $key;
}
}
?>
It is being used like this,
Language::getLanguage('CHAIN_VALIDATOR_INITIALIZED')
but I have to pass more parameters. Similar to this,
Language::getLanguage('CHAIN_VALIDATOR_INITIALIZED', array(__FUNCTION__))
These parameters should be passed in an order, like %s. Final look should look like this:
"A function returned false" to;
"%s function returned false"
And output would be;
"myLovelyFunction() returned false" (the first array parameter, which is __FUNCTION__)
Sounds like piece of cake my brain stopped atm.
How can I do this?
You can use call_user_func_array and sprintf for that, e.g.
prints