fatfree icon indicating copy to clipboard operation
fatfree copied to clipboard

Latin locale not available under windows

Open eliargon opened this issue 2 years ago • 1 comments

in base.php line 1136 in the function language() stats: $locale=@constant('ISO::LC_'.$parts[0]); This line generates an Internal Server Error of Undefined Constant ISO::LC_la

Any idea why and how to fix?

eliargon avatar Aug 14 '22 17:08 eliargon

This is because "Latin" (la) is not part of the Windows compatible ISO-639-2 locale subset.

ref.: https://docs.moodle.org/dev/Table_of_locales#Table

we should probably review this and check if Win10+ can handle the unix type locales now.

ikkez avatar Sep 18 '22 13:09 ikkez

We have encountered this for the first time yesterday. The fix for this is a bit groky and I think the actual problem might still count as a bug(ish).

I come from South Africa and we have a number of local official languages. This issue was first reported by a user with isiZulu set as their browser langauge. I was able to replicate this problem by setting my browser language to isiXhosa - not an unreasonable thing for Zulu/Xhosa speakers to do. This triggered the following error: Undefined constant ISO::LC_xh [F:\wamp64\www\rodel\trust.rodelfiduciary.co.za\vendor\bcosca\fatfree-core\base.php:1136]

This is derived from the 'Accept-Language' request header, which in my case is: 'xh-ZA,xh;q=0.8,en-US;q=0.5,en;q=0.3'

The error suppression at line 1136 doesn't work at my current version of PHP (8.0.20). I am not sure if it worked previously: $locale=@constant('ISO::LC_'.$parts[0]);

The fix, which is not ideal, is to manually change the $_SERVER['HTTP_ACCEPT_LANGUAGE'] early on in the request (before you hit F3). For example: $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-ZA,en';

I can't seem to find any other way around it. I would welcome a more robust solution if I missed it :-)

MissConstrued avatar Sep 30 '22 11:09 MissConstrued

@MissConstrued I was looking at the PHP 8 upgrade info, and noticed this:

The @ operator will no longer silence fatal errors (E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR, E_PARSE). Error handlers that expect error_reporting to be 0 when @ is used, should be adjusted to use a mask check instead:

https://www.php.net/manual/en/migration80.incompatible.php

The constant() method will throw an error if the constant is not defined: https://www.php.net/manual/en/function.constant.php

If the constant is not defined, an Error exception is thrown. Prior to PHP 8.0.0, an E_WARNING level error was generated in that case.

So in PHP 7 it probably didn't work either, but the supression did work.

geniuswebtools avatar Sep 30 '22 21:09 geniuswebtools

Hi. thanks for reporting this. I heard something similar recently, but your details are very good. Yes probably we should just add a check if the constant exists with defined() before accessing it and remove the @

ikkez avatar Sep 30 '22 22:09 ikkez

Great :-)

However, for anyone currently facing this issue (who doesn't want to edit base.php for the obvious reasons) a work around is to check and override $_SERVER['HTTP_ACCEPT_LANGUAGE'] before F3 instantiation.

MissConstrued avatar Oct 01 '22 02:10 MissConstrued

fixed

ikkez avatar Nov 03 '22 23:11 ikkez