Forums / Addon Language Packs / Setting locale in template-override directory

Setting locale in template-override directory

Started by lat9 on 23 Mar 2013, 1:03 PM · Views: 2,371

Results 1 to 2 of 2
23 Mar 2013, 1:03 PM
#1
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,120
Plugin Contributions:
56

Setting locale in template-override directory

I have a multi-lingual site (English and Spanish) and I noticed yesterday that zen_date_long was formatting Saturdays like s�bado, even though my /includes/languages/MY_TEMPLATE/spanish.php had the statement

@setlocale(LC_TIME, 'es_ES.UTF-8');

After much hair-pulling and a helpful link (http://www.zen-cart.com/showthread.php?133111-locale-not-available-on-local-server-maybe) from torvista, I finally figured out what the heck was going on.

I'd upgraded this site from ZC 1.3.9h and converted to UTF-8 in the process. Although my template-override version of spanish.php was setting the locale for UTF-8, my base (i.e. /includes/languages/spanish.php) language file was still setting the locale to the non-UTF-8 format! Since it's a function call instead of a define, the last file loaded (base) "won".

I'm just mentioning this here to save others a fair amount of time and to note that the issue could be rectified by wrapping the call to setlocale with a "define" so that the function will only be run once, e.g.

if (!defined('ZEN_SETLOCALE_RUN')) {
  define('ZEN_SETLOCALE_RUN', true);
  @setlocale(LC_ALL, 'en_EN.UTF-8);
}
23 Mar 2013, 10:56 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Setting locale in template-override directory

This will be mitigated in 1.6.0 where the locale-specific stuff is split off from the english.php into its own separate locale.php file, for this and numerous other reasons.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.