You are here

public function LingotekInterfaceTranslationService::getSourceData in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 4.0.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::getSourceData()
  2. 3.2.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::getSourceData()
  3. 3.3.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::getSourceData()
  4. 3.5.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::getSourceData()
  5. 3.6.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::getSourceData()
  6. 3.7.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::getSourceData()
  7. 3.8.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::getSourceData()

Returns the source data that will be uploaded to the Lingotek service.

Only those fields that have actual translatable text, and have marked for upload will be included.

Parameters

string $component: The component which we want the source data.

Return value

array

Overrides LingotekInterfaceTranslationServiceInterface::getSourceData

3 calls to LingotekInterfaceTranslationService::getSourceData()
LingotekInterfaceTranslationService::updateDocument in src/LingotekInterfaceTranslationService.php
Resends a document to the translation service.
LingotekInterfaceTranslationService::updateEntityHash in src/LingotekInterfaceTranslationService.php
Updates the component hash.
LingotekInterfaceTranslationService::uploadDocument in src/LingotekInterfaceTranslationService.php
Uploads a document to the Lingotek service.

File

src/LingotekInterfaceTranslationService.php, line 402

Class

LingotekInterfaceTranslationService
Service for managing Lingotek interface translations.

Namespace

Drupal\lingotek

Code

public function getSourceData($component) {
  $data = [];
  $potx_strings = $this
    ->extractPotxStrings($component);
  if (!empty($potx_strings)) {
    foreach ($potx_strings as $potx_string => $potx_string_meta) {

      // The key in the JSON download cannot have the null byte used by plurals.
      $translationStringKey = str_replace("\0", "<PLURAL>", $potx_string);

      // Plural strings have a null byte delimited format. We need to separate the
      // segments ourselves and nest those in.
      $explodedStrings = explode("\0", $potx_string);
      $translationData = [];
      foreach ($explodedStrings as $index => $explodedString) {
        $translationData[$explodedString] = $explodedString;
      }
      foreach ($potx_string_meta as $context => $potx_string_meta_locations) {
        $translationStringKeyWithContext = $translationStringKey . '<CONTEXT>' . $context;
        $data[$translationStringKeyWithContext] = $translationData;
        $data[$translationStringKeyWithContext]['_context'] = $context;
      }
    }
  }
  return $data;
}