You are here

protected function i18n_string_textgroup_default::string_add in Internationalization 7

Add source string to the locale tables for translation.

It will also add data into i18n_string table for faster retrieval and indexing of groups of strings. Some string context doesn't have a numeric oid (I.e. content types), it will be set to zero.

This function checks for already existing string without context for this textgroup and updates it accordingly. It is intended for backwards compatibility, using already created strings.

Parameters

$i18nstring: String object

$format: Text format, for strings that will go through some filter

Return value

Update status.

1 call to i18n_string_textgroup_default::string_add()
i18n_string_textgroup_default::string_update in i18n_string/i18n_string.inc
Update / create / remove string.

File

i18n_string/i18n_string.inc, line 385
API for internationalization strings

Class

i18n_string_textgroup_default
Textgroup handler for i18n_string API

Code

protected function string_add($i18nstring, $options = array()) {
  $options += array(
    'watchdog' => TRUE,
  );

  // Default return status if nothing happens
  $status = -1;
  $source = NULL;
  $location = $i18nstring->location;

  // The string may not be allowed for translation depending on its format.
  if (!$this
    ->string_check($i18nstring, $options)) {

    // The format may have changed and it's not allowed now, delete the source string
    return $this
      ->string_remove($i18nstring, $options);
  }
  elseif ($source = $i18nstring
    ->get_source()) {
    if ($source->source != $i18nstring->string || $source->location != $location) {
      $i18nstring->location = $location;

      // String has changed, mark translations for update
      $status = $this
        ->save_source($i18nstring);
      db_update('locales_target')
        ->fields(array(
        'i18n_status' => I18N_STRING_STATUS_UPDATE,
      ))
        ->condition('lid', $source->lid)
        ->execute();
    }
    elseif (empty($source->version)) {

      // When refreshing strings, we've done version = 0, update it
      $this
        ->save_source($i18nstring);
    }
  }
  else {

    // We don't have the source object, create it
    $status = $this
      ->save_source($i18nstring);
  }

  // Make sure we have i18n_string part, create or update
  // This will also create the source object if doesn't exist
  $this
    ->save_string($i18nstring);
  if ($options['watchdog']) {
    switch ($status) {
      case SAVED_UPDATED:
        watchdog('i18n_string', 'Updated string %location for textgroup %textgroup: %string', $i18nstring
          ->get_args());
        break;
      case SAVED_NEW:
        watchdog('i18n_string', 'Created string %location for text group %textgroup: %string', $i18nstring
          ->get_args());
        break;
    }
  }
  return $status;
}