osCommerce / oscommerce2

osCommerce Online Merchant v2.x
http://www.oscommerce.com
MIT License
281 stars 222 forks source link

Date character issues in windows enviroment #645

Open tgely opened 5 years ago

tgely commented 5 years ago

https://github.com/osCommerce/oscommerce2/blob/de0e97d15d43ac6a9a6cfb2847134a82a0148f2b/catalog/includes/OSC/Sites/Shop/Shop.php#L88

For ages I have idiot character problems on hungarian languages in development enviroment because we live on windows... (New Product for July and so on)

Array ( days.. [0] => vas�rnap [1] => h�tf� [2] => kedd [3] => szerda [4] => cs�t�rt�k [5] => p�ntek [6] => szombat [7] => vasárnap - utf8 encoded [8] => hétfõ - utf8 encoded [9] => kedd - utf8 encoded [10] => szerda - utf8 encoded [11] => csütörtök - utf8 encoded [12] => péntek - utf8 encoded [13] => szombat - utf8 encoded ) Array ( months.. [7] => j�lius [6] => j�nius [5] => m�jus [4] => �prilis [3] => m�rcius [2] => febru�r [1] => janu�r [12] => december )

The conflict was when LC_ALL redefined then disabled LC_TIME in windows enviroment.

Solution for windows developers:

        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
            $lc_time = OSCOM::getDef('windows_time_locale');
            if (!empty($lc_time) && $lc_time !== 'windows_time_locale') {
                setlocale(LC_TIME, explode(';', $lc_time));
            }
        }

Add

windows_time_locale = hu_HU.UTF8;hu_HU.UTF-8

into main language collection and I have inserted the code you see above after reported lines.

At this moment I have issue on PHP5.6 version only, but this could be more seriously problem for others.

oitsuki commented 5 years ago

Is not better to add a new field in language db and call the locale

setlocale(LC_ALL, explode(',', $this->getLocale()));

and a function :

    public function getLocale()
    {
      $code = $this->getCode();
      return $this->get('locale', $code);
    }
tgely commented 5 years ago

Thanks @oitsuki :+1: To use locale field in language table is a good idea! I will do it later but not have to declare a new language class function for it.

  setlocale(LC_ALL, explode(';', $OSCOM_Language->get('locale'));

Setlocale can not fixable on windows enviroment so I had to do another things. :disappointed:

Its an UTF-8 issue.

In windows enviroment on some wrong PHP versions required a date name template exchange function fixer and I have to add fix into DateTime::toLong() function too.

Here is the checkpoint:

  if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' && strpos(setlocale(LC_TIME, 0), 'UTF-8') === false) {
    // do stuff here
  }
oitsuki commented 5 years ago

Look Oscommerce V3 for that.