14 Replies Latest reply on Nov 4, 2013 9:30 AM by TᴀW

    JS: Convert Arabic numbers to Hebrew

    Peter Kahrel Adobe Community Professional & MVP

      Does anyone know of a function (preferably JavaSript) to convert Arabic numbers to Hebrew?

       

      Thanks,

       

      Peter

        • 1. Re: JS: Convert Arabic numbers to Hebrew
          TᴀW Adobe Community Professional & MVP

          Which version of InDesign?

          • 2. Re: JS: Convert Arabic numbers to Hebrew
            TᴀW Adobe Community Professional & MVP

            Actually, my question is not so relevant. There is a built-in function

            to convert between Farsi, Arabic and Hindi, but not Hebrew, from CS6 up.

            • 3. Re: JS: Convert Arabic numbers to Hebrew
              TᴀW Adobe Community Professional & MVP

              I don't know of a function, but as it is a little bit complicated, I

              would be tempted, if you have the right version of InDesign, to create a

              story with a number list using the Hebrew style of your choice, then

              convert to text, load it up into an array, and delete.

               

              Otherwise you're going to have to deal with a number of peculiarities

              (such as 15 and 16 being represented as 96 and 97 instead of 10+5 and

              10+6 to avoid the inadvertent use of the name of God), and so on.

              • 4. Re: JS: Convert Arabic numbers to Hebrew
                Peter Kahrel Adobe Community Professional & MVP

                Thanks, Ariel. Odd that there's a built-in conversion function for Farsi, Arabic and Hindi, but not for Hebrew. That would be the ME version, right? I was looking to convert plain Arabic numbers to Hebrew irrespective of the ID version. I found a description of how to do the conversion (http://www.i18nguy.com/unicode/hebrew-numbers.html). It should be possible to script it, but I thought I'd look around for something existing first. Nothing shows up on Google, and I was hoping that you or Harbs might have something.

                 

                Peter

                • 5. Re: JS: Convert Arabic numbers to Hebrew
                  TᴀW Adobe Community Professional & MVP

                  Well, I think that Farsi, Hindi and Arabic numbers have a one-to-one

                  correlation. It's just a question of replacing the glyphs. Hebrew

                  numbering is not decimal based, so it's more complicated. (Yes, ME

                  edition, starting in CS6 -- called "transliterate". So you've got

                  doc.findChangeTransliterateOptions, myText.findTransliterate etc. etc.

                  It's a new tab in the find/change dialog box.)

                  • 6. Re: JS: Convert Arabic numbers to Hebrew
                    TᴀW Adobe Community Professional & MVP

                    What's the biggest number you need, by the way?

                    • 7. Re: JS: Convert Arabic numbers to Hebrew
                      TᴀW Adobe Community Professional & MVP

                      This should do the trick. A bit clunky, but it seems to work, for numbers between 1 and 999:

                       

                      do{

                      myNumber = prompt("Please enter a number between 1 and 999");

                      }

                      while (myNumber < 1 && myNumber > 999);

                      sNumber = String(myNumber);

                      numberLength = sNumber.length;

                      sTens = sHundreds = 0;

                      sUnits = sNumber[numberLength-1];

                      if (myNumber > 9) sTens = sNumber[numberLength-2];

                      if (myNumber > 99) sHundreds = sNumber[numberLength-3];

                      hebrewHundreds = ["", "ק", "ר", "ש", "ת", "תק", "תר", "תש", "תת", "תתק"];

                      hebrewTens = ["", "י", "כ", "ל", "מ", "נ", "ס", "ע", "פ", "צ"];

                      hebrewUnits = ["", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט"];

                      myHebrewNumber = hebrewHundreds[sHundreds]+hebrewTens[sTens]+hebrewUnits[sUnits]+"*";

                      myHebrewNumber = myHebrewNumber.replace("יו*", "טז*");

                      myHebrewNumber = myHebrewNumber.replace("יה*", "טו*");

                      myHebrewNumber = myHebrewNumber.slice(0, myHebrewNumber.length-1);

                      alert(sNumber + " in Hebrew numbering is \r"+myHebrewNumber);

                       

                       

                      Ariel

                      • 8. Re: JS: Convert Arabic numbers to Hebrew
                        TᴀW Adobe Community Professional & MVP

                        Here's a link to the file, as the editor in these forums doesn't seem able to cope:

                         

                        www.freelancebookdesign.com/ArabicToHebrewNumbers.zip

                         

                        Ariel

                        • 9. Re: JS: Convert Arabic numbers to Hebrew
                          TᴀW Adobe Community Professional & MVP

                          Well, first bug: That should be an || not an && in the while statement, obviously.

                          • 10. Re: JS: Convert Arabic numbers to Hebrew
                            Trevorׅ Adobe Community Professional

                            Hi Peter and Ariel,

                             

                            I wrote this some time back,

                            http://creative-scripts.com/?wpdmact=process&did=NC5ob3RsaW5r

                            Note: Hebrew numbers don't use decimals / fractions.

                             

                            Regards

                             

                            Trevor

                             

                            var  w = new Window ("dialog", "Gematria", undefined, {}),
                                    g1 = w.add('group'),
                                    g2 = w.add('group'),
                                    g3 = w.add('group');
                                    s1 = g1.add('statictext', undefined, "Hebrew Word or Number"),
                                    s2 = g2.add('statictext', undefined, "Hebrew Number"),
                                    s3 = g3.add('statictext', undefined, "Arabic (English) Number"),
                                    g = g1.add ('edittext', undefined, "",{}),
                                    n = g2.add ('edittext', undefined, "", {readonly: true}),
                                    d = g3.add ('edittext', undefined, "");
                            
                            s1.characters = s2.characters = s3.characters = 20;
                            g.characters = n.characters = d.characters = 40;
                            g.onChanging = function () 
                                {
                                    t = g.text.replace(/[^א-ת\"]/g,"");
                                    if (t.length)
                                    {
                                        var gem = calculateGematria (t);
                                        d.text = gem;
                                        n.text =  numberToAmmud (gem);
                                     } else  {d.text = ""; n.text =  ""}
                                 }
                                n.onChanging = function () {n.text = n.text.replace(/[^\d]/g,"")}
                                d.onChanging = function () {
                                    dt = d.text.replace(/[^0-9+*\-\/"]/g,"");
                                    n.text =  numberToAmmud (dt)
                                    } 
                                
                                w.show()
                                
                            
                            function numberToAmmud (daf)
                                {  
                                     if (!daf > 0) return "";
                                    var  thousands = ["","א׳","ב׳","ג׳","ד׳","ה׳","ו׳","ז׳","ח׳","ט׳"],
                                            hundreds = ["","ק","ר","ש","ת","תק","תר","תש","תת","תתק"],
                                            tens = ["","י","כ","ל","מ","נ","ס","ע","פ","צ"],
                                            ones = ["","א","ב","ג","ד","ה","ו","ז","ח","ט"],
                                            ten = tens[Math.floor((daf/10))%10],
                                            one = ones[daf%10],
                                            hundred = hundreds[(Math.floor(daf/100))%10],
                                            thousand = thousands[(Math.floor(daf/1000))%10],
                                            aVerylot = "",
                                            c = 10000000000000000;
                                            if (daf >c) return "Number tooooooo big"
                                            while (c > 1000) {aVerylot +=  thousands[(Math.floor(daf/c))%10]; c = c/10}
                                    if (ten == "י" && one == "ה") {ten = "ט"; one = "ו";}
                                    else if (ten == "י" && one == "ו")  {ten = "ט"; one = "ז";}
                                    else if (hundred == "ר" && ten == "צ" && one == "ח")  {ten = "ח"; one = "צ";}
                                    else if (hundred == "ש" && ten == "מ" && one == "ד")  {ten = "ד"; one = "מ";}
                                    var ammud = aVerylot + thousand + hundred+ten+one;
                                    if  (ammud.length > 1 && (one !=0 || ten !=0 || hundred !=0 )) ammud = ammud.slice (0,ammud.length-1) +"״" +ammud.slice (ammud.length-1,ammud.length);
                                   // ammud = aOrB + ammud;
                                   if (!ammud.length)  ammud = " " ;
                                    return  ammud;
                                 }
                            
                            function calculateGematria (x)
                                {
                                    
                                    var   myWords = x.replace (/[^א-ת ]+/g,""),
                                            myWords = myWords.match (/[א-ת]+/g),
                                            l = myWords.length,
                                            gematria = 0;
                                    while (l--)
                                        {
                                            var  mySingles = myWords[l].replace(/[^א-ט]+/g,""),
                                                    myTens =  myWords[l].replace(/[^י-ץ]+/g,""),
                                                    myHundreds =  myWords[l].replace(/[^קשרת]+/g,""),
                                                    sl = mySingles.length,
                                                    tl = myTens.length,
                                                    hl = myHundreds.length;
                                            while (sl--) // singles
                                                {
                                                    gematria += mySingles.charCodeAt (sl) - 1487;
                                                 }
                                             var tenss = 0;
                                              while (tl--) // tens
                                                {
                                                    
                                                    if (myTens.charCodeAt (tl) > 1508)  tenss= 90;
                                                    else if (myTens.charCodeAt (tl) > 1506) tenss= 80;
                                                    else if(myTens.charCodeAt (tl) > 1505) tenss= 70;
                                                    else if(myTens.charCodeAt (tl) > 1504) tenss= 60;
                                                    else if(myTens.charCodeAt (tl) > 1502) tenss= 50;
                                                    else if (myTens.charCodeAt (tl) > 1500) tenss= 40;
                                                    else if (myTens.charCodeAt (tl) > 1499) tenss= 30;
                                                    else if (myTens.charCodeAt (tl) > 1497) tenss= 20;
                                                    else  tenss= 10;
                                                    gematria += tenss;
                                                 }
                                                while (hl--) // hundreds
                                                {
                                                       gematria += 100 * (myHundreds.charCodeAt (hl)-1510) ;
                                                 }
                                            }
                                            return gematria + " ";
                                            }
                            
                            • 11. Re: JS: Convert Arabic numbers to Hebrew
                              Trevorׅ Adobe Community Professional

                              P.s. Works at properly up to  9999

                              Can fix it up for higher numbers is you need.

                              • 12. Re: JS: Convert Arabic numbers to Hebrew
                                Trevorׅ Adobe Community Professional

                                Peter

                                 

                                I think the 1,000,000 and 3,000,000 examples in your link are not kosher.

                                In my opinion http://smontagu.org/writings/HebrewNumbers.html larger numbers example is better.

                                Ariel, would you agree?

                                 

                                Trevor

                                • 13. Re: JS: Convert Arabic numbers to Hebrew
                                  Peter Kahrel Adobe Community Professional & MVP

                                  Thanks, Trevor. Since I know almost nothing about Hebrew I couldn't say if the details on that web site are kosher. But even to my untrained eye the site you mentioned (smontagu) looks more reliable. Thanks.

                                   

                                  Peter

                                  • 14. Re: JS: Convert Arabic numbers to Hebrew
                                    TᴀW Adobe Community Professional & MVP

                                    I think anything above 999 is best dealt with by adding the word

                                    "thousands" (אלפים) in most written contexts. In page/paragraph numbers,

                                    I guess a letter with a geresh is normal. I don't think it's

                                    standardized really, and it's probably hard to find numbers above 999

                                    written as gematriyas in old sources anyway.