diff --git a/model/Config.php b/model/Config.php index 4eb94366..53f2586e 100644 --- a/model/Config.php +++ b/model/Config.php @@ -218,7 +218,18 @@ final class Config { * @return string value of $PALANG[$var], parsed by sprintf */ public static function lang_f($var, $value) { - return self::read_f('__LANG.' . $var, $value); + $all = self::read_array('__LANG'); + + $text = $all[$var] ?? ''; + + $newtext = sprintf($text, $value); + + # check if sprintf changed something - if not, there are chances that $text didn't contain a %s + if ($text == $newtext) { + error_log("$var used via read_f, but nothing replaced (value $value)"); + } + + return $newtext; } /** diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php new file mode 100644 index 00000000..33a84d62 --- /dev/null +++ b/tests/ConfigTest.php @@ -0,0 +1,33 @@ +getAll(); + + $all['xmlrpc_enabled'] = false; + + $c->setAll($all); + + parent::setUp(); + } + + public function testLangF() { + $x = Config::lang_f('must_be_numeric', 'foo@bar'); + + $this->assertEquals('foo@bar must be numeric', $x); + } + + public function testLang() { + $x = Config::lang('must_be_numeric', 'foo@bar'); + + $this->assertEquals('%s must be numeric', $x); + } + + public function testBool() { + $x = Config::bool('xmlrpc_enabled'); + + $this->assertFalse($x); + } +}