View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0015654||phpList 3 application||Internationalization (l18n)||public||01-12-11 12:40||30-05-12 22:21|
|Fixed in Version||2.11.7|
|Summary||0015654: Unnecessary multiple including of language files|
|Description||I installed the APC (Alternative PHP Cache) extension to see what effect on response times it would have and as a side effect found that the language files are included not just once but on every call to the phplist_I18N class get method.|
APC shows the number of times each file is included/required and showed these results:
to display the home page once:
included en/home.php 84 times
included en/common.php 38 times
to display the users page once:
included en/users.php 114 times
included en/common.php 39 times
Although phplist 'is fast enough' it seems a good idea reduce the number of times each file is included.
My proposed solution is to load the language file for the page, and the common and frontend language files in the constructor instead of in the get() method. Additionally, to accumulate the files into a single array so simplifying the lookup processing in get().
Attached is a modified languages.php, taken from the 2.10.17 release.
The changes are only to the phplist_I18N class:
1) added instance variable $this->lan, which is set in the constructor and read in the get() method
2) moved the loading of the languages files from the get() method to the constructor, into a single array $this->lan
3) simplified the lookup of the text in the get() method
The lookup logic, initially in the page file then falling through to the common file, then to the front-end file, has been replaced by merging the files into a single array.
The lookup logic of the text, then the lowercased text, then the uppercased text is unchanged.
|Tags||No tags attached.|
languages.new.php (6,443 bytes)
||I have added the modified languages.php that I refer to in the original description. When I originally added the issue, adding attachments seemed to be broken.|
Hmm, the main issue with this is that each term is looked up differently.
eg, one term in a page may be in lan/[iso]/page.php and the other in lan/[iso]/common.php
I'm redoing the translation system to use the gettext method, and this should be included.
The current code looks-up a term in the order - the 'page' file, then the 'common' file, and then the 'front-end' file.
My change loads the files in the same order into a single array, so a term should be found from the 'page' file if it is present there, otherwise found from the 'common' file if present there, and finally from the 'front-end' file if present there.
If a term appears in more than one file then the earlier takes precedence.
||ah, yes, of course, good point|
the language.php file had changed a lot in the meantime, but I've incorporated your changes manually.