slashme / parliamentdiagram

Parliament diagram creator
GNU General Public License v2.0
99 stars 27 forks source link

Localize the numbers in diagrams #118

Open mahozad opened 2 years ago

mahozad commented 2 years ago

The number(s) shown in the diagram always uses western Arabic numerals irrespective of the user locale.

Please update the code to generate alternative numbers for users with different locales (at least for my language Persian (also called Farsi) and also Arabic šŸ˜™). Note that Persian and Arabic numerals are different from each other.

This Wikipedia article and this can help.

Here is an example vector that shows the number based on the user (system) locale. The SVG shows Farsi (Persian) numerals if user locale matches Farsi, otherwise falls back to the default Western numerals for all other locales (the order in <switch> element matters).

I think in JavaScript, number.toLocaleString(Locale) can be used to produce localized numbers.

Below is an example.

index.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test</title>
<script src="script.js" defer></script>
</head>
<body>
  <h1>Farsi</h1>
  <p id="farsi"/>
  <hr>
  <h1>Arabic</h1>
  <p id="arabic"/>
</body>
</html>

script.js:

let num = 123456;
document.getElementById("farsi").innerHTML = num.toLocaleString("fa");
document.getElementById("arabic").innerHTML = num.toLocaleString("ar-EG");