class StringOverridesTranslation in String Overrides 8
Provides string overrides.
Hierarchy
- class \Drupal\Core\StringTranslation\Translator\StaticTranslation implements TranslatorInterface
- class \Drupal\stringoverrides\StringOverridesTranslation
Expanded class hierarchy of StringOverridesTranslation
1 string reference to 'StringOverridesTranslation'
1 service uses StringOverridesTranslation
File
- src/
StringOverridesTranslation.php, line 15 - Contains \Drupal\stringoverrides\StringOverridesTranslation.
Namespace
Drupal\stringoverridesView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StaticTranslation:: |
protected | property | String translations | |
StaticTranslation:: |
public | function |
Retrieves English string to given language. Overrides TranslatorInterface:: |
|
StaticTranslation:: |
public | function |
Resets translation cache. Overrides TranslatorInterface:: |
|
StaticTranslation:: |
public | function | Constructs a translator from an array of translations. | 2 |
StringOverridesTranslation:: |
protected | function |
Retrieves translations for a given language. Overrides StaticTranslation:: |