Post by iyn » Mon Nov 01, 2010 7:45 pm

add this function in the system/engine/controller.php

Code: Select all

public function load_language($language) {
	$this->data = array_merge($this->data, $this->load->language($language));
}
then, in the controller (eg: catalog/controller/product/product.php) instead of using

Code: Select all

$this->language->load('product/product');
and instead of writing tons of

Code: Select all

			$this->data['text_enlarge'] = $this->language->get('text_enlarge');
			$this->data['text_discount'] = $this->language->get('text_discount');
			$this->data['text_options'] = $this->language->get('text_options');
			$this->data['text_price'] = $this->language->get('text_price');
			$this->data['text_availability'] = $this->language->get('text_availability');
			$this->data['text_model'] = $this->language->get('text_model');
			$this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
			$this->data['text_order_quantity'] = $this->language->get('text_order_quantity');
			$this->data['text_price_per_item'] = $this->language->get('text_price_per_item');
			$this->data['text_qty'] = $this->language->get('text_qty');
			$this->data['text_write'] = $this->language->get('text_write');
			$this->data['text_average'] = $this->language->get('text_average');
			$this->data['text_no_rating'] = $this->language->get('text_no_rating');
			$this->data['text_note'] = $this->language->get('text_note');
			$this->data['text_no_images'] = $this->language->get('text_no_images');
			$this->data['text_no_related'] = $this->language->get('text_no_related');
			$this->data['text_wait'] = $this->language->get('text_wait');
			$this->data['text_tags'] = $this->language->get('text_tags');
			$this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);

			$this->data['entry_name'] = $this->language->get('entry_name');
			$this->data['entry_review'] = $this->language->get('entry_review');
			$this->data['entry_rating'] = $this->language->get('entry_rating');
			$this->data['entry_good'] = $this->language->get('entry_good');
			$this->data['entry_bad'] = $this->language->get('entry_bad');
			$this->data['entry_captcha'] = $this->language->get('entry_captcha');

			$this->data['button_continue'] = $this->language->get('button_continue');
you can simply use

Code: Select all

$this->language_load('product/product');
and you don't need to write those redundant & repetitive language variable assignments, because it will be automatically done

hope this helps :)

iyn
Newbie

Posts

Joined
Mon Nov 01, 2010 7:33 pm
Location - surabaya

Post by Qphoria » Mon Nov 01, 2010 8:26 pm

This has been brought up before here:
http://forum.opencart.com/viewtopic.php?f=24&t=11152

Actually this is already done slightly different in the core.
Daniel doesn't want language data loading into the controller engine for framework purposes. So a slight alteration to your example is already in effect as of 1.4.8 and later:

In any controller file (catalog/controller/* or admin/controller/*):

instead of :

Code: Select all

$this->language->load('product/product');
$this->data['text_enlarge'] = $this->language->get('text_enlarge');
$this->data['text_discount'] = $this->language->get('text_discount');
$this->data['text_options'] = $this->language->get('text_options');
$this->data['text_price'] = $this->language->get('text_price');
Just use:

Code: Select all

$this->data = array_merge($this->data, $this->load->language('product/product'));
You can do this already with no modifications already.

It just hasn't been converted yet but is planned for 1.5.0

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 5 guests