How programmatically translate vocabolary name

Created on 13 November 2023, about 1 year ago
Updated 14 November 2023, about 1 year 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 3 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 about 1 year ago
Production build 0.71.5 2024