class CustomStrings

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/StringTranslation/Translator/CustomStrings.php \Drupal\Core\StringTranslation\Translator\CustomStrings
  2. 10 core/lib/Drupal/Core/StringTranslation/Translator/CustomStrings.php \Drupal\Core\StringTranslation\Translator\CustomStrings
  3. 11.x 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

Title Sort descending Modifiers Object type Summary Overriden Title 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 1
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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.