You are here

public function i18n_string_textgroup_default::string_update in Internationalization 7

Update / create / remove string.

@pram $string New value of string for update/create. May be empty for removing.

Parameters

$name: String context.

$format: Text format, that must have been checked against allowed formats for translation

$options: Processing options, the ones used here are:

  • 'watchdog', whether to produce watchdog messages.
  • 'messages', whether to produce user messages.
  • 'check', whether to check string format and then update/delete if not allowed.

Return value

status SAVED_UPDATED | SAVED_NEW | SAVED_DELETED | FALSE (If the string is to be removed but has no source)

2 calls to i18n_string_textgroup_default::string_update()
i18n_string_textgroup_cached::string_update in i18n_string/i18n_string.inc
Update / create / remove string.
i18n_string_textgroup_default::context_update in i18n_string/i18n_string.inc
Update / create translation source for user defined strings.
1 method overrides i18n_string_textgroup_default::string_update()
i18n_string_textgroup_cached::string_update in i18n_string/i18n_string.inc
Update / create / remove string.

File

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

Class

i18n_string_textgroup_default
Textgroup handler for i18n_string API

Code

public function string_update($i18nstring, $options = array()) {
  $options += array(
    'watchdog' => TRUE,
    'messages' => $this->debug,
    'check' => TRUE,
  );
  if ((!$options['check'] || $this
    ->string_check($i18nstring, $options)) && $i18nstring
    ->get_string()) {

    // String is ok, has a value so we store it into the database.
    $status = $this
      ->string_add($i18nstring, $options);
  }
  elseif ($i18nstring
    ->get_source()) {

    // Just remove it if we already had a source created before.
    $status = $this
      ->string_remove($i18nstring, $options);
  }
  else {

    // String didn't pass validation or we have an empty string but was not stored anyway.
    $status = FALSE;
  }
  if ($options['messages']) {
    switch ($status) {
      case SAVED_UPDATED:
        drupal_set_message(t('Updated string %location for text group %textgroup: %string', $i18nstring
          ->get_args()));
        break;
      case SAVED_NEW:
        drupal_set_message(t('Created string %location for text group %textgroup: %string', $i18nstring
          ->get_args()));
        break;
    }
  }
  if ($options['watchdog']) {
    switch ($status) {
      case SAVED_UPDATED:
        watchdog('i18n_string', 'Updated string %location for text group %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;
}