I load the vocabulary with taxonomy_vocabulary_load($vocabulary_id).

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


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 :

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

  // Do your thing here.

  // Restore the config 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.