public static function LingotekConfigChunk::saveSegmentTranslations in Lingotek Translation 7.4
Same name and namespace in other branches
- 7.3 lib/Drupal/lingotek/LingotekConfigChunk.php \LingotekConfigChunk::saveSegmentTranslations()
- 7.5 lib/Drupal/lingotek/LingotekConfigChunk.php \LingotekConfigChunk::saveSegmentTranslations()
Save segment target translations for the given language
Parameters
obj: the SimpleXMLElement object containing the translations to be saved
string: the language code under which to save the translations
1 call to LingotekConfigChunk::saveSegmentTranslations()
- LingotekConfigChunk::updateLocalContentByTarget in lib/
Drupal/ lingotek/ LingotekConfigChunk.php - Updates the local content of $target_code with data from a Lingotek Document
File
- lib/
Drupal/ lingotek/ LingotekConfigChunk.php, line 801 - Defines LingotekConfigChunk.
Class
- LingotekConfigChunk
- A class wrapper for Lingotek-specific behavior on ConfigChunks.
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);
}
}