1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-10 18:54:08 +02:00

[feature/avatars] Add function for localizing errors

PHPBB3-10018
This commit is contained in:
Marc Alexander
2013-01-06 21:09:07 +01:00
parent 111e02395c
commit 41710c745d
5 changed files with 35 additions and 58 deletions

View File

@@ -44,11 +44,7 @@ class phpbb_avatar_manager
/**
* Construct an avatar manager object
*
* @param string $phpbb_root_path Path to the phpBB root
* @param string $phpEx PHP file extension
* @param phpbb_config $config phpBB configuration
* @param phpbb_request $request Request object
* @param phpbb_cache_driver_interface $cache Cache driver
* @param array $avatar_drivers Avatar drivers passed via the service container
* @param object $container Container object
*/
@@ -260,4 +256,33 @@ class phpbb_avatar_manager
{
return preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver));
}
/**
* Replace "error" strings with their real, localized form
*
* @param phpbb_user phpBB User object
* @param array $error Array containing error strings
* Key values can either be a string with a language key or an array
* that will be passed to vsprintf() with the language key in the
* first array key.
*
* @return array Array containing the localized error strings
*/
public function localize_errors(phpbb_user $user, $error)
{
foreach ($error as $key => $lang)
{
if (is_array($lang))
{
$lang_key = array_shift($lang);
$error[$key] = vsprintf($user->lang($lang_key), $lang);
}
else
{
$error[$key] = $user->lang("$lang");
}
}
return $error;
}
}