Subversion Repositories wimsdev

Rev

Rev 10915 | Rev 14528 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

!if $wims_read_parm!=slib_header
 !goto proc
!endif

slib_author=Bernadette, Perrin-Riou; Raoul, Hatterer
slib_example=5678\
[678,122]\
[295,180],fr\
[295,180],en\
[181,1008,1081,200,201,280]\
[181,1008,1081,200,201,280],en\
[9880,99120],fr\
[9880,99120],en

[0,1,10,100,1000,10000,100000,1000000,10000000], fr\
[0,1,10,100,1000,10000,100000,1000000,10000000], en

!exit

:proc

slib_language= $(wims_read_parm[2])
!reset slib_out
slib_data= $(wims_read_parm[1])
slib_data=!declosing $slib_data
!if $slib_language=en
  !! english transcription
  !! author : Raoul HATTERER
  !! algorithm: http://www.blackwasp.co.uk/NumberToWords.aspx

  slib_smallNumbers = one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen
  slib_tyWords = , twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety
  slib_scaleNumbers = ,thousand, million, billion

  !for slib_number in $slib_data
    !! Zero Rule.
    !! If the value is zero then the number in words is 'zero'
    !! and no other rules apply.
    !if $slib_number==0
      slib_combined=zero
    !else
      !! Three Digit Rule.
      !! The integer value is split into groups of three digits starting from the right-hand side.
      !! Once converted to text, the three-digit groups are recombined with the addition
       !! of the relevant scale number (thousand, million, billion).

      !! The integer value is split into groups of three digits starting from the right-hand side.
       !reset slib_3digitsGroups
       !for slib_scale= 1 to 4
         slib_3digits=!char -3 to -1 of $slib_number
         slib_3digitsGroups=!append item $slib_3digits to $slib_3digitsGroups
        slib_number=!char 1 to -4 of $slib_number
       !next

      !! Each set of three digits is then processed individually as a number of hundreds, tens and units.
       !reset slib_textGroups
       !for slib_scale= 1 to 4
         slib_3digits= !column $slib_scale of $slib_3digitsGroups
         !if $slib_3digits > 99
           slib_hundreds=!char -3 of $slib_3digits
         !else
           slib_hundreds=0
         !endif
         slib_tensUnits=!char -2 to -1 of $slib_3digits
         slib_tens=!char -2 of $slib_3digits
         slib_units=!char -1 of $slib_3digits
          !! Hundreds Rules.
         !! If the hundreds portion of a three-digit group is not zero,
         !! the number of hundreds is added as a word.
         !! If the three-digit group is exactly divisible by one hundred,
         !! the text 'hundred' is appended.
         !! If not, the text "hundred and" is appended.
         !! eg. 'two hundred' or 'one hundred and twelve'
         !reset slib_3digitsText
         !if $slib_hundreds!=0
           slib_3digitsText = !column $slib_hundreds of $slib_smallNumbers
          slib_3digitsText = $slib_3digitsText hundred
           !if $slib_tensUnits!=00
             slib_3digitsText = $slib_3digitsText and
           !endif
         !endif

         !! Tens Rules.
         !! If the tens section of a three-digit group is two or higher,
         !! the appropriate '-ty' word (twenty, thirty, etc.) is added
         !! to the text and followed by the name of the third digit
         !! (unless the third digit is a zero, which is ignored).
         !! If the tens and the units are both zero, no text is added.
         !! For any other value, the name of the one or two-digit number
         !! is added as a special case.
         !if $slib_tens >= 2
           slib_tyWord=!column $slib_tens of $slib_tyWords
           slib_3digitsText= $slib_3digitsText $slib_tyWord
           !if $slib_units!= 0
             slib_unitWord=!column $slib_units of $slib_smallNumbers
             slib_3digitsText=$slib_3digitsText-$slib_unitWord
           !endif
         !else
           !if $[$slib_tensUnits]!= 0
             slib_tenUnitWord=!column $slib_tensUnits of $slib_smallNumbers
             slib_3digitsText= $slib_3digitsText $slib_tenUnitWord
           !endif
         !endif
         !if $slib_3digits==000
           slib_3digitsText=zero
         !endif
         slib_textGroups=!append item $slib_3digitsText to $slib_textGroups
       !next

       !! Recombination Rules.
       !! When recombining the translated three-digit groups,
       !! each group except the last is followed by a large number name
       !! and a comma,
       !! unless the group is blank and therefore not included at all.
       !! One exception is when the final group does not include
       !! any hundreds and there is more than one non-blank group.
       !! In this case, the final comma is replaced with 'and'.
       !! eg. 'one billion, one million and twelve'.

       slib_combined = !column 1 of $slib_textGroups
       !if $slib_combined=zero
         slib_combined=
       !endif
       slib_3digits=!column 1 of $slib_3digitsGroups
       !if $[$slib_3digits]>0 and $[$slib_3digits]<100
         slib_appendAnd=true
       !else
         slib_appendAnd=false
       !endif
       !for slib_scale = 2 to 4
         slib_3digits=!column $slib_scale of $slib_3digitsGroups
         !if $[$slib_3digits]!=0
            slib_3digitsText=!column $slib_scale of $slib_textGroups
            slib_scaleNumber=!column $slib_scale of  $slib_scaleNumbers
           slib_prefix = $slib_3digitsText $slib_scaleNumber
           !if $slib_appendAnd==true
             slib_prefix=$slib_prefix and
             slib_appendAnd=false
           !else
             slib_empty=!charcnt $slib_combined
             !if $slib_empty!=0
               slib_prefix=$slib_prefix,
             !endif
           !endif
           slib_combined=$slib_prefix $slib_combined
         !endif
       !next
    !endif
    slib_out=!append item $slib_combined to $slib_out
  !next
