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

Breadcrumb

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

function LocaleConfigManager::getStringTranslation

Get the translation object for the given source/context and language.

Parameters

string $name: Name of the configuration location.

string $langcode: Language code to translate to.

string $source: The source string, should be English.

string $context: The string context.

Return value

\Drupal\locale\TranslationString|false The translation object if the string was not empty or FALSE otherwise.

File

core/modules/locale/src/LocaleConfigManager.php, line 438

Class

LocaleConfigManager
Manages configuration supported in part by interface translation.

Namespace

Drupal\locale

Code

public function getStringTranslation($name, $langcode, $source, $context) {
    if ($source) {
        $this->translateString($name, $langcode, $source, $context);
        if ($string = $this->translations[$name][$langcode][$context][$source]) {
            if (!$string->isTranslation()) {
                $conditions = [
                    'lid' => $string->lid,
                    'language' => $langcode,
                ];
                $translation = $this->localeStorage
                    ->createTranslation($conditions);
                $this->translations[$name][$langcode][$context][$source] = $translation;
                return $translation;
            }
            else {
                return $string;
            }
        }
    }
    return FALSE;
}

API Navigation

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