You are here

function i18n_string_translation_update in Internationalization 7

Update / create translation for a certain source.

Parameters

$name: Array or string concatenated with ':' that contains textgroup and string context

$translation: Translation string for this language code

$langcode: The language code to translate to a language other than what is used to display the page.

$source_string: Optional source string, just in case it needs to be created.

Return value

mixed Source string object if update was successful. Null if source string not found. FALSE if use doesn't have permission to edit this translation.

1 call to i18n_string_translation_update()
i18n_string_l10n_client_save_string in i18n_string/i18n_string.pages.inc
Menu callback. Saves a string translation coming as POST data.

File

i18n_string/i18n_string.module, line 971
Internationalization (i18n) package - translatable strings.

Code

function i18n_string_translation_update($name, $translation, $langcode, $source_string = NULL) {
  if (is_array($translation)) {
    return i18n_string_multiple('translation_update', $name, $translation, $langcode);
  }
  elseif ($source = i18n_string_get_source($name)) {
    if ($langcode == i18n_string_source_language()) {

      // It's the default language so we should update the string source as well.
      i18n_string_update($name, $translation);
    }
    else {
      list($textgroup, $context) = i18n_string_context($name);
      i18n_string_textgroup($textgroup)
        ->update_translation($context, $langcode, $translation);
    }
    return $source;
  }
  elseif ($source_string) {

    // We don't have a source in the database, so we need to create it, but only if we've got the source too.
    // Note this string won't have any format.
    i18n_string_update($name, $source_string);
    return i18n_string_translation_update($name, $translation, $langcode);
  }
  else {
    return NULL;
  }
}