Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PoDatabaseReader.php

function PoDatabaseReader::loadStrings

Builds and executes a database query based on options set earlier.

1 call to PoDatabaseReader::loadStrings()
PoDatabaseReader::readString in core/modules/locale/src/PoDatabaseReader.php
Get the database result resource for the given language and options.

File

core/modules/locale/src/PoDatabaseReader.php, line 104

Class

PoDatabaseReader
Gettext PO reader working with the locale module database.

Namespace

Drupal\locale

Code

private function loadStrings() {
    $langcode = $this->langcode;
    $options = $this->options;
    $conditions = [];
    if (array_sum($options) == 0) {
        // If user asked to not include anything in the translation files,
        // that would not make sense, so just fall back on providing a template.
        $langcode = NULL;
        // Force option to get both translated and untranslated strings.
        $options['not_translated'] = TRUE;
    }
    // Build and execute query to collect source strings and translations.
    if (!empty($langcode)) {
        $conditions['language'] = $langcode;
        // Translate some options into field conditions.
        if ($options['customized']) {
            if (!$options['not_customized']) {
                // Filter for customized strings only.
                $conditions['customized'] = LOCALE_CUSTOMIZED;
            }
            // Else no filtering needed in this case.
        }
        else {
            if ($options['not_customized']) {
                // Filter for non-customized strings only.
                $conditions['customized'] = LOCALE_NOT_CUSTOMIZED;
            }
            else {
                // Filter for strings without translation.
                $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);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal