mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/12115] Translate profile field name before displaying it in errors
PHPBB3-12115
This commit is contained in:
parent
38608bfa62
commit
f97d268a79
7 changed files with 31 additions and 14 deletions
|
@ -76,6 +76,14 @@ abstract class type_base implements type_interface
|
|||
return 'pf_' . $field_data['field_ident'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_field_name($field_name)
|
||||
{
|
||||
return isset($this->user->lang[$field_name]) ? $this->user->lang[$field_name] : $field_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -136,7 +136,7 @@ class type_bool extends type_base
|
|||
|
||||
if (!$field_value && $field_data['field_required'])
|
||||
{
|
||||
return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
|
||||
return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -159,17 +159,17 @@ class type_date extends type_base
|
|||
|
||||
if ((!$day || !$month || !$year) && $field_data['field_required'])
|
||||
{
|
||||
return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
|
||||
return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50)
|
||||
{
|
||||
return $this->user->lang('FIELD_INVALID_DATE', $field_data['lang_name']);
|
||||
return $this->user->lang('FIELD_INVALID_DATE', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
if (checkdate($month, $day, $year) === false)
|
||||
{
|
||||
return $this->user->lang('FIELD_INVALID_DATE', $field_data['lang_name']);
|
||||
return $this->user->lang('FIELD_INVALID_DATE', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -137,12 +137,12 @@ class type_dropdown extends type_base
|
|||
|
||||
if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value))
|
||||
{
|
||||
return $this->user->lang('FIELD_INVALID_VALUE', $field_data['lang_name']);
|
||||
return $this->user->lang('FIELD_INVALID_VALUE', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
|
||||
{
|
||||
return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
|
||||
return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -126,11 +126,11 @@ class type_int extends type_base
|
|||
|
||||
if ($field_value < $field_data['field_minlen'])
|
||||
{
|
||||
return $this->user->lang('FIELD_TOO_SMALL', (int) $row['field_minlen'], $row['lang_name']);
|
||||
return $this->user->lang('FIELD_TOO_SMALL', (int) $field_data['field_minlen'], $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
else if ($field_value > $field_data['field_maxlen'])
|
||||
{
|
||||
return $this->user->lang('FIELD_TOO_LARGE', (int) $row['field_maxlen'], $row['lang_name']);
|
||||
return $this->user->lang('FIELD_TOO_LARGE', (int) $field_data['field_maxlen'], $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -174,4 +174,13 @@ interface type_interface
|
|||
* @return null
|
||||
*/
|
||||
public function display_options(&$template_vars, &$field_data);
|
||||
|
||||
/**
|
||||
* Return templated value/field. Possible values for $mode are:
|
||||
* change == user is able to set/enter profile values; preview == just show the value
|
||||
* @param string $mode
|
||||
* @param array $profile_row
|
||||
* @return null
|
||||
*/
|
||||
public function process_field_row($mode, $profile_row);
|
||||
}
|
||||
|
|
|
@ -52,16 +52,16 @@ abstract class type_string_common extends type_base
|
|||
}
|
||||
else if (trim($field_value) === '' && $field_data['field_required'])
|
||||
{
|
||||
return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
|
||||
return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen'])
|
||||
{
|
||||
return $this->user->lang('FIELD_TOO_SHORT', (int) $row['field_minlen'], $row['lang_name']);
|
||||
return $this->user->lang('FIELD_TOO_SHORT', (int) $field_data['field_minlen'], $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen'])
|
||||
{
|
||||
return $this->user->lang('FIELD_TOO_LONG', (int) $row['field_maxlen'], $row['lang_name']);
|
||||
return $this->user->lang('FIELD_TOO_LONG', (int) $field_data['field_maxlen'], $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
|
||||
if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*')
|
||||
|
@ -72,13 +72,13 @@ abstract class type_string_common extends type_base
|
|||
switch ($row['field_validation'])
|
||||
{
|
||||
case '[0-9]+':
|
||||
return $this->user->lang('FIELD_INVALID_CHARS_NUMBERS_ONLY', $row['lang_name']);
|
||||
return $this->user->lang('FIELD_INVALID_CHARS_NUMBERS_ONLY', $this->get_field_name($field_data['lang_name']));
|
||||
|
||||
case '[\w]+':
|
||||
return $this->user->lang('FIELD_INVALID_CHARS_ALPHA_ONLY', $row['lang_name']);
|
||||
return $this->user->lang('FIELD_INVALID_CHARS_ALPHA_ONLY', $this->get_field_name($field_data['lang_name']));
|
||||
|
||||
case '[\w_\+\. \-\[\]]+':
|
||||
return $this->user->lang('FIELD_INVALID_CHARS_SPACERS_ONLY', $row['lang_name']);
|
||||
return $this->user->lang('FIELD_INVALID_CHARS_SPACERS_ONLY', $this->get_field_name($field_data['lang_name']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue