mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/14432] Adds a method to get raw language values
PHPBB3-14432
This commit is contained in:
parent
56062a2635
commit
f5ca8c363b
2 changed files with 42 additions and 3 deletions
|
@ -246,14 +246,14 @@ class language
|
|||
}
|
||||
|
||||
/**
|
||||
* Act like lang() but takes a key and an array of parameters instead of using variadic
|
||||
* Returns the raw value associated to a language key or the language key no translation is available.
|
||||
* No parameter substitution is performed, can be a string or an array.
|
||||
*
|
||||
* @param string|array $key Language key
|
||||
* @param array $args Parameters
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
public function lang_array($key, $args = array())
|
||||
public function lang_raw($key)
|
||||
{
|
||||
// Load common language files if they not loaded yet
|
||||
if (!$this->common_language_files_loaded)
|
||||
|
@ -281,6 +281,26 @@ class language
|
|||
return $key;
|
||||
}
|
||||
|
||||
return $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Act like lang() but takes a key and an array of parameters instead of using variadic
|
||||
*
|
||||
* @param string|array $key Language key
|
||||
* @param array $args Parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function lang_array($key, $args = array())
|
||||
{
|
||||
$lang = $this->lang_raw($key);
|
||||
|
||||
if ($lang === $key)
|
||||
{
|
||||
return $key;
|
||||
}
|
||||
|
||||
// If the language entry is a string, we simply mimic sprintf() behaviour
|
||||
if (is_string($lang))
|
||||
{
|
||||
|
|
|
@ -53,6 +53,25 @@ class phpbb_language_test extends phpbb_test_case
|
|||
$this->assertFalse($this->lang->is_set(array('PHPBB', 'PHP')));
|
||||
}
|
||||
|
||||
public function test_lang_raw()
|
||||
{
|
||||
$this->assertEquals($this->lang->lang_raw('FOO'), 'BAR');
|
||||
$this->assertEquals($this->lang->lang_raw('VOID'), 'VOID');
|
||||
$this->assertEquals($this->lang->lang_raw('ARRY'), array(
|
||||
0 => 'No posts', // 0
|
||||
1 => '1 post', // 1
|
||||
2 => '%d posts', // 2+
|
||||
));
|
||||
}
|
||||
|
||||
public function test_lang_array()
|
||||
{
|
||||
$this->assertEquals($this->lang->lang_array('FOO'), 'BAR');
|
||||
$this->assertEquals($this->lang->lang_array('VOID'), 'VOID');
|
||||
$this->assertEquals($this->lang->lang_array('ARRY', [0]), 'No posts');
|
||||
$this->assertEquals($this->lang->lang_array('FOO', [2, 3, 'BARZ']), 'BAR');
|
||||
}
|
||||
|
||||
public function test_lang()
|
||||
{
|
||||
// No param
|
||||
|
|
Loading…
Add table
Reference in a new issue