You are here

function i18nprofile_field_options in Internationalization 6

Translates field options.

2 calls to i18nprofile_field_options()
i18nprofile_form_translate_field in i18nprofile/i18nprofile.module
Translate form field.
i18nprofile_profile_alter in i18nprofile/i18nprofile.module
Implementation of hook_profile_alter().

File

i18nprofile/i18nprofile.module, line 215
Internationalization (i18n) submodule: Profile translation.

Code

function i18nprofile_field_options($field, $source = array()) {
  if ($translation = i18nstrings("profile:field:{$field}:options", '')) {

    // Troubles when doing the split, produces empty lines, quick fix
    $translation = str_replace("\r", '', $translation);
    $translation = explode("\n", $translation);
    if ($source) {
      $options = $source;
    }
    elseif ($source = db_result(db_query("SELECT options FROM {profile_fields} WHERE name = '%s'", $field))) {
      $source = str_replace("\r", '', $source);
      $source = explode("\n", $source);
      $options = array();
    }
    else {
      return NULL;
    }
    foreach ($source as $value) {
      if ($value != '--') {
        $string = $translation ? trim(array_shift($translation)) : trim($value);
        $options[trim($value)] = $string;
      }
    }
    return $options;
  }
}