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

Setting locale in template-override directory

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

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

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, 22:56
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

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.