Decimal separator vs locale (problem on moodle 2.1.3)

Decimal separator vs locale (problem on moodle 2.1.3)

by Mike K -
Number of replies: 5

Hello,

We are having problem with decimal separator during quiz attempt. Moodle is set to Polish locale, language pack is installed and server LANG is set to pl_PL.UTF-8.

When the question is previewed it works as expected, i.e. coma is treated as decimal separator and answer is accepted. However when attempting the same question in quiz we get error message:

"Please enter your answer without using the thousand separator (,)."

What makes things worse is the fact that this message is suppressed and question is marked incomplete until one returns to the question instead of informing the user before advancing to next one. 

We tried forcing locale/language in user settings, site-wide settings and given course settings but to no avail, the problem persists. 

It is my understanding, that since moodle 2.1 moodle should take decimal separator and thousand separator from locale settings. Unfortunately in quiz attempt this does not seem to be working. Could anybody shed some light on the issue and propose a solution?

We are running moodle 2.1.3 on Debian. Any help would be greatly appreciated. 

Average of ratings: -
In reply to Mike K

Re: Decimal separator vs locale (problem on moodle 2.1.3)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I have no idea why that works during quetsion preview, but not in a quiz attempt.

That is a bug, but unless you can give me some more clues, I don't really have any idea how to fix it.

If you have any programming ability, can you try putting some debugging output into qtype_numerical_answer_processor::__construct in question/type/numerical/questiontype.php where it does get_string('decsep', 'langconfig');

I wonder if the current language is properly initialised at that point? (That seems highly inlikely to me, however.)

In reply to Tim Hunt

Re: Decimal separator vs locale (problem on moodle 2.1.3)

by Mike K -

Hi Tim,

Thanks for answering smile

decsep seems to be properly initialized multiple times when question is displayed during quiz attempt:

string(1) ","
string(1) ","
string(1) ","
string(1) ","
string(1) ","
string(1) ","
string(1) ","
string(1) ","
string(1) ","
string(1) ","
string(1) ","
string(1) ","
string(1) ","
string(1) ","
string(1) ","

as you can see from above output. So the problem must be elsewhere. 

I can dump whatever variables you need, just say which ones smile

 

EDIT:

Here's a dump of entire initilized question object (long description strings removed for clarity):

qtype_calculatedsimple_question Object

(

    [datasetloader] => qtype_calculated_dataset_loader Object

        (

            [questionid:protected] => 1943

            [itemsavailable:protected] => 50

        )

 

    [vs] => qtype_calculated_variable_substituter Object

        (

            [values:protected] => Array

                (

                    [KK] => 832384

                    [SP] => 2.27

                    [LR] => 324

                    [OP] => 3.53

                )

 

            [decimalpoint:protected] => ,

            [search:protected] => Array

                (

                    [0] => {KK}

                    [1] => {SP}

                    [2] => {LR}

                    [3] => {OP}

                )

 

            [safevalue:protected] => Array

                (

                    [0] => (832384)

                    [1] => (2.27)

                    [2] => (324)

                    [3] => (3.53)

                )

 

            [prettyvalue:protected] => Array

                (

                    [0] => 832384

                    [1] => 2,27

                    [2] => 324

                    [3] => 3,53

                )

 

            [replace] => Array

                (

                )

 

        )

 

    [synchronised] => 0

    [answers] => Array

        (

            [4864] => qtype_numerical_answer Object

                (

                    [tolerance] => 0.01

                    [tolerancetype] => 1

                    [id] => 4864

                    [answer] => {KK}*(1+({SP}/100))/{LR}+{KK}*(1+({SP}/100))*({OP}/100)/12

                    [answerformat] => 2

                    [fraction] => 1.0000000

                    [feedback] =>

                    [feedbackformat] => 1

                    [correctanswerlength] => 0

                    [correctanswerformat] => 1

                )

 

        )

 

    [unitdisplay] => 3

    [unitgradingtype] => 0

    [unitpenalty] => 0.1000000

    [ap] => qtype_numerical_answer_processor Object

        (

            [units:protected] => Array

                (

                )

 

            [decsep:protected] => ,

            [thousandssep:protected] => ,

            [unitsbefore:protected] =>

            [regex:protected] =>

        )

 

    [shownumcorrect] =>

    [id] => 1943

    [category] => 183

    [contextid] => 1

    [parent] => 0

    [qtype] => qtype_calculatedsimple Object

        (

            [wizard_pages_number] => 1

            [wizardpagesnumber] => 3

            [fileoptions:protected] => Array

                (

                    [subdirs] =>

                    [maxfiles] => -1

                    [maxbytes] => 0

                )

 

        )

 

    [name] =>  (removed)

    [questiontext] => (removed)

    [questiontextformat] => 1

    [generalfeedback] =>

    [generalfeedbackformat] => 1

    [defaultmark] => 1

    [length] => 1

    [penalty] => 0.3333333

    [stamp] => xxxx.xxxxx.pl+120112101842+KYTEJF

    [version] => xxxx.xxxxx.pl+120112103713+PLbR3T

    [hidden] => 0

    [timecreated] => 1326363522

    [timemodified] => 1326364628

    [createdby] => 666

    [modifiedby] => 666

    [hints] => Array

        (

        )

)

In reply to Mike K

Re: Decimal separator vs locale (problem on moodle 2.1.3)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think the problem is

[decsep:protected] => ,

[thousandssep:protected] => ,

The problem seems to be that the Polish lang pack difines thousandssep and decsep to be the same (Or possibly it does not define thousandssep at all, and so inherits the value from en) and this confuses the numerical qtype.

You need to get thousandssep defined correcty in the pl lang pack - so take that up with the language pack maintainers.

In the mean time, you can edit this in your Moodle using the language editing facilities in the admin screens.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Decimal separator vs locale (problem on moodle 2.1.3)

by Mike K -

You are absolutely correct, the polish pack does not define thousandssep and thus moodle falls back to English default. Once thousandssep is defined to some other char, the quiz works as expected.

Thank you for your help smile 

 

I do think though, that moodle core should prevent situation where decsep == thousandssep forcefully setting thousandssep to some safe character to prevent this kind of situation, and showing appropriate warning message wherever either is used.