1

I load the vocabulary with taxonomy_vocabulary_load($vocabulary_id).

How can I can translate its label in the language currently used?

1

It will be default by the current language.

There are only two ways to get something else, unfortunately:

a) Use ConfigEntityStorage::loadOverrideFree to load a config entity without overrides, then it is in the default language of that entity, which is what language() returns.

b) You can set the current config language and then load the entity. See for example user_mail function :

  <?php
  // Get the current language and override it.
  $language_manager = \Drupal::languageManager();
  $language = $language_manager->getLanguage($desired_langcode);
  $original_language = $language_manager->getConfigOverrideLanguage();
  $language_manager->setConfigOverrideLanguage($language);

  // Do your thing here.

  // Restore the config language.
  $language_manager->setConfigOverrideLanguage($original_language);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.