!else
  !! by default : french transcription
  !! author : Bernadette Perrin Riou
  slib_list=1,un\
  2,deux\
  3,trois\
  4,quatre\
  5,cinq\
  6,six\
  7,sept\
  8,huit\
  9,neuf\
  10,dix\
  11,onze\
  12,douze\
  13,treize\
  14,quatorze\
  15,quinze\
  16,seize\
  17,dix-sept\
  18,dix-huit\
  19,dix-neuf\
  20,vingt\
  21,vingt-et-un\
  22,vingt-deux\
  23,vingt-trois\
  24,vingt-quatre\
  25,vingt-cinq\
  26,vingt-six\
  27,vingt-sept\
  28,vingt-huit\
  29,vingt-neuf\
  30,trente\
  31,trente-et-un\
  32,trente-deux\
  33,trente-trois\
  34,trente-quatre\
  35,trente-cinq\
  36,trente-six\
  37,trente-sept\
  38,trente-huit\
  39,trente-neuf\
  40,quarante\
  41,quarante-et-un\
  42,quarante-deux\
  43,quarante-trois\
  44,quarante-quatre\
  45,quarante-cinq\
  46,quarante-six\
  47,quarante-sept\
  48,quarante-huit\
  49,quarante-neuf\
  50,cinquante\
  51,cinquante-et-un\
  52,cinquante-deux\
  53,cinquante-trois\
  54,cinquante-quatre\
  55,cinquante-cinq\
  56,cinquante-six\
  57,cinquante-sept\
  58,cinquante-huit\
  59,cinquante-neuf\
  60,soixante\
  61,soixante-et-un\
  62,soixante-deux\
  63,soixante-trois\
  64,soixante-quatre\
  65,soixante-cinq\
  66,soixante-six\
  67,soixante-sept\
  68,soixante-huit\
  69,soixante-neuf\
  70,soixante-dix\
  71,soixante-et-onze\
  72,soixante-douze\
  73,soixante-treize\
  74,soixante-quatorze\
  75,soixante-quinze\
  76,soixante-seize\
  77,soixante-dix-sept\
  78,soixante-dix-huit\
  79,soixante-dix-neuf\
  80,quatre-vingts\
  81,quatre-vingt-un\
  82,quatre-vingt-deux\
  83,quatre-vingt-trois\
  84,quatre-vingt-quatre\
  85,quatre-vingt-cinq\
  86,quatre-vingt-six\
  87,quatre-vingt-sept\
  88,quatre-vingt-huit\
  89,quatre-vingt-neuf\
  90,quatre-vingt-dix\
  91,quatre-vingt-onze\
  92,quatre-vingt-douze\
  93,quatre-vingt-treize\
  94,quatre-vingt-quatorze\
  95,quatre-vingt-quinze\
  96,quatre-vingt-seize\
  97,quatre-vingt-dix-sept\
  98,quatre-vingt-dix-huit\
  99,quatre-vingt-dix-neuf

  !for slib_j in $slib_data
    !reset slib_nb
    !if $slib_j=0
      slib_nb=zéro
      !goto loopend
    !endif
    slib_d=!char -2 of $slib_j
    slib_du=!char -2 to -1 of $slib_j
    slib_du=$[$slib_du]
    slib_dutext=!select $slib_list where column 1=$slib_du
    slib_nb=$(slib_dutext[2])
    slib_c=!char -3 of $slib_j
    slib_m=!char 1 to -4 of $slib_j

    !if $slib_c!=0 and $slib_c!=$empty
      !if $slib_c=1 or $slib_du!=0
        !if $slib_du=0
          slib_nb=cent
        !else
          slib_nb=cent-$slib_nb
        !endif
      !else
        !if $slib_du=0
          slib_nb=cents
       !else
         slib_nb=cents-$slib_nb
       !endif
     !endif
     slib_ctext=!select $slib_list where column 1=$slib_c
     !if $slib_c!=1
       slib_nb=$(slib_ctext[2])-$slib_nb
     !endif
    !endif
    !if $slib_m!=0 and $slib_m!=$empty
      slib_mtext=!select $slib_list where column 1=$slib_m
      slib_nb=mille-$slib_nb
     !if $slib_m!=1
       slib_nb=$(slib_mtext[2])-$slib_nb
     !endif
   !endif
   slib_nb=!nospace $slib_nb
   slib_test=!char -1 of $(slib_nb)
   !if $slib_test=-
     slib_nb=!char 1 to -2 of $(slib_nb)
   !endif
:loopend
   slib_out=!append item $slib_nb to $slib_out
  !next

  slib_out=!nospace $slib_out
!endif