The Drupal Console is Now Multilingual

The Drupal Console is Now Multilingual

FFW Blog - illustration
default avatar
Thought byJesus Olivas
Drupal 8 Solution Architect
January 21, 2015

We're very pleased to announce that the new Drupal Console project is now multilingual!

We put a lot of hours into this effort because we felt it was so important to broaden the base of Console users and help them get off to a great start developing modules for Drupal 8. It will be the last major feature to be added before an upcoming code freeze that will allow us to work on Console documentation - another effort to broaden the base of users that can benefit from the project.

Here are a few reasons why we felt it was so important to add multilingual capabilities to the Console project:

  • Drupal is multilingual and Drupal 8 is even more so than ever. Take a look at D8MI at  We want to ship this project with capabilities like these.
  • It feels good and more natural to use a tool on your mother tongue. Most of our project contributors are not native english speakers.
  • Separating messages from code will ease the text messages updates, no need to know/learn PHP or use an IDE to contribute.
  • David Flores & myself will be presenting a sesion in Spanish related to this project at the DrupalCon Latino in Bogota and we knew making the project multilingual would be interesting for the event audience.

As I mentioned on twitter:

But we needed a starting point.

Talking about code, this is what was required

Adding the Symfony Translation Component to the composer.json file

"require": {
+   "symfony/config": "2.6.*",
+   "symfony/translation": "2.6.*",

For more information about the Translation Component look the awesome symfony documentation here.

Add translation files and messages

# extract of config/translations/console.en.yml
      description: Rebuild and clear all site caches.
        cache: Only clean a specific cache.
        welcome: Welcome to the cache:rebuild command.
        rebuild: Rebuilding cache(s), wait a moment please.
        completed: Done cleaning cache(s).
        invalid_cache: Cache "%s" is invalid.
        cache: Select cache.

Create a new Helper class

In order to take care of the translation the TranslatorHelper class was added and the Helper was also registered at bin/conosle.php.

Inject the TranslatorHelper

For this task it was necessary to modify the RegisterCommandsHelper class, obtaining the TranslatorHelper and Injecting via the constructor when creating and registering a new instance of each command.

if ($cmd->getConstructor()->getNumberOfRequiredParameters()>0) {
  $translator = $this->getHelperSet()->get('translator');
  $command = $cmd->newInstance($translator);
else {
  $command = $cmd->newInstance();

How to override the default language

As simple as creating a new YAML file at your home directory ~/.console/config.yml and override the language value.

#file path ~/.console/config.yml
  language: es

How to make a console.phar

We are using and recommend this great project

$ curl -LSs | php
$ mv box.phar /usr/local/bin/box

// Run this inside your project directory to create a new console.phar file
$ box build

Feel free to try this new multilingual feature on the latest release v0.6.0, and as usual feel free to ask any questions commenting on this page, or adding a new issue on the drupal project page or the github repository.

I mentioned earlier that we are moving toward a code freeze so we can focus on documentation. The freeze is expected to be in place for about 4 weeks. I'll also use the time to prepare my DrupalCon Latino  Console presentation with David Flores aka @dmouse.

Stay tuned!

This post has been adapted from my personal blog.

Drupal Console

Fill out the form to learn how FFW can support your needs.

Read next:

Drupal Component Composer Console

The ABC's of Drupal: Component, Composer, Console

FFW Rocks DrupalCon

Community, Connections, Console & Personalization. FFW Rocks DrupalCon.

Drupal Console

Drupal Console: An Overview of the New Drupal CLI

FFW Blog - illustration

Drupal 8 Right Now: Console Workflow