You are here

function i18nprofile_update_2 in Internationalization 6

Drop old table and fields.

File

i18nprofile/i18nprofile.install, line 21
Installation file for i18nprofile module.

Code

function i18nprofile_update_2() {
  $items = array();

  // Create source strings for translations.
  $categories = array();
  $result = db_query("SELECT * FROM {profile_fields}");
  while ($field = db_fetch_object($result)) {

    // Store strings to translate: title, explanation, options.
    i18nstrings_update_object("profile:field:{$field->name}", $field, array(
      'title',
      'explanation',
      'options',
    ));
    if (!in_array($field->category, $categories)) {
      $categories[] = $field->category;
      i18nstrings_update("profile:category", $field->category);
    }
  }

  // Category translations from variables.
  foreach (array_keys(language_list()) as $lang) {
    if ($translation = variable_get('i18nprofile_' . $lang, FALSE)) {
      foreach ($translation as $category => $translation) {
        if (in_array($category, $categories) && $translation) {
          $context = i18nstrings_context('profile:category', $category);
          i18nstrings_update_translation($context, $lang, $translation);
        }
      }
    }
  }

  // Move current data into string translations.
  $result = db_query("SELECT * FROM {i18n_profile_fields}");
  while ($field = db_fetch_object($result)) {
    foreach (array(
      'title',
      'explanation',
      'options',
    ) as $property) {
      if (!empty($field->{$property})) {
        i18nstrings_update_translation("profile:field:{$field->name}:{$property}", $field->language, $field->{$property});
      }
    }
  }
  return $items;
}