You are here

function i18nprofile_profile_alter in Internationalization 6

Same name and namespace in other branches
  1. 5.3 i18nprofile/i18nprofile.module \i18nprofile_profile_alter()
  2. 5 i18nprofile/i18nprofile.module \i18nprofile_profile_alter()
  3. 5.2 i18nprofile/i18nprofile.module \i18nprofile_profile_alter()

Implementation of hook_profile_alter().

Translates categories and fields.

File

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

Code

function i18nprofile_profile_alter(&$account) {
  foreach (profile_categories() as $category) {
    $name = $category['name'];
    if (!empty($account->content[$name])) {

      // First ranslate category title then fields.
      $account->content[$name]['#title'] = i18nstrings('profile:category', $account->content[$name]['#title']);
      foreach (element_children($account->content[$name]) as $field) {
        i18nprofile_form_translate_field($account->content[$name], $field);

        // Translate value if options field
        if (!empty($account->content[$name][$field]['#value']) && ($options = i18nprofile_field_options($field))) {

          // Get the value from the account because this one may have been formatted.
          if (isset($options[$account->{$field}])) {

            // It may be a link or a paragraph, trick for not loading the field again.
            if (!preg_match('|^<a href="|', $account->content[$name][$field]['#value'])) {

              // Plain html
              $account->content[$name][$field]['#value'] = check_markup($options[$account->{$field}]);
            }
            else {

              // Link
              $account->content[$name][$field]['#value'] = check_markup(l($options[$account->{$field}], 'profile/' . $field . '/' . $account->{$field}));
            }
          }
        }
      }
    }
  }
}