[dev] setlocale() usage in Horde_Registry

Michael M Slusarz slusarz at horde.org
Tue Jan 28 17:35:51 UTC 2014


Quoting Jan Schneider <jan at horde.org>:

> Zitat von Michael M Slusarz <slusarz at horde.org>:
>
>> This is mostly for Jan's input, although anyone else is welcome to chime in.
>>
>> In Horde_Registry#setLanguage(), there is the following code:
>>
>>        $lang_charset = $lang . '.UTF-8';
>>        if (setlocale(LC_ALL, $lang_charset)) {
>>            putenv('LC_ALL=' . $lang_charset);
>>            putenv('LANG=' . $lang_charset);
>>            putenv('LANGUAGE=' . $lang_charset);
>>        } else {
>>            $changed = false;
>>        }
>>
>> As an example, have $lang be 'pt_PT'.  When loading gettext  
>> strings, the following is seen via strace:
>>
>> open("mail/locale/pt_PT.UTF-8/LC_MESSAGES/horde.mo", O_RDONLY) = -1  
>> ENOENT (No such file or directory)
>> open("mail/locale/pt_PT.utf8/LC_MESSAGES/horde.mo", O_RDONLY) = -1  
>> ENOENT (No such file or directory)
>> open("mail/locale/pt_PT/LC_MESSAGES/horde.mo", O_RDONLY) = -1  
>> ENOENT (No such file or directory)
>> open("mail/locale/pt.UTF-8/LC_MESSAGES/horde.mo", O_RDONLY) = -1  
>> ENOENT (No such file or directory)
>> open("mail/locale/pt.utf8/LC_MESSAGES/horde.mo", O_RDONLY) = -1  
>> ENOENT (No such file or directory)
>> open("mail/locale/pt/LC_MESSAGES/horde.mo", O_RDONLY) = 12
>>
>> I'm almost 100% sure that all of our .mo files are utf8, so adding  
>> this to the locale string is simply causing spurious attempts to  
>> load non-existent files.
>>
>> If I am reading this right  
>> (http://www.gnu.org/software/gettext/manual/gettext.html#The-LANGUAGE-variable), this may be a better  
>> choice:
>>
>> putenv('LANGUAGE=' . $lang);
>>
>> This would theoretically change the loading to this instead (I  
>> don't have the ability to test this at the moment):
>>
>> open("mail/locale/pt_PT/LC_MESSAGES/horde.mo", O_RDONLY) = -1  
>> ENOENT (No such file or directory)
>> open("mail/locale/pt/LC_MESSAGES/horde.mo", O_RDONLY) = 12
>>
>> ...saving up to 4 file lookups for every application.
>>
>> Thoughts?
>>
>> michael
>>
>> ___________________________________
>> Michael Slusarz [slusarz at horde.org]
>
> These locale settings are inherited to external binaries and calls  
> too. It may not be necessary for Horde's locales, but it's necessary  
> for other system locales. Also, this is the environment setting  
> that's most compatible on different platforms.

OK.  I won't touch this code.

michael

___________________________________
Michael Slusarz [slusarz at horde.org]



More information about the dev mailing list