I'm currently trying to translate my twig template to the current language and at this moment I'm getting the following error
InvalidArgumentException: Invalid translation language (fr) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 872 of /Applications/XAMPP/xamppfiles/htdocs/iom/core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Here is a snippet of code that I'm currently working on
// Page-level pre-processing
function iom_preprocess_page(&$variables) {
$language = \Drupal::languageManager()->getCurrentLanguage();
$variables['lang_code'] = $language->getId();
}
{% if (language.getId() == 'fr') %}
<li class="tab">{{ tab_label.entity.field_tab_title.entity.translation('fr').label }}</li>
{% else %}
<li class="tab">{{ tab_label.entity.field_tab_title.entity.label }}</li>
{% endif %}
Somehow this part right here is what seems to be causing the error even though the language is currently correct
<li class="tab">{{ tab_label.entity.field_tab_title.entity.translation('fr').label }}</li>
lang_code
notlanguage.getId()
something like{% if tab_label.entity.hastranslation(lang_code) %} {{ tab_label.entity.translation(lang_code).field_tab_title.entity.label }}