How programmatically translate vocabolary name

Created on 13 November 2023, 8 months ago
Updated 14 November 2023, 8 months ago

Problem/Motivation

I want to translate taxonomy vocabolary name programmatically.
I load vocabolary entity but i dont' have "hasTranslation" and "addTranslation" function to do that.

How i can achieve this?
Thank you in advance

💬 Support request
Status

Closed: works as designed

Version

10.1 ✨

Component
Transliteration  →

Last updated 7 months ago

Created by

🇮🇹Italy trickfun

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @trickfun
  • 🇮🇹Italy trickfun

    I found the solution.
    I need to translate config.

    
    $config_factory = \Drupal::service('config.factory');
    $config = $config_factory->getEditable('taxonomy.vocabulary.myvocabolary');
            if($config){
    
              $key = $config->getName();
              $data  =$config->get();
    
              $data['langcode'] = $langcode;
              $data['name'] = $translated_name;
    
              $trans = \Drupal::languageManager()->getLanguageConfigOverride($langcode, $key);
              $trans->merge($data);
              $trans->save();
            }
    
  • Status changed to Closed: works as designed 8 months ago
  • 🇺🇸United States cilefen
Production build 0.69.0 2024