Prestashop logo, Visit home page

Install locales

-

Locales are language packs installed on the server. PHP can use locales to display dates in languages other than English.

 

Install new locales

You can list all available locales on the server with this command:

locale -a

You will get a list like this:

C
C.UTF-8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IL
en_IL.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
POSIX

For example, if you want to add French locales, enter this command:

locale-gen fr_FR fr_FR.UTF-8

The list of locales now looks like this:

C
C.UTF-8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IL
en_IL.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
french
fr_FR
fr_FR.iso88591
fr_FR.utf8
POSIX

You can now restart PHP FPM to take these local news into account:

service php7.4-fpm restart

 

Locales in PrestaShop

In PrestaShop, locales are defined inconfig/config.inc.php.

/* Set locales */
$locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')) . '_' . strtoupper(Configuration::get('PS_LOCALE_COUNTRY'));
/* Please do not use LC_ALL here <http://www.php.net/manual/fr/function.setlocale.php#25041> */
setlocale(LC_COLLATE, $locale . '.UTF-8', $locale . '.utf8');
setlocale(LC_CTYPE, $locale . '.UTF-8', $locale . '.utf8');
setlocale(LC_TIME, $locale . '.UTF-8', $locale . '.utf8');
setlocale(LC_NUMERIC, 'en_US.UTF-8', 'en_US.utf8');

You can test if the locales work by creating this file in

/vol/site/current/testlocales.php :

<?php
/* Set locales */
$locale = 'fr_FR';
/* Please do not use LC_ALL here <http://www.php.net/manual/fr/function.setlocale.php#25041> */
setlocale(LC_COLLATE, $locale . '.UTF-8', $locale . '.utf8');
setlocale(LC_CTYPE, $locale . '.UTF-8', $locale . '.utf8');
setlocale(LC_TIME, $locale . '.UTF-8', $locale . '.utf8');
setlocale(LC_NUMERIC, 'en_US.UTF-8', 'en_US.utf8');

echo strftime("%A");

Then run this script in your browser to check if you get the desired result.

Note that not all PHP methods use locales. For example, you should use strftime instead of the date method.

Share

Was the article helpful?