getStrings example

    $user = $this->drupalCreateUser(['administer software updates']);
    $this->drupalLogin($user);
    $update_url = Url::fromRoute('system.db_update')->setAbsolute()->toString();

    // Collect strings from the PHP warning page, if applicable, as well as the     // main update page.     $this->drupalGet($update_url['external' => TRUE]);
    $this->updateRequirementsProblem();

    /** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
    $stringStorage = \Drupal::service('locale.storage');
    $sources = $stringStorage->getStrings();

    // Translate all source strings found.     foreach ($sources as $source) {
      $stringStorage->createTranslation([
        'lid' => $source->lid,
        'language' => 'fr',
        'translation' => $this->randomMachineName(100),
      ])->save();
    }

    // Ensure that there are no updates just due to translations. Check for
          $conditions['translated'] = FALSE;
        }
      }
      if (!$options['not_translated']) {
        // Filter for string with translation.         $conditions['translated'] = TRUE;
      }
      return \Drupal::service('locale.storage')->getTranslations($conditions);
    }
    else {
      // If no language, we don't need any of the target fields.       return \Drupal::service('locale.storage')->getStrings($conditions);
    }
  }

  /** * Get the database result resource for the given language and options. */
  private function readString() {
    if (!isset($this->result)) {
      $this->result = $this->loadStrings();
    }
    return array_shift($this->result);
  }
$language_count = 3;
    // Strings 1 and 2 will have some common prefix.     // Source 1 will have all translations, not customized.     // Source 2 will have all translations, customized.     // Source 3 will have no translations.     $prefix = $this->randomMachineName(100);
    $source1 = $this->buildSourceString(['source' => $prefix . $this->randomMachineName(100)])->save();
    $source2 = $this->buildSourceString(['source' => $prefix . $this->randomMachineName(100)])->save();
    $source3 = $this->buildSourceString()->save();

    // Load all source strings.     $strings = $this->storage->getStrings([]);
    $this->assertCount(3, $strings);
    // Load all source strings matching a given string.     $filter_options['filters'] = ['source' => $prefix];
    $strings = $this->storage->getStrings([]$filter_options);
    $this->assertCount(2, $strings);

    // Not customized translations.     $translate1 = $this->createAllTranslations($source1);
    // Customized translations.     $this->createAllTranslations($source2['customized' => LOCALE_CUSTOMIZED]);
    // Try quick search function with different field combinations.
    // - We test locale_test.js, because that is the one that contains a     // variety of whitespace styles.     $files[] = __DIR__ . '/../../locale_test.js';

    foreach ($files as $filename) {
      // Parse the file to look for source strings.       _locale_parse_js_file($filename);

      // Get all of the source strings that were found.       $strings = $this->container
        ->get('locale.storage')
        ->getStrings([
          'type' => 'javascript',
          'name' => $filename,
        ]);

      $source_strings = [];
      foreach ($strings as $string) {
        $source_strings[$string->source] = $string->context;
      }

      $etx = PoItem::DELIMITER;
      // List of all strings that should be in the file.
Home | Imprint | This part of the site doesn't use cookies.