1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-24 20:13:22 +01: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

@ -550,22 +550,8 @@ class acp_groups
$avatar = phpbb_get_group_avatar($group_row, 'GROUP_AVATAR', true);
/*
* Merge any avatar errors into the primary error array
* Drivers use language constants, so we need to map to the actual strings
*/
foreach ($avatar_error as $lang)
{
if (is_array($lang))
{
$key = array_shift($lang);
$error[] = vsprintf($user->lang($key), $lang);
}
else
{
$error[] = $user->lang("$lang");
}
}
// Merge any avatar errors into the primary error array
$error = array_merge($error, $phpbb_avatar_manager->localize_errors($user, $avatar_error));
$back_link = request_var('back_link', '');

View File

@ -1831,18 +1831,7 @@ class acp_users
}
// Replace "error" strings with their real, localised form
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);
}
}
$error = $phpbb_avatar_manager->localize_errors($user, $error);
$avatar = phpbb_get_user_avatar($user_row, 'USER_AVATAR', true);

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;
}
}

View File

@ -674,19 +674,7 @@ class ucp_groups
}
// Merge any avatars errors into the primary error array
// Drivers use lang constants, so we need to map to the actual strings
foreach ($avatar_error as $lang)
{
if (is_array($lang))
{
$key = array_shift($lang);
$error[] = vsprintf($user->lang($key), $lang);
}
else
{
$error[] = $user->lang("$lang");
}
}
$error = array_merge($error, $phpbb_avatar_manager->localize_errors($user, $avatar_error));
$template->assign_vars(array(
'S_EDIT' => true,

View File

@ -659,19 +659,8 @@ class ucp_profile
}
// Replace "error" strings with their real, localised form
foreach ($error as $key => $lang)
{
if (is_array($lang))
{
$key = array_shift($lang);
$error[$key] = vsprintf($user->lang($key), $lang);
}
else
{
$error[$key] = $user->lang("$lang");
}
}
$error = $phpbb_avatar_manager->localize_errors($user, $error);
$avatar = phpbb_get_user_avatar($user->data, 'USER_AVATAR', true);
$template->assign_vars(array(