You are here

public static function LingotekConfigSet::saveSegmentTranslations in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lib/Drupal/lingotek/LingotekConfigSet.php \LingotekConfigSet::saveSegmentTranslations()

Save segment target translations for the given language

Parameters

obj: the LingotekXMLElement object containing the translations to be saved

string: the language code under which to save the translations

1 call to LingotekConfigSet::saveSegmentTranslations()
LingotekConfigSet::downloadTriggered in lib/Drupal/lingotek/LingotekConfigSet.php
Updates the local content of $target_code with data from a Lingotek Document

File

lib/Drupal/lingotek/LingotekConfigSet.php, line 1048
Defines LingotekConfigSet.

Class

LingotekConfigSet
A class wrapper for Lingotek-specific behavior on ConfigSets.

Code

public static function saveSegmentTranslations($document_xml, $target_language) {
  $non_lingotek_locales_targets = self::getNonLingotekLocalesTargets($document_xml, $target_language);
  $plural_mapping = variable_get('lingotek_config_plural_mapping', array());
  $rows = array();
  $sql = 'INSERT INTO {locales_target} (lid, translation, language, plid, plural, translation_agent_id) VALUES ';
  $subsql = '';
  $icount = 0;
  $lingotek_agent = self::getLingotekTranslationAgentId();
  foreach ($document_xml as $drupal_field_name => $xml_obj) {
    $lid = self::getLidFromTag($drupal_field_name);
    if (!in_array($lid, $non_lingotek_locales_targets)) {
      $content = (string) $xml_obj->element;
      $content = lingotek_unfilter_placeholders(decode_entities($content));
      $plural_lid = array_key_exists($lid, $plural_mapping);
      $rows += array(
        ":l_{$icount}" => $lid,
        ":c_{$icount}" => $content,
        ":lang_{$icount}" => $target_language,
        ":plid_{$icount}" => $plural_lid ? $plural_mapping[$lid]['plid'] : 0,
        ":plural_{$icount}" => $plural_lid ? $plural_mapping[$lid]['plural'] : 0,
        ":agent_{$icount}" => $lingotek_agent,
      );
      $subsql .= "( :l_{$icount}, :c_{$icount}, :lang_{$icount}, :plid_{$icount}, :plural_{$icount}, :agent_{$icount}),";
      $icount++;
    }
  }
  if (!empty($rows)) {
    $subsql = rtrim($subsql, ',');
    db_query($sql . $subsql, $rows);
  }
}