[dev] [commits] Horde branch master updated. 0b14c18084d8fc19f2f20a316fdabef73fb1f570

Michael M Slusarz slusarz at horde.org
Tue Jan 28 17:42:55 UTC 2014


Quoting Jan Schneider <jan at horde.org>:

> Zitat von Michael M Slusarz <slusarz at horde.org>:
>
>> Quoting Michael M Slusarz <slusarz at horde.org>:
>>
>>> commit e8e8c48d6fffb73c3d9252a8ea3656cf1efb0cc1
>>> Author: Michael M Slusarz <slusarz at horde.org>
>>> Date:   Tue Jan 28 00:07:33 2014 -0700
>>>
>>>   [mms] Add Horde_Translation#gettext_define().
>>>
>>>   Allows access to the original (English) text while still allowing text
>>>   to be translated.
>>>
>>> framework/Translation/lib/Horde/Translation.php              |    
>>> 31 ++++++++-
>>> framework/Translation/package.xml                            |   12 ++--
>>> framework/Translation/test/Horde/Translation/WrapperTest.php |    3 +
>>> 3 files changed, 36 insertions(+), 10 deletions(-)
>>>
>>> http://github.com/horde/horde/commit/e8e8c48d6fffb73c3d9252a8ea3656cf1efb0cc1
>>
>> Read the gettext/PHP documentation for hours, and I believe this is  
>> necessary since there is no built-in (or previously Horde  
>> implemented) way of being able to both:
>>
>> 1. Grab the original English gettext message in PHP code
>> 2. Have the string be recognized by the translation extraction script.
>>
>> Please let me know if I have missed something.
>>
>> michael
>>
>> ___________________________________
>> Michael Slusarz [slusarz at horde.org]
>
> The question is what are using this for? What we currently do when  
> we need English text, e.g. to be able to parse certain messages, is  
> to temporarily switch the locale to C. Works fine and switching  
> locales is really a no-brainer, performance-wise.

We need this for logging purposes.  i.e. Horde_Imap_Client returns  
translated messages as the error messages for Exceptions.  This is  
correct, since there is an outside chance that this Exception message  
may slip through and be presented to the user ... and it eliminates  
the need for duplicate translations in every package that uses the  
library.  But we don't want to log the exception details in the  
translated message, since everything else we log is in English.

Otherwise, the only way I can think of to get the original error  
string (and without manipulating locales, since that's not something  
we ever do in a package) is to explicitly write all of the strings  
twice ... once as a non-gettext string, and once as a gettext string.   
That is just a waste of time and asking for transcription errors.

Now we can do this:

new Horde_Imap_Client_Exception(
     Horde_Imap_Client_Translation::gettext_string("FOO")
);

And the exception constructor can both translate the message  
(Exception->getMessage()), store the original English string  
(Exception->raw_msg property), and "FOO" will correctly appear in the  
gettext translation files as extracted by horde-translation.

michael

___________________________________
Michael Slusarz [slusarz at horde.org]



More information about the dev mailing list