If you want to add some new texts into OpenCart multilingual theme, you’ll need not only to add it translated to your language files, but also core shop controller files must be modified. But to have a better update compatibility, it is preferred not to modify core files.
For example you want to add a contact link to the footer. We’ll add an html link and
<?php echo $text_contact; ?> to have it translated to languages into template.
In language files
/catalog/language/english/common/footer.php and i.e.
/catalog/language/russian/common/footer.php we’ll have that translated with
$_['text_contact'] = 'Contact Us'; and
$_['text_contact'] = 'Связь'; respectably. But then you’ll have undefined variable error on template.
We need to add a call for language files from footer controller
$this->data['text_contact'] = $this->language->get('text_contact'); where all such strings are called. But that is a core file, that will have to be changed in next version of OpenCart.
Opencart 1.5 still has no normal automatic upgrade solution, like WordPress or at least Prestashop. What it has is a scripting plugin vQmode, where you can write scripts to override core files. So we’ll create a script to add call for language translations into controller.
In vqmode/xml folder add a file template_lang_vars.xml with such code:
<?xml version="1.0" encoding="UTF-8"?> <modification> <id>Theme Language</id> <version>1.0.1</version> <vqmver>2.4.0</vqmver> <author>Iggy</author> <file name="catalog/controller/common/footer.php"> <operation error="skip"> <search position="after"><![CDATA[ $this->data['text_yt'] = $this->language->get('text_yt'); ]]></search> <add><![CDATA[ $this->data['text_contact'] = $this->language->get('text_contact'); $this->data['more_texts'] = $this->language->get('more_texts'); ]]></add> </operation> </file> </modification>
This way you search for last translation call in core file and adding your translation calls next to it. I’m adding next string
$this->data['more_texts'] = $this->language->get('more_texts'); here to show that more strings could be added. You can search only for 1 code line and add as many lines as you wish.
We can search in more files to add more translated strings.
This way we can add things to core files, and maybe even to language files, but I find it easier to add translations to language file itself. Anyway they shouldn’t be overwritten, after a shop is customized.