You are here

function i18n_field_translate_allowed_values in Internationalization 7

Returns the array of translated allowed values for a list field.

The strings are not safe for output. Keys and values of the array should be sanitized through field_filter_xss() before being displayed.

Parameters

$field: The field definition.

Return value

The array of allowed values. Keys of the array are the raw stored values (number or text), values of the array are the display labels.

2 string references to 'i18n_field_translate_allowed_values'
hook_i18n_field_info in i18n_field/i18n_field.api.php
Provide information about callbacks for translating specific field types.
i18n_field_i18n_field_info in i18n_field/i18n_field.i18n.inc
Implements hook_i18n_field_info().

File

i18n_field/i18n_field.module, line 400
Internationalization (i18n) module - Field handling

Code

function i18n_field_translate_allowed_values($field, $langcode = NULL) {
  $allowed_values = list_allowed_values($field);
  if (!$allowed_values) {
    return array();
  }

  // Do not attempt to translate options from a callback.
  $function = $field['settings']['allowed_values_function'];
  if (!empty($function) && function_exists($function)) {
    return $allowed_values;
  }
  return i18n_string_translate(array(
    'field',
    $field['field_name'],
    '#allowed_values',
  ), $allowed_values, array(
    'langcode' => $langcode,
    'sanitize' => FALSE,
  ));
}