hi there
how can i show numbers in page persian (arabic)format

Comments

markus_petrux’s picture

Priority: Critical » Normal

Do you have a URL to an official spec? Also, an example of what you mean would be nice.

molavy2003’s picture

www.tollabsh.ir
when i select farsi(persian) language in drupal local module .
numbers not translate
so in persian text it show english number

is this in your task?

markus_petrux’s picture

Status: Active » Postponed (maintainer needs more info)

I'm afraid no one is translating numbers. Drupal itself does not, and Format Number module only deals with decimal point and thousands separator symbols.

I would be glad to try to include this as a new feature in Format Number API. However, I would need a reference to official standards for different representations of numbers, and then it would be possible to evaluate if this is easy to do here, or something that would be better covered from a separate module.

molavy2003’s picture

http://unicode.org/glossary/
Arabic-Indic digits

http://www.unicode.org/versions/Unicode5.0.0/ch08.pdf#G20596
keep in mind that Persian number just in pages must showed
if them save in sql it will be not search able in internal search

markus_petrux’s picture

hmm... looking at the file ch08.pdf, it seems we may just need to convert European digits into *something else*, based on the Table 8-1. Arabic Digit Names?

Name                 Code Points      Forms
European             U+0030..U+0039   0123456789
Arabic-Indic         U+0660..U+0669   ٠١٢٣٤٥٦٧٨٩
Eastern Arabic-Indic U+06F0..U+06F9   äÒÚÛÙıˆ˜¯˘
Indic (Devanagari)   U+0966..U+096F   ivwx  yz{|}~

If so, this should only happen on output, when rendering numbers, and we could implement this here as an additional option, next to the current ones that already allow us configure decimal point and thousands separator symbols.

Looks right?

molavy2003’s picture

i think so
this is really basic feature
do you think we can request support on next drupal version
or contribute on develop in this case?

molavy2003’s picture

what about JavaScript?
it will decrease server-side process

molavy2003’s picture

any idea?

markus_petrux’s picture

Sorry, I do not have the time right now to work on a patch for this feature. Patches are welcome. I guess the idea would be that we need to add an additional option to choose the digits between "European", "Arabic-Indic", "Eastern Arabic-Indic" and "Indic (Devanagari)". This should be a site wide setting as well as a user setting, the same as the other decpoint and thsep.

In the meantime, you may try with something like this:

  $arabic_indic_digits = array(
    "\xD9\xA0",
    "\xD9\xA1",
    "\xD9\xA2",
    "\xD9\xA3",
    "\xD9\xA4",
    "\xD9\xA5",
    "\xD9\xA6",
    "\xD9\xA7",
    "\xD9\xA8",
    "\xD9\xA9",
  );
  $number = 1234.56;
  $formatted_number = format_number($number, 2);
  $arabic_number = str_replace(array_keys($arabic_indic_digits), $arabic_indic_digits, $formatted_number);
molavy2003’s picture

about input textbox
how can i show Persian number while persian and arabic user filling form
and save them on sql in english format?

markus_petrux’s picture

Support for Form API elements is something I would like to add in the future to this module, but for the moment, this is not possible due to lack of time.

In the meantime, I think you could do it using your own implementation of hook_form_alter(), and probably #pre_render callback, in custom module. Here you would have to find out the proper form elements, transform the numbers to arabic/persian/whatever before the HTML is sent to the browser. Also, insert an #element_validate callback on top of the list of other possible callbacks for those form elements, and there you can transform the arabic/persian/whatever numbers to european format when the form is sent.

markus_petrux’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Due to lack of time, also because I do not need this feature for our projects, and Drupal surely allows you to alter the output of anything, it is possible to provide custom solutions on top of this API.

Since no one else seems to be working on this feature I'm marking this issue as won't fix. Feel free to re-open if you can provide a patch for review.

sa3er’s picture

You can convert English digits to Persian digits using this JavaScript code in your template:

<script type="text/javascript">
var replaceDigits = function() {
	var map = ["&\#1776;","&\#1777;","&\#1778;","&\#1779;","&\#1780;", "&\#1781;","&\#1782;","&\#1783;","&\#1784;","&\#1785;"]
	document.body.innerHTML = document.body.innerHTML.replace(/\d(?=[^<>]*(<|$))/g, function($0) { return map[$0]});
}
window.onload = replaceDigits;
</script>

And also your body tag should have a onload attribute like the following:
<body onload="replaceDigits()">

tommann’s picture

I found a work around for my English/Persian site. If you use an embedded fonts for the Persian/Arabic that uses the same characters set for the numbers as a western fonts the Arabic-Hindi numbers will work.

http://70.40.203.42/