Skip to content

Commit

Permalink
[ticket/13762] Fix language fallback with path in $component
Browse files Browse the repository at this point in the history
PHPBB3-13762
  • Loading branch information
CHItA committed Apr 16, 2015
1 parent 2cb7bf3 commit 0def5bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
20 changes: 19 additions & 1 deletion phpBB/phpbb/language/language_file_loader.php
Expand Up @@ -125,9 +125,27 @@ public function load_extension($extension, $component, $locale, &$lang)
*/
protected function load_file($path, $component, $locale, &$lang)
{
// This is BC stuff and not the best idea as it makes language fallback
// implementation quite hard like below.
if (strpos($this->phpbb_root_path . $component, $path) === 0)
{
$component = basename($component, '.' . $this->php_ext);
// Filter out the path
$path_diff = str_replace($path, '', dirname($this->phpbb_root_path . $component));
$language_file = basename($component, '.' . $this->php_ext);
$component = '';

// This step is needed to resolve language/en/subdir style $component
// $path already points to the language base directory so we need to eliminate
// the first directory from the path (that should be the language directory)
$path_diff_parts = explode('/', $path_diff);

if (sizeof($path_diff_parts) > 1)
{
array_shift($path_diff_parts);
$component = implode('/', $path_diff_parts) . '/';
}

$component .= $language_file;
}

// Determine filename
Expand Down
16 changes: 9 additions & 7 deletions tests/user/lang_test.php
Expand Up @@ -122,20 +122,22 @@ public function test_user_lang_sprintf()
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime');
self::$language_reflection_lang->setValue($lang,array(

self::$language_reflection_lang->setValue($lang, array(
'PLURAL_RULE' => 13,
'ARRY' => array(
'PLURAL_ARRY' => array(
0 => '%d is 0', // 0
1 => '%d is 1', // 1
2 => '%d ends with 01-10', // ending with 01-10
3 => '%d ends with 11-19', // ending with 11-19
4 => '%d is part of the last rule', // everything else
),
));
$this->assertEquals($user->lang('ARRY', 0), '0 is 0');
$this->assertEquals($user->lang('ARRY', 1), '1 is 1');
$this->assertEquals($user->lang('ARRY', 103), '103 ends with 01-10');
$this->assertEquals($user->lang('ARRY', 15), '15 ends with 11-19');
$this->assertEquals($user->lang('ARRY', 300), '300 is part of the last rule');

$this->assertEquals($user->lang('PLURAL_ARRY', 0), '0 is 0');
$this->assertEquals($user->lang('PLURAL_ARRY', 1), '1 is 1');
$this->assertEquals($user->lang('PLURAL_ARRY', 103), '103 ends with 01-10');
$this->assertEquals($user->lang('PLURAL_ARRY', 15), '15 ends with 11-19');
$this->assertEquals($user->lang('PLURAL_ARRY', 300), '300 is part of the last rule');
}
}

0 comments on commit 0def5bf

Please sign in to comment.