After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 142824 - gcalctool ignores locale specific decadic point
gcalctool ignores locale specific decadic point
Status: RESOLVED FIXED
Product: gnome-calculator
Classification: Core
Component: general
unspecified
Other Linux
: Normal major
: ---
Assigned To: Sami Pietilä
Sami Pietilä
Depends on:
Blocks:
 
 
Reported: 2004-05-20 09:32 UTC by Stanislav Brabec
Modified: 2006-01-14 16:55 UTC
See Also:
GNOME target: ---
GNOME version: 2.11/2.12


Attachments
Possible "fix" for the problem. (714 bytes, text/plain)
2004-05-21 17:46 UTC, Rich Burridge
  Details
Possible fix for the problem. (2.23 KB, text/plain)
2004-05-25 19:31 UTC, Rich Burridge
  Details
decimal.patch (2.10 KB, patch)
2004-05-26 15:35 UTC, Stanislav Brabec
none Details | Review
Fix from Sami for problem in AOP mode. (3.35 KB, text/plain)
2006-01-09 16:28 UTC, Rich Burridge
  Details

Description Stanislav Brabec 2004-05-20 09:32:54 UTC
In some locales (e. g. cs_CZ), standard decadic point is ",". GCalcTool displays
it on both button and "display", but still expects only "." when entering from
keyboard.
Comment 1 Rich Burridge 2004-05-21 17:43:21 UTC
EEk! Adding Jody for his advice on the best way to handle this:

In .../gcalctool/gcalctool/calctool.c at about line 396, there is 
a struct button entry for the numeric point:

{
    N_("."),
    N_("Numeric point"),
    NULL,
    { 0,	  0,		  0,		 0 },
    { GDK_period, GDK_KP_Decimal, GDK_KP_Delete, GDK_KP_Separator, 0 },
    '.',
    M_NONE,
    do_point
},

You will see that it's looking for certain GDK events that are currently
hard-coded to be ".".

One "fix" for this would be to adjust those two lines to include in the
GDK keysyms for ",":

    { 0,	  0,		  0,		 0,                0 },
    { GDK_period, GDK_KP_Decimal, GDK_KP_Delete, GDK_KP_Separator, GDK_comma, 0 },

(GDK_comma isn't used anywhere else) but I wonder if there is a 
better way of doing it. It's certainly not going to be a universal
fix if other locales use anything else apart from "." or ",".

Stanislav, I'll generate a simple patch for you to try (against CVS
HEAD), but if this works it might not be the final fix.
Comment 2 Rich Burridge 2004-05-21 17:46:34 UTC
Created attachment 27910 [details]
Possible "fix" for the problem.

This will probably work but might not be the best way to solve this.
Comment 3 Stanislav Brabec 2004-05-24 12:08:35 UTC
Old-gnome-calculator used a gettext trick _(".").

XCalc uses localeconv()->decimal_point.
Comment 4 Rich Burridge 2004-05-24 15:30:13 UTC
Thanks, but neither of these maps to GDK keysyms.
Stanislav, did the attached patch actually work for you?
Just curious.

Adding Owen to the cc: for his advice on the best
way to handle this.
Comment 5 Stanislav Brabec 2004-05-24 16:16:35 UTC
Attached patch works.
Comment 6 Owen Taylor 2004-05-24 19:05:58 UTC
The translation between key symbols and characters is fixed.
(After some wavering, we came up with the policy that

 GDK_KP_Separator is ',' always
 GDK_KP_Decimal is '.' always

This is indepenent of the locale. If your keyboard definition doesn't follow 
this, then it needs to be fixed.)

So, the right thing to do is to convert to a unicode character, then interpret 
the unicode character in terms of the current locale. 

localeconv ()->decimal_point should be available virtually everywhere.
It's used in unconditionalized code in GLib. (See g_ascii_strtod())

