diff --git a/src/StringTranslationTrait.php b/src/StringTranslationTrait.php index 435de5e..b233e2f 100644 --- a/src/StringTranslationTrait.php +++ b/src/StringTranslationTrait.php @@ -36,6 +36,16 @@ trait StringTranslationTrait { if (empty($options['context'])) { $options['context'] = $this->translationContext; } + // Attempt to get the current string translation for the 'shs' context. + if (!empty($this->stringTranslation)) { + $langcode = \Drupal::service('language_manager')->getCurrentLanguage()->getId(); + $translation = $this->stringTranslation->getStringTranslation($langcode, $string, $options['context']); + // If the string doesn't have a translation for this context, fallback to + // to the string translation without context (default). + if (empty($translation)) { + unset($options['context']); + } + } return $this->tCore($string, $args, $options); }