Drupal's data is always in UTF-8 but console is not. It makes trouble to use drush with sites where default language is not english.
In my case shell code page is KOI8-R and site default language is russian. In order to get right output I pipe drush with command 'iconv -f UTF-8 -t KOI8-R' to convert characters from UTF-8 to KOI8-R. It works until drush wait input from user (like y/n question). In the last case drush hungs.

Drush have to determine console code page automatically and make such conversion by oneself. Or drush have to have option (cmdline and drushrc) to convert output to the specified encoding.

CommentFileSizeAuthor
#6 output_charset.patch1.3 KBv.sidorov

Comments

greg.1.anderson’s picture

It would be pretty easy to wrap output with php iconv in drush_print() et. al. if an appropriate option is set in drushrc.php. It also seems that UTF-8 should work just fine with the right system configuration and terminal, but I see no reason why drush couldn't also support older encodings.

Patches welcome.

v.sidorov’s picture

Added option output_charset to translate output from UTF-8. Option can be specified in command line as

--output_charset=ISO-8859-1

or in drushrc.php as

$options['output_charset'] = 'ISO-8859-1'

Patch here.

includes/drush.inc:

--- includes/drush.inc.orig     Thu Apr 22 20:57:40 2010
+++ includes/drush.inc  Thu May 13 14:53:34 2010
@@ -791,7 +791,12 @@
  *    The indentation (space chars)
  */
 function drush_print($message = '', $indent = 0) {
-  print str_repeat(' ', $indent) . (string)$message . "\n";
+  $msg = str_repeat(' ', $indent) . (string)$message . "\n";
+  $charset = drush_get_option('output_charset');
+  if ($charset) {
+    $msg = iconv('UTF-8', $charset, $msg);
+  }
+  print $msg;
 }

 /**
@@ -972,7 +977,7 @@
   }

   $tbl->addData($newrows);
-  print $tbl->getTable();
+  drush_print($tbl->getTable());
   return $tbl;
 }

examples/example.drushrc.php:

--- examples/example.drushrc.php.orig   Thu May 13 15:42:14 2010
+++ examples/example.drushrc.php        Thu May 13 15:45:15 2010
@@ -119,6 +119,16 @@
 );

 /*
+ * The output charset suitable to pass to iconv PHP function as out_charset
+ * parameter. Drush will convert its output from UTF-8 to specified here
+ * charset. It is possible to use //TRANSLIT and //IGNORE charset name suffixes
+ * (see iconv documentation). If not defined conversion will not perform.
+ */
+# $options['output_charset'] = 'ISO-8859-1';
+# $options['output_charset'] = 'KOI8-R//IGNORE';
+# $options['output_charset'] = 'ISO-8859-1//TRANSLIT';
+
+/*
  * Command-specific options
  *
  * To define options that are only applicable to certain commands,
v.sidorov’s picture

Do you accept this patch?

greg.1.anderson’s picture

The code looks good, but I'm travelling on business this week and last week, and won't have a chance to look at it until next week. You could increase your odds that some other maintainer might take a look if you rolled a .patch file and set the status of the issue to "needs review". (Heck, I might forget to come back to this issue if you don't do that...)

moshe weitzman’s picture

code looks good from my perspective as well. In addition to a real patch file, I'd love some instructions on how to test this using OSX.

v.sidorov’s picture

Status: Active » Needs review
StatusFileSize
new1.3 KB

Patch file attached. Status changed.

To test this... It is really not easy. Lets try this scenario.

  1. Configure you console to use ISO-8859-1 code page.
  2. Take any existing module and edit it's module.info file. Change description line to that containing umlaut characters (Ö, Ü, â, ê, etc). You can paste and copy it from here. Save module.info file encoded in UTF-8.
  3. Go to admin/modules drupal web page and make sure description of changed module looks as expected - with umlauts.
  4. Run drush pm-info command with the name of changed module. You should get some garbage in place of umlauts.
  5. Now run drush --output_charset=ISO-8859-1 pm-info. All characters should be printed correctly.
moshe weitzman’s picture

Status: Needs review » Fixed

The patch wouldn't apply for me (See diff and patch page for help). But I copied the changes and your test steps worked out perfectly so I committed this.

v.sidorov’s picture

Status: Fixed » Needs review

Please commit the following code to examples/example.drushrc.php file as a bit of documentation. Otherwise there is no info about output_charset option. Thank you.

/*
 * The output charset suitable to pass to iconv PHP function as out_charset
 * parameter. Drush will convert its output from UTF-8 to specified here
 * charset. It is possible to use //TRANSLIT and //IGNORE charset name suffixes
 * (see iconv documentation). If not defined conversion will not perform.
 */
# $options['output_charset'] = 'ISO-8859-1';
# $options['output_charset'] = 'KOI8-R//IGNORE';
# $options['output_charset'] = 'ISO-8859-1//TRANSLIT';
moshe weitzman’s picture

Status: Needs review » Fixed

#797700 by v.sidorov | greg.1.anderson: Added Convert drush output to terminal console code page.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.