3

I'm using Umami profile and choose Spanish is default language. Almost of the interface has been translated into Spanish. But some places did not translate like user page.

enter image description here

I'm going to admin/config/regional/translate to check. But This text already translated, but UI still show English text.

enter image description here I try debug to find the reason. I was break point at line 340 of line drupal/core/modules/views/src/Plugin/views/field/BulkForm.php and found that $action->label() return English string.

enter image description here

Because at line 116 $this->actionStorage->loadMultiple() return all actions. In this some actions return English string, some actions return Spanish string (example install module pathauto, this action return Spanish). All actions when install profile will using English text and module install after will be translate.

enter image description here

I don't know why. And How to can translate label of actions?

2

To translate action labels install the core module Actions and go to /admin/config/regional/config-translation/action.

Actions are config entities, which you can translate in an exported config as well, if you don't want to install the UI option.

  • Thank you for support. Do you why all core config entities did not translate? But config entities from other modules (install after default) will be translated. – Jonh Mar 25 at 16:12
  • When the config entities are created on installation they are parsed through user interface translation. There might be a timing issue downloading translations and creating those entities. But I think installing the Actions module is the way to go if you want to correct this after installation. – 4k4 Mar 25 at 17:32
0

you can translate them easily in form_alter hook. This is one of charming Drupal features that I love. form_alter

/**
 * Implement of hoo_form_later
 */
function YOURMODULENAME_form_alter(&$form, $form_state, $form_id) {

  if($form_id ='views_exposed_form' && isset($form['header']['node_bulk_form']['action']['#options'])){
    foreach($form['header']['node_bulk_form']['action']['#options'] as $key =>$option){
      $form['header']['node_bulk_form']['action']['#options'][$key] = t($option);
    }
}
  • 1
    The "You should never use t() to translate variables" doesn't count anymore for D8? api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/… – leymannx Mar 22 at 21:02
  • @leymannx I've tested it before and works. – Yusef Mohamadi Mar 22 at 21:14
  • @YusefMohamadi thank you for support. But I think this way does not good. Because It's not convenient. Suppose we have 20 roles, so we need to translate 40 strings (add+remove roles). And this ways does not resolved root of cause. When you load all config entity action why some actions install after finish install profile will return string translated? – Jonh Mar 23 at 3:42
  • @Jonh you're welcome, if it has been translated on the core it shows the translated text else it's the core issue. btw, this is a convenient solution and 100% works. I've tested it. hope to find a better solution but it's really very hard to achieve it without patching the core or this convenient solution. – Yusef Mohamadi Mar 23 at 7:28
  • Variables should not be passed through the t() function. It may work, but it can open up security vulnerabilities. – Jaypan Mar 29 at 2:54

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.