Of course, you might want to just accept localeconv()->decimal_point,
',' *and* '.' (localecov()->decimal point isn't necessarily either one)
all the time, since people aren't entirely consistent.
Comment 7 Rich Burridge 2004-05-25 19:31:21 UTC
Created attachment 28013 [details]
Possible fix for the problem.

Okay, here's a fix (hopefully) for the problem.
Thanks to Owen and Toshi (Hidetoshi Tajima) for
pointing me in the right direction.

Stanislav could you give this a try please?
Also make sure that you patch a "clean" version
of gcalctool (i.e. it doesn't include the previous
patch fix for this problem). 

If you are okay with it, I'll check it in.
Comment 8 Rich Burridge 2004-05-25 20:18:13 UTC
Keep forgetting to get this out of the UNCONFIRMED state.
Comment 9 Stanislav Brabec 2004-05-26 09:59:09 UTC
New patch does not work. Recognizes only ".".

You can simply test it LANG=cs_CZ gcalctool or LANG=cs_CZ.UTF-8 gcalctool.

Tried with keymap cz.

And maybe s/numeric_point/decimal_point/g.
Comment 10 Rich Burridge 2004-05-26 14:23:49 UTC
Unfortunately I can't test it:

$ LANG=cs_CZ ./gcalctool
couldn't set locale correctly

(gcalctool:19177): Gtk-WARNING **: Locale not supported by C library.
	Using the fallback 'C' locale.

Perhaps you could add a line of debug in main() after:

  X->lnp = get_localized_numeric_point();

  fprintf(stderr, "X->lnp: %s\n", X->lnp);

and tell me what it says.

I also believe numeric point is more correct as this
situation occurs in other numeric bases (binary, octal
and hexadecimal).

Adding Miloslav who is hopefully able to help in 
tracking this down.
Comment 11 Stanislav Brabec 2004-05-26 15:35:15 UTC
Created attachment 28032 [details] [review]
decimal.patch

X->lnp: .

The problem is, that you have called get_localized_numeric_point() before
setlocale(). After moving it after gnome_program_init() (which calls
setlocale()), patch works OK.
Comment 12 Rich Burridge 2004-05-26 15:54:31 UTC
Thanks. I've checked in the revised patch to CVS HEAD.
I've bumped the version number in configure.in to
4.4.7.
Comment 13 Stanislav Brabec 2005-09-21 13:23:41 UTC
Bug is still not properly fixed in some places in GNOME 2.12.

Reopening bug and setting to major, because in particular cases it causes bad
calculation without any evidence.

Typing a number: Bad (minor bug). It displays ".", but after enter it changes to
",".

How to reproduce: Set LANG=cs_CZ.UTF-8. Type "3,1". You see "3.1". Press Enter.
It changes to "3,1".

Copying number: OK. It copies ","

Pasting number: Bad (major). It seems to accept both "," and ".", but only "."
is really accepted. Pasting number with "," truncates the number without evidence.

How to reproduce: Set LANG=cs_CZ.UTF-8. Type 3,5+3,5 to editor. Paste. You see
"3,5+3,5". Press "=". The result is "6".
Comment 14 Rich Burridge 2005-09-22 17:29:25 UTC
Hi Stanislav. Could you tell me if you are seeing these
two problem with or without Arithmetic Precedence Mode?
Or both.

To determine this, see if the "Use Arithmetic Precedence"
check box is checked on the View menu from the menubar.

Thanks.
Comment 15 Stanislav Brabec 2005-09-23 11:16:10 UTC
Yes. "Use Arithmetic Precedence" was checked. Unchecking it, I got different
results (with one bug):

Typing a number: OK, it displays "," all the time.

Copying number: OK. It copies ",".

Pasting number: Bad (normal). It accepts only ".". Pasting number with ","
causes "Clipboard contained malformed calculation".

How to reproduce: Set LANG=cs_CZ.UTF-8.

Type "3+3,5=". Copy. Paste. The result is "Clipboard contained malformed
calculation" (translated).
Comment 16 Rich Burridge 2005-09-23 14:59:39 UTC
Transferring to Sami as the fix(es) will be in his code.
I did have a quick look at the only non-arithmetic operator
precedence failure. When you paste something into gcalctool,
it uses the get_proc() routine in gtk.c to handle this.
For non-arithmetic op. precedence, it calls lr_parse to generate
the number to display. For arithmetic op. precedence, it calls 
exp_append(). It looks like routines that parse this buffer need to
call check_for_localized_numeric_point() in order to do the right 
thing here.
Comment 17 Rich Burridge 2006-01-09 16:28:56 UTC
Created attachment 57044 [details]
Fix from Sami for problem in AOP mode.
Comment 18 Rich Burridge 2006-01-14 16:55:35 UTC
I could have swore I closed this. Doing so now. Changes have
been checked into CVS HEAD. They will also be in the gcalctool
(v5.7.23) that'll be in GNOME 2.13.5.