Hey All,
I have some knowledge in PHP, OOP and MVC but I really want to learn more and I think that learning how Opencart is structured and operates would teach me a lot on the subject.
I currently have a simple task for my own store, I want to add a translation layer for Countries / Zones and maybe later on for Cities as well. I saw that there are already extensions that do that out there. But I really want to make my own so I can learn something on the way.
My Idea basically is to add an intermediate layer that will interact as a translator to whatever data I fetched.
so for example let's say the I want to translate a country name the pseudo code would be:
1. get user current language
2. fetch country id x
3. fetch translation from (JSON File/DB whatever) where lang= user_lang and country_id=x
and of course the reverse when editing translations from the admin panel.
It looks simple but I really don't know where to start and how to plug it into Opencart so that I don't break anything. I already used vQmod for a little so I know how to change files without really screwing them up.
If I'm correct I need first to take care of the admin part of the extension and set up the form that from there I could edit and add translations ?
I need to find all places that country names and/or zones are fetched and implement my code. right ?
Can I use JSON in order to keep translations per language ?
I appreciate your help
I have some knowledge in PHP, OOP and MVC but I really want to learn more and I think that learning how Opencart is structured and operates would teach me a lot on the subject.
I currently have a simple task for my own store, I want to add a translation layer for Countries / Zones and maybe later on for Cities as well. I saw that there are already extensions that do that out there. But I really want to make my own so I can learn something on the way.
My Idea basically is to add an intermediate layer that will interact as a translator to whatever data I fetched.
so for example let's say the I want to translate a country name the pseudo code would be:
1. get user current language
2. fetch country id x
3. fetch translation from (JSON File/DB whatever) where lang= user_lang and country_id=x
and of course the reverse when editing translations from the admin panel.
It looks simple but I really don't know where to start and how to plug it into Opencart so that I don't break anything. I already used vQmod for a little so I know how to change files without really screwing them up.
If I'm correct I need first to take care of the admin part of the extension and set up the form that from there I could edit and add translations ?
I need to find all places that country names and/or zones are fetched and implement my code. right ?
Can I use JSON in order to keep translations per language ?
I appreciate your help
Ok Thanks, I made some progress today already used vQmod to edit the controller/localisation/country.php and view/template/localisation/country_form.tpl
I added access to languages within the controller country.php by adding this lines:
I added a loop in the country_form.tpl that loops through all the languages (minus english I left the old name input as is) and adds an <Input> for translation followed by the language flag by changing this code:
Into this:
Basically asking if language is not 1 (english) add a new input line for translation. (btw I hardcoded the number 1 cause I wasn't sure from where to pull the admin default language -> help 
so far it looks pretty much as I wanted:

Now comes the part where I'm getting a little confused ... I need to store the data somehow and to make it CRUD as it should with the country.
How should I do it ? The straight thinking tells me to create a table that holds translations and to add a seperate model file with the CRUD for the translation and call it from the country controller on insert / update / delete moethods.
But, I think there must be a smarter way to go about it ... need your advise !
I added access to languages within the controller country.php by adding this lines:
Code: Select all
$this->load->model('localisation/language');
$this->data['languages'] = $this->model_localisation_language->getLanguages();
Code: Select all
<td><span class="required">*</span> <?php echo $entry_name; ?></td>
<td><input type="text" name="name" value="<?php echo $name; ?>" />
<?php if ($error_name) { ?>
<span class="error"><?php echo $error_name; ?></span>
<?php } ?>
</td>
Code: Select all
<td><?php foreach ($languages as $language) { ?>
<?php if ($language['language_id'] != 1 ) { ?>
<input type="text" name="[<?php echo $language['name']; ?>][<?php echo $language['language_id']; ?>]" value="" />
<?php } else { ?>
<input type="text" name="name" value="<?php echo $name; ?>" />
<?php } ?>
<img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />
<?php if ($error_name) { ?>
<span class="error"><?php echo $error_name; ?></span>
<?php } ?>
<?php } ?>
</td>

so far it looks pretty much as I wanted:

Now comes the part where I'm getting a little confused ... I need to store the data somehow and to make it CRUD as it should with the country.
How should I do it ? The straight thinking tells me to create a table that holds translations and to add a seperate model file with the CRUD for the translation and call it from the country controller on insert / update / delete moethods.
But, I think there must be a smarter way to go about it ... need your advise !
yoshiro,
You have already modified the controller and the view. It seems you only need to modify the model (adding your changes).
May I ask you what CRUD is?
Thanks
You have already modified the controller and the view. It seems you only need to modify the model (adding your changes).
May I ask you what CRUD is?
Thanks
Create, Read, Update, Deletepablofiumara wrote:yoshiro,
You have already modified the controller and the view. It seems you only need to modify the model (adding your changes).
May I ask you what CRUD is?
Thanks
http://en.wikipedia.org/wiki/Create,_re ... and_delete
Thank you very much, QphoriaQphoria wrote:Create, Read, Update, Deletepablofiumara wrote:yoshiro,
You have already modified the controller and the view. It seems you only need to modify the model (adding your changes).
May I ask you what CRUD is?
Thanks
http://en.wikipedia.org/wiki/Create,_re ... and_delete
That's a great start. I'd store the data in a new table like:
Alternatively you could add a language_id column and indexes to the existing oc_country table though this could necessitate a lot of editing in other places.
Code: Select all
CREATE TABLE `oc_country_description` (
`country_id` int(11) NOT NULL DEFAULT '0',
`language_id` int(11) NOT NULL DEFAULT '0',
`name` varchar(128) NOT NULL,
PRIMARY KEY (`country_id`,`language_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
-Ryan
--@Pablo
You are right basically this is where I like to start from cause sometimes it give you an idea about the model. But as I am new to Opencart I'm not 100% sure of things but now thanks to Ryan I have some tailwind to go on.
--@Ryan
Thanks Ryan this suits my needs perfectly, thanks to your positive feedback I can now go on to the next step.
If there is demand I'll update this thread as I go.
You are right basically this is where I like to start from cause sometimes it give you an idea about the model. But as I am new to Opencart I'm not 100% sure of things but now thanks to Ryan I have some tailwind to go on.
--@Ryan
Thanks Ryan this suits my needs perfectly, thanks to your positive feedback I can now go on to the next step.
If there is demand I'll update this thread as I go.
yoshiro, in addition to uksitebuilder's vQmod Generator and its alternative versions, another tool you should see is for Shortcodes at quahar's http://forum.opencart.com/viewtopic.php?f=23&t=111369 with two releases, his 1.0 and most recently his 1.1 RC1 (at the moment the last post in the thread). As with the prior tool, I just want for you to see it, since it might come in handy.
@Buute
Thanks a lot that could be very useful !
I'm done with the backend part of this extension works pretty smooth now on to the frontend. Now the plan is to patch the country model at the frontend and change get_country() and get_countries() methods to try and get the translation for the current customer language and if it is null/not found fallback to the english name.
Thanks a lot that could be very useful !
I'm done with the backend part of this extension works pretty smooth now on to the frontend. Now the plan is to patch the country model at the frontend and change get_country() and get_countries() methods to try and get the translation for the current customer language and if it is null/not found fallback to the english name.
I've finished my first extension!
Countries & Zones Translator
It's the first version i'd be happy if you download and check it out
please leave me feedback / suggestions / remarks etc.
I Thanks you all for your help.
Countries & Zones Translator
It's the first version i'd be happy if you download and check it out

please leave me feedback / suggestions / remarks etc.
I Thanks you all for your help.
Who is online
Users browsing this forum: No registered users and 8 guests