Closed (fixed)
Project:
CAPTCHA
Version:
5.x-3.x-dev
Component:
User interface
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
20 Jul 2007 at 21:42 UTC
Updated:
7 Sep 2007 at 09:02 UTC
Jump to comment: Most recent file
Comments
Comment #1
soxofaan commentedIn my original rewrite I tried to address this, but apparently I got it a bit wrong. CAPTCHA_DESCRIPTION occurs at two places (the define() not including).
The first one (line 190 of revision 1.42.2.11 of captcha.module) should be
'#default_value' => variable_get('captcha_description', CAPTCHA_DESCRIPTION),instead of
'#default_value' => t(variable_get('captcha_description', CAPTCHA_DESCRIPTION)),(no translation on the settings page)
the second one (line 283 of revision 1.42.2.11 of captcha.module) should be
$captcha_description = t(variable_get('captcha_description', CAPTCHA_DESCRIPTION));instead of
$captcha_description = variable_get('captcha_description', CAPTCHA_DESCRIPTION);(translatable on challenge)
Maybe some more description should be added to line 189 to note that the string can/will be translated
Comment #2
soxofaan commentedpatch to do the thing from #1
Comment #3
robloachThat won't do it because you have to pass the string directly to t() as the default for variable_get().... See the attached patch.
Comment #4
robloach#74808
Comment #5
soxofaan commentedWhy?
If I get your patch (#3) correctly, your solution won't work either: if the variable
captcha_descriptionis set (through the settings page), it will be used as description, while the default valuet('This question ....')(which does the localization) won't be used. The variablecaptcha_descriptioncould of course written in the desired language, but if you have a multi-lingual site, you're stuck because the description can only be in one language.With my patch (#2) however, the description in the settings page is/should be English (no translation), while on the captcha challenge the right translation for the user is picked. Translation is done with the standard drupal localization.
In short: your patch only translates the default value,
while my patch translates the description itself, independent if the default value is overwritten or not.
Comment #6
robloachRead the documentation on t() and you'll see why I translate the static string instead of the dynamically changing captcha_description variable in the database. The difference between what you proposed and what I proposed is this:
You want to translate the default value so that if they have a site in Spanish, they'll see the Spanish translation by default. If they want to change the description, they can. It's assumed that they'd write this new description already in their desired language. Also, you can't use
t()to translate something that's dynamic and can change (likevariable_get).If you had read the documentation on
t(), you'd understand that it only takes a static string. If you have anything dynamic, you'd pass it into the second argument. If we use your method, usingt()properly would turn the call into something like this:.... And that's really not right ;-) .
Comment #7
soxofaan commentedI read documentation, I even bought the pro drupal development book. So don't worry about that.
The documentation on
t($string, ...)does not explicitly state that$stringshould be static (whatever that could mean). But I understand that it could feel wrong to use a "dynamic-ish" string. The string indeed comes from the database, but it is not that dynamic that it could change every day. My idea is just: on the settings page the admin sets the captcha_description string (in English, like all default strings in drupal), and this string can be translated to all desired languages through the locale module.The documentation does indeed say something about parts in the string that could change and to use placeholders for that, but in this case it's about the whole string, so placeholders are not a part of the equation..
I understand however that my patch is a bit controversial and wouldn't be accepted in its current state.
On the other hand, the patch that you propose in #3 (and already committed) won't work either for multilingual sites, as I already tried to explain in #5. I, for example, live in Belgium, which has three official languages: Dutch, French and German, so the multilingual capabilities of a CMS are important over here. In your patch the
t()is only around the default captcha_description:If an admin defines a different string, there is no
t()to catch that, so it can't be translated. Well, it can be translated by the admin in only one language (e.g. Dutch) in the text field directly, but translation to other languages (French and German) is not possible.You need an "outer"
t()around thevariable_get()for this (like in my patch).Conclusion: I think this issue isn't fixed, yet.
Comment #8
soxofaan commentedOne simple option is to remove the configurability of the captcha_description and just use a hardcoded but translatable string.
So, no more
variable_get('captcha_description', t('This question is used to make sure you are a human visitor and to prevent spam submissions.'))but just
t('This question is used to make sure you are a human visitor and to prevent spam submissions.')and delete all form stuff, database interaction and conditionals for the
captcha_description.For a bit more admin control we could add a toggle 'show captcha description or not' to the settings page.
Comment #9
soxofaan commented@Rob:
I experimented a bit with captcha.module revision 1.42.2.13 (which is with patch from #3).
It appears that this version behaves like I propose after all and not like you intended ;)
As you see on line 296, the what you call 'dynamic' captcha description
$captcha_descriptionstill gets passed to the translation functiont().So revision 1.42.2.13 is how I propose to do translation of the captcha description, except that there is one extra (and unneeded) call to
t()in line 104. And it works in a multilingual setting (different users with different languages).Comment #10
robloachString translation: why using t() for user specified text is evil
Comment #11
robloachJust changing the status of this.
Comment #12
soxofaan commentedWell, that's weird,
because this issue is fixed in the way you heavily argued against:
Line 296 (of captcha.module version 1.42.2.15) still translates a user defined string with
t():(also see #9)
Comment #13
robloachGood eyes ;-) .
Comment #14
heine commentedAs far as I can tell, this issue is not fixed.
Comment #15
robloachI removed the extra call to t() that you mentioned in #9 and #12. Everything else is fixed because sending in custom user defined strings to t() is evil. That was the major issue here, and it's resolved. I've tested this myself and it works...
Comment #16
heine commentedI believe I tried to explain in IRC, but apparantly I failed.
The issue is not that sending user defined strings to t() is evil, it is that the user defined string cannot be translated when another locale is in use. This is troublesome for multilingual sites (Dutch/French, Dutch/Frisian for example) which may even be required by law in certain regions.
Comment #17
soxofaan commentedI agree completely and I also tried to explain this (see #5 and #7).
A possible (simple) solution (see #8) is to make the captcha description not configurable so it can be fed to
t()without problems. However this feels giving up to much flexibility.This issue is indeed not fixed
Comment #18
robloachSo please submit a patch to fix it and make Heine review it. Although I do know that this works with a one language site (English, Dutch, etc), I don't know how it performs in a multi-lingual environment (when you could have mysite.com, mysite.eu, mysite.cn, etc). This was a simple little issue that I thought I resolved and I'm honestly quite tired of seeing it on my issue queue.
Comment #19
soxofaan commentedThis patch makes the captcha module do the following:
When the locale module is not enabled, nothing changes: just one captcha description available/configurable.
When the locale module is enabled (multilingual sites): a captcha description can be set for each enabled language. On challenge generation the description corresponding with the user's locale will be used (default locale for unauthenticated users, chosen locale for authenticated users)
Comment #20
soxofaan commentedminor update of my patch of #19:
added a bit of documentation and tweaked some UI strings
Comment #21
robloachAhh, that's how you do it. Thanks! Note that I haven't reviewed this, just quickly took a look.
Comment #22
robloachReviewed and tested..... Nicely going. I never looked at the locale module.
Comment #23
soxofaan commentedfixed by commit http://drupal.org/cvs?commit=78720 apparently
Comment #24
(not verified) commented