Post by yukai.lin » Sun Feb 21, 2010 3:07 pm

I tried another way to load language file, and it make less code, u dun need add the code like '
$this->data['heading_title'] = $this->language->get('heading_title'); '
. On the other hand, I am not sure if the performance would be worse. :)

1.add the code in \system\library\language.php:

Code: Select all

    public function getFile($filename) {
		return $file = $file = DIR_LANGUAGE . $this->directory . '/' . $filename . '.php';
	}
2.then add the code in \system\engine\controller.php:

Code: Select all

    public function load_language($filename) {
        $this->languages = Registry::get('language');

       $file = $this->languages->getFile($filename);

      if (file_exists($file)) {

         $_ = array();

       require($file);

       $this->data = array_merge($this->data, $_);

     } else {
          exit('Error: Could not load language ' . $filename . '!');
        }
    }
3. load the language by using $this->load_language('common/login');
and u dun need load the language by using $this->data['heading_title'] = $this->language->get('heading_title'); any more.

4.in the tpl, u still display the text with <?php echo $heading_title;?>, no need change anything in tpl.
Last edited by i2Paq on Sun Feb 21, 2010 7:29 pm, edited 1 time in total.
Reason: code-tags added

http://www.tylsoft.net - supply opencart extensions,opencart template,etc.
opencart中文站 - http://www.cnopencart.com


Newbie

Posts

Joined
Fri Dec 18, 2009 9:13 pm


Post by OSWorX » Sun Feb 21, 2010 4:19 pm

Seems like a good approach.
Anyway, let us wait for next OC release after 1.4.0, I still do not know what Daniel will change/add/remove.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by AvanOsch » Thu Mar 08, 2012 8:34 pm

Ok, now @ version 1.5.2.1, and we're still typing loads of senseless code...

I totally get that OpenCart wants to keep to the MVC structure, but c'mon...
Isn't such a thing made up to make life easier?!?

Code: Select all

We're just repeating lot's of code, because we're "supposed to", like a bunch of drones!
We're just repeating lot's of code, because we're "supposed to", like a bunch of drones!
We're just repeating lot's of code, because we're "supposed to", like a bunch of drones!
I'll be using a modified version of yukai.lin's code from now on!

User avatar
Active Member

Posts

Joined
Sat Sep 03, 2011 9:17 pm

Post by Qphoria » Thu Mar 08, 2012 11:29 pm

AvanOsch wrote:Ok, now @ version 1.5.2.1, and we're still typing loads of senseless code...

I totally get that OpenCart wants to keep to the MVC structure, but c'mon...
Isn't such a thing made up to make life easier?!?

Code: Select all

We're just repeating lot's of code, because we're "supposed to", like a bunch of drones!
We're just repeating lot's of code, because we're "supposed to", like a bunch of drones!
We're just repeating lot's of code, because we're "supposed to", like a bunch of drones!
I'll be using a modified version of yukai.lin's code from now on!
No, you wont. This has actually already been in the code since 1.4.8. Daniel chose NOT to use it in the core files because he likes it the old way, but you can certainly use this method for your own files. The syntax used in opencart is discussed here:
http://forum.opencart.com/viewtopic.php?f=24&t=19000 (item number 1)

Simply replace

Code: Select all

$this->language->load('payment/mypay');
with

Code: Select all

$this->data = array_merge($this->data, $this->load->language('payment/mypay'));
Then you can get rid of all the separate langauge lines.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by AvanOsch » Fri Mar 09, 2012 12:05 am

Qphoria wrote: No, you wont.
Yeah, found that out for myself too ;D

Thanks for the fix!

User avatar
Active Member

Posts

Joined
Sat Sep 03, 2011 9:17 pm
Who is online

Users browsing this forum: No registered users and 15 guests