Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internationalization - Decimal point/comma #175

Closed
targodan opened this issue Sep 17, 2018 · 4 comments
Closed

Internationalization - Decimal point/comma #175

targodan opened this issue Sep 17, 2018 · 4 comments

Comments

@targodan
Copy link

Don't know how much of a hassle it might be but on terms of internationalization it would be great to configure whether to use . or , as a decimal "point". I'm from germany and in the german keyboard layout the point on the num pad is a comma, since we use commas instead of points.

English: 4,992.5
German: 4.992,5

I don't really care about the visual style, I can read english or german numbers equally well. However I mostly use the num pad for calculation inputs and it's really annoying to not be able to use the comma of the num pad.

As a result handling of german keyboard layouts (or others with a comma on the num pad) so the decimal point/comma is interpreted correctly would be a real improvement! Having the ui display commas instead of points would just be icing on top.

One example of handling it is in the graphical calculator extcalc. They always display decimal points but handle the keyboard layout in such a way, that the num pad emits a point instead of a comma.

@sharkdp
Copy link
Owner

sharkdp commented Sep 17, 2018

I'm also from Germany, so I feel you 😄

We have already discussed this in #104. I still stand by my statement:

I'd rather have a predictable and strict syntax for the calculator (that is based on the English language) compared to something that is properly 'internationalized' but requires me to know which mode I'm in. This is only a personal opinion, of course, but I'm always surprised if 3.145 is suddenly parsed as 3145 because . is just the thousands-separator in German

Back then, we decided that we could make this user-defined (via a hypothetical set decimal_separator "," syntax), but there is one more thing that I haven't thought of in the original discussion (or maybe it wasn't relevant at the time): we separate function arguments by the comma-operator. If we allow , to be a decimal-separator, expressions such as f(3,14) are really ambiguous. If we keep the current function-argument syntax, I don't think we should/could allow for , as a decimal separator.

One example of handling it is in the graphical calculator extcalc. They always display decimal points but handle the keyboard layout in such a way, that the num pad emits a point instead of a comma.

That is a potential solution that I never thought of. If there is a good way (in JavaScript) to detect a "comma on the num pad" (as opposed to a "comma anywhere on the keyboard"), we could certainly give this a try!

@targodan
Copy link
Author

targodan commented Sep 17, 2018

Right, I didn't think about the ambiguity of allowing commas. And I totally agree that given those considerations comma should not actually be interpreted as a decimal point.

There seems to be a way to get the keycodes to the keypress event (at least on web-JavaScript, I don't know my way around node at all). On my keyboard this seems to yield event.which == 110 or more expressively event.code == "NumpadDecimal"

Source:
http://keycode.info/ see the source code of this, in particular the scripts.js.

I also did a quick fiddle with the necessary code boiled down to almost the minimum. I don't know how you would do this in node.js, in particular with the terminal interface (maybe some hooks in that library?), but here is a way to detect it in Web-JavaScript: https://jsfiddle.net/targodan/xnery589/
Note, that it only seems to be possible to detect this in the keyDown handler, not the keyPress handler.

Edit:
Some further research lead to this: https://stackoverflow.com/questions/5006821/nodejs-how-to-read-keystrokes-from-stdin
I don't have any node expertise and don't have a node environment setup, so I can't really test it at the moment, but maybe it helps.

If I can find the time I may be able to setup a quick node environment and see if I can make it work somehow. I'm assuming this is the main equivalent of the program?

@targodan
Copy link
Author

So, after some testing and experimenting I am afraid it might be impossible. I certainly didn't get it to work and it might be due to how terminals handle key presses. I got readline to give me keypress events, those always just contained the character , but never the key code.

I found one workaround though. You can use the following command to have your numpad always emit a dot instead of a comma regardless of your keyboard layout: setxkbmap -option kpdl:dot

@sharkdp
Copy link
Owner

sharkdp commented Sep 18, 2018

So, after some testing and experimenting I am afraid it might be impossible. I certainly didn't get it to work and it might be due to how terminals handle key presses. I got readline to give me keypress events, those always just contained the character , but never the key code.

Ok - thank you very much for checking!

I found one workaround though. You can use the following command to have your numpad always emit a dot instead of a comma regardless of your keyboard layout: setxkbmap -option kpdl:dot

That's pretty cool! I think I'm going to use this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants