protected function StringOverridesTranslation::getLanguage in String Overrides 8
Retrieves translations for a given language.
Parameters
string $langcode: The langcode of the language.
Return value
array A multidimensional array of translations, indexed by the context the source string belongs to. The second level is using original strings as keys. An empty array will be returned when no translations are available.
Overrides StaticTranslation::getLanguage
File
- src/
StringOverridesTranslation.php, line 20 - Contains \Drupal\stringoverrides\StringOverridesTranslation.
Class
- StringOverridesTranslation
- Provides string overrides.
Namespace
Drupal\stringoverridesCode
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;
}
}