PxPlus User Forum

Twitter Twitter Twitter

Author Topic: locale settings in chromium browser  (Read 1999 times)

Thomas Bock

  • Diamond Member
  • *****
  • Posts: 177
    • View Profile
locale settings in chromium browser
« on: August 29, 2019, 10:34:57 AM »
We use "parseFloat(value).toLocaleString();" in order to display decimal values with german formatting.
On my V14 WindX client I see english formatting.
On my V16 WindX client I see german formatting.
On our TS with a V14 WindX client I see german formatting.
On my colleague's V14 WindX client I see german formatting.

The OS settings for decimal formatting are all set correctly for both of us.
What else may have an effect on the formatting?

Marginalia: None of us sees options in the popup menu due to installation issues.

Devon Austen

  • Administrator
  • Diamond Member
  • *****
  • Posts: 382
  • Don’t Panic
    • View Profile
    • PVX Plus Technologies
Re: locale settings in chromium browser
« Reply #1 on: August 29, 2019, 11:03:47 AM »
I would suspect that versions before 2019 (v16) would always treat the locale as US since it was not until 2019 that we implemented multi-language support for the embedded browser.

I would suggest resolving the installation issues (probably by doing a clean install in a new directory). If you are not getting a popup menu that means that the embedded chromium browser is not running correctly and any test results could be the result of undefined behavior cause by this.
Principal Software Engineer for PVX Plus Technologies LTD.

Frank Dreßler

  • Guest
Re: locale settings in chromium browser
« Reply #2 on: August 29, 2019, 12:20:40 PM »
As a workaround you could specify the target language "de-DE" explicitly like this:
Code: [Select]
(123456789.123456789).toLocaleString("de-DE")

Frank Dreßler

  • Guest
Re: locale settings in chromium browser
« Reply #3 on: August 29, 2019, 01:43:55 PM »
Here is a more convenient workaround. After executing this code once any calls to toLocaleString/toLocaleTimeString/toLocaleDateString behave as if "de-DE" was passed explicitly. It should not be executed twice.

It might be considered bad practice to change the prototype of built-in objects and functions. One negative side effect of this work-around is the fact that .toLocaleString() does not behave like .toLocaleString(navigator.language) anymore.

Code: [Select]
// Hooks Number's and Date's .toLocale...() to use "de-DE" in case no language is passed expliclitly.
(function(defaultLocale) {
function hookObjectFunction(obj, name, hook) {
const orig = obj[name];
obj[name] = function(...args) { return hook.call(this, orig, args); }
}

function defaultLocaleHook(orig, args) {
args[0] = args[0] || defaultLocale;
return orig.apply(this, args);
}

hookObjectFunction(Date.prototype, "toLocaleDateString", defaultLocaleHook);
hookObjectFunction(Date.prototype, "toLocaleTimeString", defaultLocaleHook);
hookObjectFunction(Date.prototype, "toLocaleString", defaultLocaleHook);
hookObjectFunction(Number.prototype, "toLocaleString", defaultLocaleHook);
})("de-DE");

EDIT: Fixed a bug (orig.call() changed to orig.apply())
« Last Edit: August 30, 2019, 05:38:48 AM by Frank Dreßler »