-
Notifications
You must be signed in to change notification settings - Fork 67
Initial draft on number, currency, and unit formatting #693
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
Conversation
✅ Deploy Preview for i18n-drafts ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
questions/qa-number-format.en.md
Outdated
|
|
||
| Many regions, like the US and UK, use a period as the decimal separator (e.g., `1,234.56`). Conversely, much of Europe and South America use a comma (e.g., `1.234,56`). | ||
|
|
||
| In rare cases, a currency symbol can even act as a decimal separator, like the [Cape Verdean escudo](https://en.wikipedia.org/wiki/Cape_Verdean_escudo). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an example here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double barrd dollarsign doesn't seem to be encoded in Unicode. Should I use a picture to represent it?
questions/qa-number-format.en.md
Outdated
|
|
||
| **Symbol vs. Code vs. Name:** Currencies can be displayed using a specific symbol (e.g., `€`, `£`, `¥`), their ISO 4217 code (e.g., `EUR`, `GBP`, `JPY`), or their full name (e.g., `US Dollar`, `Japanese Yen`). | ||
|
|
||
| **Placement:** The symbol can appear before the number (e.g., `$100.00`) or after (e.g., `1,000 ₫`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example illustrates that white space also varies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
questions/qa-number-format.en.md
Outdated
|
|
||
| ## By the way | ||
|
|
||
| Typically, you'll want to format based on the user's browser language. You can get this from `navigator.language` or `navigator.languages`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this probably merits its own section. There may be times when it's best to use the browser settings, but usually its the page language or current section language that is more important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to thumbs-up this comment, but I'd be more emphatic. Typically you want to use the locale (language) of the page. Occasionally you'll want to override that with an author specified locale (such as when writing I18N tutorials). Rarely will you want to peek at browser language (and there is no way to do so at the server--Accept-Language isn't quite the same thing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I edited the content of this section.
questions/qa-number-format.en.md
Outdated
|
|
||
| ## Further reading | ||
|
|
||
| * [ECMAScript Internationalization API Specification](https://tc39.es/ecma402/) No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add some dos and donts to the Web and point to that, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm going to add the dos and donts after this article is published so that I can link to it.
aphillips
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review.
questions/qa-number-format.en.md
Outdated
|
|
||
| ## Question | ||
|
|
||
| **How do I prepare my web pages to display varying international number, currency, and unit formats?** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is the right question for what this article proceeds to talk about? JS is a mechanism for formatting data into strings dynamically in the page. Some parts of a Web page will need to do that, but this question sounds like it would cover server-side formatting.
I'll also call out that numbers and currencies are a broad topic. Units are complicated and might warrant separate coverage. (Currencies are complicated too, but are generally bundled with numbers. Don't overlook percentages, which are also commonly bundled, but which are a sort of unit.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is the right question for what this article proceeds to talk about? JS is a mechanism for formatting data into strings dynamically in the page. Some parts of a Web page will need to do that, but this question sounds like it would cover server-side formatting.
What about: How do I use JavaScript to dynamically format numbers, currencies, and units for different locales?
I'll also call out that numbers and currencies are a broad topic. Units are complicated and might warrant separate coverage. (Currencies are complicated too, but are generally bundled with numbers. Don't overlook percentages, which are also commonly bundled, but which are a sort of unit.)
Any specific suggestions? Should we expand this article or start a new one?
questions/qa-number-format.en.md
Outdated
|
|
||
| #### Currency symbol display | ||
|
|
||
| **Symbol vs. Code vs. Name:** Currencies can be displayed using a specific symbol (e.g., `€`, `£`, `¥`), their ISO 4217 code (e.g., `EUR`, `GBP`, `JPY`), or their full name (e.g., `US Dollar`, `Japanese Yen`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the full range. There are also "medium" width symbols used in various contexts, such as CA$, US$ and MX$
There are also contextual variations, e.g. ¥ vs. 円 (in sentences).
Symbols are not always a single code point and you should probably have some examples of those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I expanded this paragraph.
questions/qa-number-format.en.md
Outdated
|
|
||
| **Placement:** The symbol can appear before the number (e.g., `$100.00`) or after (e.g., `1,000 ₫`). | ||
|
|
||
| **Ambiguity:** The same symbol might represent multiple currencies (e.g., `$` for US Dollar, Canadian Dollar, Australian Dollar, etc.). So the locale is crucial. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The locale is crucial all the time. Note that the Mexican peso also uses $ and makes a good example (showing that $ doesn't mean the word dollar is lurking nearby)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Fixed.
jsahleen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great article! Mentioned a couple of minor points but nothing blocking.
questions/qa-number-format.en.md
Outdated
|
|
||
| ### Choosing the right locale | ||
|
|
||
| Typically, you'll want to format number, currency, and unit according to the language of the web page. This can be determined from the `lang` attribute: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think something about the wording here might lead people to think the lang attribute is populated by default, when it needs to be set. This isn't the right place for an in-depth discussion, I think, but is there an article or guide on choosing the right locale we can point to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsahleen if you want an article that's specifically about choosing the right locale you may be looking for https://www.w3.org/International/questions/qa-choosing-language-tags.en.html
Otherwise, there are a bunch of other language setting related articles at https://www.w3.org/International/articlelist#language
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I added a link.
Fix #410. Comments welcome.
Preview