Forums / Templates, Stylesheets, Page Layout / how to override template file according to language?

how to override template file according to language?

Locked

Views: 2,124

Results 1 to 5 of 5
This thread is locked. New replies are disabled.
13 Jan 2009, 9:57 PM
#1
vasilios avatar

vasilios

New Zenner

Join Date:
Sep 2008
Posts:
59
Plugin Contributions:
0

how to override template file according to language?

I have setup a local testing site with zen cart 1.3.8 in a winxp environment, using wamp server (with mysql 4.1.22 and php 5.2.6). The site is bilingual. I use a commercial template which is made for a previous zen cart version and I am trying to modify it in order to work ok. It has hard-coded some english link headings in the tpl_main_page.php file in the includes\templates<mytemplate>\common dir (e.g. "Customer Login", "Specials").

I want to do some modifications so these headings are output in both languages when a visitor selects one of these languages correspondingly. The template supports only english (as I wrote above the header string are hard-coded, i.e. are literal strings and not variables).

I guess I cannot override the tpl_main_page.php file itself, since it is located in a different dir than the** \includes\languages** directory where overrides can be implicated. Instead, I replaced the hard-coded strings with constant variables (the ones with the capital letters defined in the language files) which themselves get overriden language-wise since they are defined in files located in overridable directories.

So, for example one of the strings is the "Specials" heading for which the original code in the tpl_main_page.php was: ```

<td class="txt_content"><a href="index.php?main_page=specials">Specials</a></td> ``` and I replaced that with: ``` <td class="txt_content"><a href="index.php?main_page=specials"><?php echo BOX_HEADING_SPECIALS; ?></a></td> ```. Now, the BOX_HEADING_SPECIALS constant is defined as two alternative strings in each corresponding language file (**english.php** and **<2nd language.php**> under each **\includes\languages\<language>** directory, and indeed it works ok.
  1. Is the above method correct and compatible with the override system, or there is another alternative?

  2. Now, my problem is that I attempted to do the same for another string but I cannot find a constant to replace it with (in the tpl_main_page.php file) so I read in the wiki about adding one's own definition files. So, I created two <myfile>.php definition files with just this code: <?php DEFINE('MY_CUSTOM_CONSTANT', '<english string>'); ?> and ```
    <?php DEFINE('MY_CUSTOM_CONSTANT', '<2nd language string>'); ?>


I hope I made myself clear, and I appreciate any tips...
14 Jan 2009, 12:02 AM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: how to override template file according to language?

  1. That is indeed the correct way to account for multiple languages.
    Note that the original english.php file should remain untouched, and you should have your template versions for the two languages in /includes/languages/english/your_template/english.php and
    /includes/languages/your_language/your_template/your_language.php.

  2. Not sure about this. Your files look right - have you checked to be sure there are no extra blank lines or spaces after the closing ?> of the files? That can cause errors.

14 Jan 2009, 8:01 AM
#3
vasilios avatar

vasilios

New Zenner

Join Date:
Sep 2008
Posts:
59
Plugin Contributions:
0

Re: how to override template file according to language?

Ok, I think I solved the problem with the constant variable method substitution. Actually I used the HEADER_TITLE_LOGIN constant to replace the hard-coded string I had the problem for, so I didn't use any extra definition files.

Now, in the case of the 2nd language, I just go ahead and change it's initial language files (under the /includes/languages/my_language/) directly, i.e. I don't use override directories for this language since the modifications (i.e. the translations) I am doing will be template-independent. Actually this is a language pack I am trying to build which won't be overwritten by any future zen cart upgrades.
Is that right ?

thanks a lot for the tip....

18 Jan 2009, 2:53 PM
#4
willowgayle avatar

willowgayle

New Zenner

Join Date:
Jan 2009
Posts:
1
Plugin Contributions:
0

Re: how to override template file according to language?

how do I change the color of my cart?

18 Jan 2009, 11:47 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: how to override template file according to language?

Your question has nothing to do with this thread; to get proper attention, please start a new thread in the "Stylesheet" forum.
Also give a link to your site and specify which colors and areas you want to change, so we can give accurate answers.