5

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?

5

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.

4
  • 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 '19 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 '19 at 17:32
  • It appears that you can uninstall the Actions module after doing the translations. At least, I've not run into any bugs so far, and the translations are still there. I'll come back if I discover otherwise.
    – Jaypan
    Jun 30 at 21:16
  • Yes, Action configuration is part of the system module and is not affected by uninstalling the Actions UI module.
    – 4k4
    Jul 1 at 6:39
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);
    }
}
15
  • 2
    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 '19 at 21:02
  • @leymannx I've tested it before and works.
    – Yuseferi
    Mar 22 '19 at 21:14
  • 1
    Variables should not be passed through the t() function. It may work, but it can open up security vulnerabilities.
    – Jaypan
    Mar 29 '19 at 2:54
  • 1
    From the documentation: It is especially important never to call new TranslatableMarkup($user_text) or t($user_text) where $user_text is some text that a user entered -- doing that can lead to cross-site scripting and other security problems. api.drupal.org/api/drupal/…
    – Jaypan
    Jul 9 '19 at 22:41
  • 1
    Well, the security reason is only one reason not to use variables in the t() function. See the documentation page I linked to above. If you want to pass variables through t(), that's your choice, but it's considered a bad practice.
    – Jaypan
    Jul 11 '19 at 5:04

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.