Formatting numbers using current locale
Summary
GitLab displays numbers in a number of places (
Should we agree on a "global" way to format numbers according to user defined locale? Which locale should it be?
The problem
Numbers are formatted using differently depending on locale:
| Value | English | Spanish |
|---|---|---|
1000 |
1,000 | 1.000 |
2.95 |
2.95 | 2,95 |
Possible solutions
GitLab's user settings allow users to select a language.
Example: The selected language sets the document lang, so we could do:
{{ (1000).toLocaleString(document.documentElement.lang) }} <!-- A `utils` could do this for us :) -->
{{ (5.1).toLocaleString(document.documentElement.lang) }}
We assume users' have configured their preferred locale in their browser, so we use the browser default formatting.
Example:
{{ (1000).toLocaleString() }} <!-- locale defaults to OS/browser settings --->
{{ (5.1).toLocaleString() }}
We keep rendering numbers as always.
Example:
{{ 1000 }} <!-- This will simply JS rendering: "1000" --->
{{ 5.1 }}
Expect RFC outcome
Gather info to document the recommended way to render numbers in our UI in the GitLab frontend guidelines.
Further development work would help enforce the guidelines with libs, linters, etc... that help us get it right easily.