Part of the EllisLab Network
   
 
[OPTIMIZATION] Language.php > load
Posted: 06 May 2007 08:57 AM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  735
Joined  10-18-2006

I run into this

$langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT;

I don’t get the point of these replacing. The native libraries calling lang->load doesn’t need them. If the point is to call lang->load(‘mylang_lang.php’) won’t properly, ‘cause the dot is included in “_lang.” and in EXT constant

I propose to replace it with

$langfile .= '_lang'.EXT;

Benchmarking time, after 10.000 iterations went from 0.1121 to 0.0656.

 Signature 

Once in a while I remember I use Twitter

Profile
 
 
Posted: 06 May 2007 11:01 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  248
Joined  02-10-2007

A similar construction can be found in Loader.php on line 323:

$helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper');

No dot in the second str_replace() though. See the difference?

 Signature 

Kohana rocks!

Profile
 
 
Posted: 06 May 2007 02:49 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  40
Joined  03-29-2006

$helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper');


$langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT;

There is a bug in the language code.

The developers allow you to load your language and helper files one of three ways:

account_lang.php
#1: $this->load->lang(‘account’);
#2: $this->load->lang(‘account_lang’);
#3: $this->load->lang(‘account_lang.php’);

account_helper.php
#1: $this->load->helper(‘account’);
#2: $this->load->helper(‘account_helper’);
#3: $this->load->helper(‘account_helper.php’);

The reason for the inner str_replace() is so that if you load your file like in #2, it will remove the “_lang” or “_helper” from it. Then the “_lang” or “_helper” is added back on. By doing this, you can load your stuff in any of the above three ways.

The bug though is in the language line. The period in “_lang.” should be removed and it should just read “_lang”. So here is the corrected code:

$langfile = str_replace(EXT, '', str_replace('_lang', '', $langfile)).'_lang'.EXT;

Personally, I wish that ALL loading classes worked the same way. Do away with the “_lang” and “_helper” forced requirement. Not only is it inconsistant with the other loaders (libraries and models) but it also slows down CI. I wish CI would load whatever is in the loader string in a what-you-type-is-what-you-get fashion:

HELPERS:
(account_helper.php)
$this->load->helper(‘account_helper’); // works
$this->load->helper(‘account’); // doesn’t work

(account.php)
$this->load->helper(‘account_helper’); // doesn’t work
$this->load->helper(‘account’); // works

etc etc for the rest of the helper functions…

(see my thread here for more information: http://codeigniter.com/forums/viewthread/51739/)

Profile
 
 
Posted: 06 May 2007 06:37 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
RankRank
Total Posts:  144
Joined  09-08-2006
kiger - 06 May 2007 02:49 PM

Personally, I wish that ALL loading classes worked the same way. Do away with the “_lang” and “_helper” forced requirement. Not only is it inconsistant with the other loaders (libraries and models) but it also slows down CI.

i agree completely and it keeps it uniform across the board. So can we petition to have this changed?

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 64458 Total Logged-in Users: 23
Total Topics: 80971 Total Anonymous Users: 1
Total Replies: 435710 Total Guests: 184
Total Posts: 516681    
Members ( View Memberlist )