How programmatically translate facet name

Created on 14 November 2023, 8 months ago

Problem/Motivation

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

$facets = \Drupal::entityTypeManager()->getStorage('facets_facet')->loadMultiple();
foreach($factes as $facet){
        $facet->set('name', $name);
        $facet->save();

        //missing hasTranslation and addTranslation
}

How i can achieve this?
Thank you in advance

💬 Support request
Status

Active

Version

3.0

Component

Miscellaneous

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('facets.facet.myfacet');
            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();
            }
    
Production build 0.69.0 2024