You are here

function _l10n_client_import_one_string_db in Localization client 5

Import one string into the database.

Note: Backport of Drupal 6 _locale_import_one_string_db basically copy and paste, removing textgroup parameters and asuming OVERWRITE mode. Also, locales_target:locale field has been renamed to language

Parameters

$report: Report array summarizing the number of changes done in the form: array(inserts, updates, deletes).

$langcode: Language code to import string into.

$source: Source string.

$translation: Translation to language specified in $langcode.

$location: Location value to save with source string.

$plid: Optional plural ID to use.

$plural: Optional plural value to use.

Return value

The string ID of the existing string modified or the new string added.

1 call to _l10n_client_import_one_string_db()
l10n_client_save_string in ./l10n_client.module
Menu callback. Saves a string translation coming as POST data.

File

./l10n_client.module, line 366
Localization client. Provides on-page translation editing.

Code

function _l10n_client_import_one_string_db(&$report, $langcode, $lid, $source, $translation, $location, $plid = NULL, $plural = NULL) {
  if (!$lid) {
    $lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $source));
  }
  if (!empty($translation)) {
    if ($lid) {

      // We have this source string saved already.
      // Changed: Do not update location
      $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $langcode));
      if (!$exists) {

        // No translation in this language.
        db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural);
        $report[0]++;
      }
      else {

        // Translation exists, only overwrite if instructed.
        db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE locale = '%s' AND lid = %d", $translation, $plid, $plural, $langcode, $lid);
        $report[1]++;
      }
    }
    else {

      // No such source string in the database yet.
      db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $location, $source);
      $lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE source = '%s' ", $source));
      db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural);
      $report[0]++;
    }
  }
  else {

    // Empty translation, remove existing if instructed.
    db_query("DELETE FROM {locales_target} WHERE language = '%s' AND lid = %d AND plid = %d AND plural = %d", $translation, $langcode, $lid, $plid, $plural);
    $report[2]++;
  }
  return $lid;
}