You are here

class CustomStrings in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/StringTranslation/Translator/CustomStrings.php \Drupal\Core\StringTranslation\Translator\CustomStrings
  2. 9 core/lib/Drupal/Core/StringTranslation/Translator/CustomStrings.php \Drupal\Core\StringTranslation\Translator\CustomStrings

String translator using overrides from variables.

This is a high performance way to provide a handful of string replacements. See settings.php for examples.

Hierarchy

Expanded class hierarchy of CustomStrings

1 string reference to 'CustomStrings'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses CustomStrings
string_translator.custom_strings in core/core.services.yml
Drupal\Core\StringTranslation\Translator\CustomStrings

File

core/lib/Drupal/Core/StringTranslation/Translator/CustomStrings.php, line 14

Namespace

Drupal\Core\StringTranslation\Translator
View source
class CustomStrings extends StaticTranslation {
  use DependencySerializationTrait;

  /**
   * The settings read only object.
   *
   * @var \Drupal\Core\Site\Settings
   */
  protected $settings;

  /**
   * Constructs a CustomStrings object.
   *
   * @param \Drupal\Core\Site\Settings $settings
   *   The settings read only object.
   */
  public function __construct(Settings $settings) {
    parent::__construct();
    $this->settings = $settings;
  }

  /**
   * {@inheritdoc}
   */
  protected function getLanguage($langcode) {
    return $this->settings
      ->get('locale_custom_strings_' . $langcode, []);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CustomStrings::$settings protected property The settings read only object.
CustomStrings::getLanguage protected function Retrieves translations for a given language. Overrides StaticTranslation::getLanguage
CustomStrings::__construct public function Constructs a CustomStrings object. Overrides StaticTranslation::__construct
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
StaticTranslation::$translations protected property String translations.
StaticTranslation::getStringTranslation public function Retrieves English string to given language. Overrides TranslatorInterface::getStringTranslation
StaticTranslation::reset public function Resets translation cache. Overrides TranslatorInterface::reset