-
Notifications
You must be signed in to change notification settings - Fork 103
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
Adding Numeral system to locales #40
Comments
function numeralReplacer(numerals) {
function replace(i) {
return numerals[+i];
}
return function(string) {
return string.replace(/[0-9]/g, replace);
};
}
var numeralIndia = numeralReplacer(["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]);
numeralIndia("1,234.56"); // "۱,۲۳۴.۵۶" More generally, I worry that this little library won‘t do enough to support other locales, and it might be better to encourage people to use a different, more full-featured, library such as jQuery Globalize. Globalize appears to support this feature already, for instance. |
Ok, I agree with you, we can
And for Arabic locales, zero padding will not be used but I haven`t problem to include it if we take into our consideration the other numeral system.
Supporting Arabic/Indic numerals in D3.format will be very important for us at IBM, as a Globalization team at IBM Egypt one of our tasks is supporting the open source technologies that IBM products use with globalize and bidi features to full fill its gap in Arabic area. And as D3 is used by tools that IBM products use, we need to support it with the missing bidi features like Arabic locales, Arabic/indic numeral system, hijri calendar for date formatting, which are considered very important for Arabic countries to meet their expectations in visualizing their data with Arabic/Indic numerals and their dates at hijri date format and to achieve that we highly need to support the numeral system here and hijri calendar at D3.time and arabic locales at d3.time.format. All of these features when compaining with each others will produce understandable and readable data for arabic users. |
Yes. My point was only that you can use D3 with other number and date formatters. The d3-format and d3-time-format are provided by default, but there’s no reason you can’t also (or instead) use jQuery Globalize, Moment, or another library, passing in the appropriate function to axis.tickFormat or wherever else you need localization. Anyway, the numeral replacer seems easy enough. |
Fixed in #41; released in 1.1.0. Thank you! |
As D3 supports different locales, we need also to add numeral system to these locales
When users select a locale file they also expect to see numbers formated in a numeral system based on the selected locale.
for example: if we talk about users from saudi arabia, when they select ar-SA as their locale file, they expect to see arabic/ indic numerals - ٠١٢٣٤٥٦٧٨٩ - instead of European numerals - 0123456789 - .
on the other hand users from Tunisia, when selecting ar-TN, they expect to see European numerals
and to solve this problem, I suggest to
Add the next function to locale.js file to formatNumerals
then call it immediately before adding padding, valuePrefix @ newFormat function as follows:
and for now as I am interesting to support Arabic users I will add one of 2 numerals types (European or arabic/indic) at each locale. (ar-*.json)
and for the remaining locales I will define numerals as european numerals.
The text was updated successfully, but these errors were encountered: