StringOverridesTranslation.php in String Overrides 8
File
src/StringOverridesTranslation.php
View source
<?php
namespace Drupal\stringoverrides;
use Drupal\Core\StringTranslation\Translator\StaticTranslation;
class StringOverridesTranslation extends StaticTranslation {
protected function getLanguage($langcode) {
$cid = 'stringoverides:translation_for_' . $langcode;
if ($cache = \Drupal::cache()
->get($cid)) {
return $cache->data;
}
else {
$translations = [];
$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;
}
}
}