showing arabic and persian number like ١ ٩٠

molavy2003 - October 30, 2009 - 18:14
Project:Format Number API
Version:6.x-1.5
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:postponed (maintainer needs more info)
Description

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

#1

markus_petrux - October 30, 2009 - 19:35
Priority:critical» normal

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

#2

molavy2003 - October 31, 2009 - 05:10

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?

#3

markus_petrux - October 31, 2009 - 20:42
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.

#4

molavy2003 - November 2, 2009 - 09:24

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

#5

markus_petrux - November 2, 2009 - 09:54

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?

#6

molavy2003 - November 2, 2009 - 11:08

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?

#7

molavy2003 - November 4, 2009 - 07:15

what about JavaScript?
it will decrease server-side process

#8

molavy2003 - November 8, 2009 - 11:13

any idea?

#9

markus_petrux - November 10, 2009 - 04:07

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:

<?php
  $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);
?>

#10

molavy2003 - November 24, 2009 - 07:02

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

#11

markus_petrux - November 24, 2009 - 07:45

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.

 
 

Drupal is a registered trademark of Dries Buytaert.