Zen Cart Language File Overrides

 hints, zen-cart  Comments Off on Zen Cart Language File Overrides
Jul 082013
 

When you write a plugin for Zen Cart, you’re encouraged to use template-override methods to allow for a more easy upgrade for stores that use your code.  If your plugin adds new text or messages to a popular page, like the login or create_account pages, your plugin’s changes can get easily lost when another plugin is installed or during an upgrade.

Zen Cart’s language file loader (/includes/modules/require_languages.php) performs the following steps:

  1. Determines the base language filename, e.g. login.php for the login page.
  2. Determines the session’s current language, e.g. english.
  3. Determines the session’s current template name, e.g. MY_TEMPLATE.
  4. Looks for the file /includes/languages/english/MY_TEMPLATE/login.php.  If found there, all files that match /includes/languages/english/MY_TEMPLATE/login*.php are loaded; otherwise, all files that match /includes/languages/english/login*.php are loaded.

So, if your plugin needs new language text for the login page, it’s not necessary to modify the login.php file.  Create a new file named login_for_my_plugin.php and provide two copies in your plugin’s distribution zip-file

  1. /includes/languages/english/login_for_my_plugin.php
  2. /includes/languages/english/YOUR_TEMPLATE/login_for_my_plugin.php

Note:  If your plugin is making modifications to existing messages for a particular page, you’ll need to distribute those changes in /includes/languages/english/YOUR_TEMPLATE/page_name.php.