You are here

function i18nstrings_save_translation in Internationalization 6

Import translation for a given textgroup.

@TODO Check string format properly

This will update multiple strings if there are duplicated ones

Parameters

$langcode: Language code to import string into.

$source: Source string.

$translation: Translation to language specified in $langcode.

$plid: Optional plural ID to use.

$plural: Optional plural value to use.

Return value

The number of strings updated

1 call to i18nstrings_save_translation()
i18nstrings_save_string in i18nstrings/i18nstrings.module
Menu callback. Saves a string translation coming as POST data.

File

i18nstrings/i18nstrings.module, line 1055
Internationalization (i18n) package - translatable strings.

Code

function i18nstrings_save_translation($langcode, $source, $translation, $textgroup) {
  include_once 'includes/locale.inc';
  $result = db_query("SELECT s.lid, i.format FROM {locales_source} s LEFT JOIN {i18n_strings} i ON s.lid = i.lid WHERE s.source = '%s' AND s.textgroup = '%s'", $source, $textgroup);
  $count = 0;
  while ($source = db_fetch_object($result)) {

    // If we have a format, check format access. Otherwise do regular check.
    if ($source->format ? filter_access($source->format) : locale_string_is_safe($translation)) {
      $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $source->lid, $langcode));
      if (!$exists) {

        // No translation in this language.
        db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '%s')", $source->lid, $langcode, $translation);
      }
      else {

        // Translation exists, overwrite
        db_query("UPDATE {locales_target} SET translation = '%s' WHERE language = '%s' AND lid = %d", $translation, $langcode, $source->lid);
      }
      $count++;
    }
  }
  return $count;
}