Page 1 of 1

Separate translation from Controllers

Posted: Mon Jun 06, 2011 12:13 am
by mjalajel
Hello,

My suggestion would be to separate translations from controllers and put them only in views.

Current Code:

Code: Select all

/* In Language File */
$_['text_overview'] = 'Overview';

/* In Controller: */
$this->load->language('common/home');
$this->data['text_overview'] = $this->language->get('text_overview');

/* In View: */
<?php echo $text_overview; ?>
Suggested Code

Code: Select all

/* In Language File */
$_['text_overview'] = 'Overview';

/* In Controller: */
# NOTHING

/* In View: */
<?php $this->load->language('common/home'); ?>
<?php echo I18n::t('text_overview'); ?>

#OR this form to get one item without affecting the registry
<?php echo I18n::t('text_overview', 'common/home'); ?>
Rationale
  • I think it is very distracting to find 25 calls in the controller to get a translated item that (may) be used in the view
  • Currently, It's somehow hard to trace back an item from a view file to a controller to the language file...
  • Suggested method will offer more simplicity, flexibility and -more importantly- separation.
I can contribute the code needed, but I'm not sure if such change would be acceptable and how many people are dependent on the current format. Maybe this could be used in one of the upcoming major releases!

What do you think!

Re: Separate translation from Controllers

Posted: Mon Jun 06, 2011 2:20 am
by Xsecrets
this is already being worked on some of the controllers are already passing all translations directly into the data array. Eventually all the controllers will be updated, but it's just going to take time to go through them all.

Re: Separate translation from Controllers

Posted: Mon Jun 06, 2011 10:02 am
by mjalajel
Is there any live examples in 1.5 that I can see?

Re: Separate translation from Controllers

Posted: Mon Jun 06, 2011 12:09 pm
by Xsecrets
see this thread http://forum.opencart.com/viewtopic.php?f=24&t=19000
I know the change had been made in a few files in the later 1.4.x versions, but it may not be in 1.5 yet since it was started from earlier versions.