Drush provides dt() as a wrapper to t() and if t is not available it fallbacks to a simple but enough call to strtr(). So the only advantage of this is to allow for a localized drush --only when it runs on a bootstrapped site.
I don't think localizing drush has any utility, moreover it can be an obstacle for scripting purposes. Also, some argument-symbol is rendered as an undesirable <em>message</em>.
Well, although t() is a bunch of code including several db accesses (if using locale.module) it seems that removing it is not much of a performance gain, but I still think it worth it.
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | drush-1159146.patch | 17.7 KB | jonhattan |
| #19 | drush-1159146.patch | 17.7 KB | jonhattan |
| #17 | drush-1159146.patch | 17.5 KB | jonhattan |
| #12 | drush-1159146.patch | 1.17 KB | jonhattan |
Comments
Comment #1
jonhattanAs a side node, some of drush commands do
'description' => dt(...)in hook_command() while others don't. The standard is to not do it.Comment #2
greg.1.anderson commentedIf the standard is to not use dt() in some places, are there any other places where it should be used? It does not seem to make sense to me to use dt() for output if it is not used for command descriptions. If we are not to use dt() in command descriptions, should we perhaps just eliminate the dt() function completely, and make all drush strings 'raw'? (That is, is the dt substitution capability better than simple concatenation if we are never going to localize?)
Comment #3
moshe weitzman commentedWhat do commands like `git` and `mysql` do for localization of help texts, error messages, etc?
Comment #4
greg.1.anderson commentedgettext, mostly. Although I cannot say for certain what any particular project is using, this is the most common answer for Linux tools written in C. There are gettext equivalents for many other languages, including php.
Not sure that drush should change, but there is your answer.
Comment #5
moshe weitzman commentedOK, the take away is that they offer localization. Then drush should do so also. Am open to more discussion, but thats my first take. I'm not too clear on what the 'scripting purposes' problem is. I guess you are saying that a calling script can no longer depend on any given string as output because of localization. Surely there are solutions for that.
Comment #6
greg.1.anderson commentedSo we are clear then that the standard is to use dt in command descriptions? At least in an ideal world they should all be there, right?
Comment #7
moshe weitzman commentedYes, I agree that command descriptions should have dt().
FYI, there are complete translations of Drush in Spanish and Danish. Partial translations in many other languages. See http://localize.drupal.org/translate/projects/drush
Comment #8
jonhattanspanish translation! it was not me! to use this translation it is needed to import it manually per site... l10n_update is not of help here.
For the scripting purposes I mean to parse the output. With 'svn', 'mysql', etc you can prepend
LANG=Cto the command and obtain untranslated output. Perhaps we could pass a flag to drush to do so and force lang=en in drupal.Also, we only benefit from t() translations when drupal is bootstrapped. Switching to gettext will fix this but we loose the translations already present in modules integrating with drush. We can complex the logic and use both gettext and t() when available. Also, the option for gettext will be to ship a bunch of .po/.mo files with drush? I see this unpractical.
On hook_command(): it is analogous to hook_menu() and t() is not used there for items definition. Strings are passed through t() in the calling function. In drush some commandfiles do use dt() others no.
In case I was not clear my proposal, in summary, is to not support translations and reduce dt() to strtr() --only useful for strings with placeholders.
Comment #9
DjebbZ commentedI'm in favor of keeping the translation possibility (the dt() function), and if scripting is a problem an option like
lang=enmay solve the problem.Comment #10
jonhattanRe-reading #8 I realize I was confusing in my writting. Sorry for that, I was in a hurry and did not review.
1. some drush commands are using dt() for its description while others no. If drush is supporting localization this needs to be fixed. I propose to let drush_get_commands() do the translations instead of filling the commands definitions with dt(). That is similar to what drupal does for hook_menu() in http://api.drupal.org/api/drupal/includes--menu.inc/function/_menu_item_... .
Attached is a patch for that. To complete this patch all calls to dt() in command definitions must be removed.
2. OTOH for drush to be fully translatable the solution can't rely on t() as it only works when there's a bootstrapped site and also it needs the drush translation to be imported per site (and l10n-update won't help as it is based on installed modules --drush isn't one).
A remedy to this is to use gettext as mentioned. We can use a script to rip translations off localize.drupal.org periodically and push them to drush repo. A counterpart of going this way and removing t() is that translation of modules integrating with drush will not be available, perhaps a minor thing.
Also consider drush can obtain the cli user's language from a env variable (as 'mysql', 'git', etc does) but it may be different from a site's language.
So I think that in practice users will use drush in english and doesn't worth it to implement gettext support or mix gettext with t() to completely cover all translated strings.
Comment #11
DjebbZ commentedOk I understand your point now. I thought you wanted to drop all kind "translatability". I'm not a core Drush developer, but including t() calls as you say in 1 seems a good idea. But where is your patch ?
As of 2, I have no idea what's the best. Maybe a drush command like
drush self-translate --lang=[language code from localize.d.o]could do the heavy work for us ?Comment #12
jonhattanthe patch.
Comment #13
moshe weitzman commentedI think this patch will work fine. Lets send along an array to dt() if an array is provided (i.e. description with placeholders).
Comment #14
anarcat commentedI would object to dropping t() from dt(). A bunch of stuff is already translated in the frontend and while it depends on the bootstrapped site, it's better than nothing - reinventing the wheel there and re-translating everything just seems like a real bad idea...
I agree with the side not of making the commands descriptions translation more standard however, but - that is a side note here. :)
As for worries about scripting, if you script relies on translatable content or plain strings, you are doing something wrong. You should:
* use --pipe, or;
* use --backend
Furthermore, you can always resent the translation through the environment, or at least that how gettext() works and it's mostly standard now:
Comment #15
greg.1.anderson commentedWould it be possible to add some code to dt() that, instead of calling through to t() would instead use a option (e.g. $options['translation-files'] in drushrc.php) to point at some drupal root where translation files could be found? Would that add too much code bloat to drush?
Comment #16
anarcat commentedYou would probably want to use gettext() directly at that point, in my opinion. The trick would be to find the files, but once it's done, since Drupal was smart enough to use that standard format, we could just use the builtin gettext() extensions instead of doing our crazy parsing:
http://php.net/manual/fr/function.gettext.php
This way drush itself could provide .po files the Drupal community knows and loves, and they would be useable even if drush wouldn't bootstrap a database.
Comment #17
jonhattanSame patch of #12 with the suggestion from #13, as:
'description' => array('a !text with placeholders', array('!text' => 'string'));and also remove all occurences of dt() in the several hook_command() implementation.
Comment #18
anarcat commentedAPI docs on the two new functions would be nice...
Comment #19
jonhattanCommited with docstrings. Attached the patch for backport to 4.x.
I've opened a new issue for the gettext(): #1162694: Switch from t() to gettext().
Comment #20
jonhattanThere was a bug 'in a 'string''.
Comment #21
msonnabaum commentedBackported.
Comment #22
jonhattanfor the record, about scripting:
this output is half localized.