You are here

class StringOverridesTranslation in String Overrides 8

Provides string overrides.

Hierarchy

Expanded class hierarchy of StringOverridesTranslation

1 string reference to 'StringOverridesTranslation'
stringoverrides.services.yml in ./stringoverrides.services.yml
stringoverrides.services.yml
1 service uses StringOverridesTranslation
string_translator.stringoverrides in ./stringoverrides.services.yml
Drupal\stringoverrides\StringOverridesTranslation

File

src/StringOverridesTranslation.php, line 15
Contains \Drupal\stringoverrides\StringOverridesTranslation.

Namespace

Drupal\stringoverrides
View source
class StringOverridesTranslation extends StaticTranslation {

  /**
   * {@inheritdoc}
   */
  protected function getLanguage($langcode) {
    $cid = 'stringoverides:translation_for_' . $langcode;
    if ($cache = \Drupal::cache()
      ->get($cid)) {
      return $cache->data;
    }
    else {
      $translations = [];

      // Drupal configuration array structure is different from translations
      // array structure, lets transform configuration array.
      $config = \Drupal::config('stringoverrides.string_override.' . $langcode);
      $contexts = $config
        ->get('contexts');
      if (!empty($contexts)) {
        foreach ($contexts as $context) {
          foreach ($context['translations'] as $word) {
            $translations[$context['context']][$word['source']] = $word['translation'];
          }
        }
      }
      \Drupal::cache()
        ->set($cid, $translations);
      return $translations;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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
StaticTranslation::__construct public function Constructs a translator from an array of translations. 2
StringOverridesTranslation::getLanguage protected function Retrieves translations for a given language. Overrides StaticTranslation::getLanguage