Problem detecting decimal separator in WebDialog help page


#1

Working with Steve Baumgartner on Angular Dimension 2 (still in beta) I’ve come across a problem I don’t understand.

We have two WebDialogue html pages in the AD2 tool. One allows the user to input settings for the format of the angular dimension, and exchanges values between JavaScript and Ruby.

The other was initially only a static HTML page, until we got feedback that it should use (as the settings dialogue does) a comma for decimal separator in those locales where that is used (eventually, we hope to have translated dialogues as well, but not yet).

I’ve tried to implement this using a simple JS function to detect whether the locale uses dot or comma as the separator for decimal values.

function getDecimalSeparator() {
  var n = 1.1;
  const DECIMAL = n.toLocaleString().substring(1, 2);
  return DECIMAL;  
}

This works fine when the page is called by a click on the Help button in the settings page opened in Sketchup, on Windows 7. When the Region is set to one which uses a comma separator, the toLocaleString function returns a comma separated value.

One a Mac, it doesn’t work.

When the web page in which this function is called is opened directly in Safari, it correctly detects and uses a decimal separator.

But when opened in SU (2017, as on Windows tests) from the settings page, it only detects a dot separator.

Is this because I’m using an English version of SU, even though I have set the Mac’s system locale to French, and checked that it is using a comma separator?

The WebDialogue is, I believe, still using Safari internally. And I have the WebKit developers toolkit installed.

When I right click on the page in native Safari, after changing Region, Primary language, and comma separator, and restarting the computer, I get the option in French to Inspecter l’element.

In SU it still says ‘Inspect element’

This suggests to me that it might work if the user’s Sketchup installation is also the French version, but not the English version running on a French system.

Anyway, Steve has a workaround which now applies to the Help page, but I wondered if anyone else has found a good and simpler way of internationalizing Ruby/WebDialogue and now HTMLDialogue pages which get user input? If so, how?


#2
Sketchup::RegionalSettings.decimal_separator

is for going forward since v16M1…


#3

What would that give you in an English version of SU when the main system is set to French?


#4

the system setting, some people use periods some comma’s…

you can change it on a ‘English’ System as well…

I did it for some testing ages ago and came up with this for my webDialogs…

the ‘foot’ symbol is equally unhelpful…

//js
ary[i] = val[i].value.replace(",", "U+002C").replace("'", "U+0027")
# ruby
          input = []
          v.split(',').each do |c|
            input << c.sub('U+002C', ',').sub('U+0027', "'")
          end

EDIT:

john


#5

Steve and I got the foot and inch replacements working fine, by coding them to html &quot; and &apos;, and he has done it for the decimal separator too, in a different way from the one I tried.

On my Mac, I don’t have the option to choose comma when the primary language is English (El Capitan still) and there is no other preferred language. Now I also have French, when I go back to English as the language, I can now choose dot or comma in English.

Steve chose German for his testing on Mac, Sierra I think now for him.

I’ll come back to this in a day or two, after trying it. Busy on a few other things first, now that Steve has found a workaround in a different way.


#6

@john_mcclenahan, Also see this post discussing new and legacy Ruby-side detection of the list and decimal separators:


#7

@DanRathbun the method you describe in that linked post is pretty much what I did that John mentions above. I knew I got the idea somewhere good !


#8

I suspect the built in web browser engine uses dots regardless of the users locale. The Ruby code john_drivenupthewall is much safer to use since it actually returns what is used in the rest of SketchUp.


#9

That’s what Steve Baumgartner ended up doing. JS uses dot, regardless of the locale.


#10

Just an FYI, Thomas has an implementation of a locale helper and units classes posted in his GitHub repos.