Log in

View Full Version : can this be done client side



Steve Sea
12-03-2007, 07:15 PM
Hi all

Have a look at this http://www.leconjugueur.com/uknombre.php

I know it a php file but could the same thing be done client side or would the file be to big, obviously I can't see this file to see the size of it.

also how is it done ?

I've no php experience but would be prepared to mess around with a basic script

Twey
12-03-2007, 07:38 PM
It's certainly possible. Here's one I wrote for English (in Python, sorry, started translating it to JS but stopped halfway for some reason):
units = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
specunits = { "ten-one" : "eleven", "ten-two" : "twelve", "ten-three" : "thirteen", "ten-four" : "fourteen", "ten-five" : "fifteen", "ten-six" : "sixteen", "ten-seven" : "seventeen", "ten-eight" : "eighteen", "ten-nine" : "nineteen" }
tens = ["", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]

def num_to_english(num):
try:
num = int(num)
except ValueError:
return "Invalid input."

if num < -999 or num > 999:
return "Invalid input."

if num == 0:
return "zero"

if num < 0:
num = num * -1;
minus = "minus "
else:
minus = ""

nunits = num % 10
ntens = int(math.floor((num % 100) / 10))
nhunds = int(math.floor(num / 100))

if tens[ntens] and units[nunits]:
tandu = "%s-%s" % (tens[ntens], units[nunits])
else:
tandu = "%s%s" % (tens[ntens], units[nunits])

if tandu in specunits.keys():
tandu = specunits[tandu]

thunds = units[nhunds]
if thunds:
thunds = "%s hundred " % thunds
if units[nhunds]:
if (tens[ntens] or units[nunits]):
thunds = "%sand " % thunds
else:
tandu = ""

return minus + thunds + tanduIt still uses tabs, I must've written this ages ago :-\

Steve Sea
12-03-2007, 07:55 PM
English numbers ! how nice and easy (same as German.)

hundreds tens and units what a dream. :)

Now with the good old French system we run in to problems too many to list here, but a small part is like English then (for only reasons the French know) they do the equivalent of "four twenty's ten nine :eek:" (quatre-vingt-dix-neuf) 99 to the laymen of you.

so you can see it's a bit of a nightmare.

Twey
12-03-2007, 08:39 PM
Aye, I know (je parle français aussi) but if you treat "quatre-vingt" as a whole number it's no problem. Same with quatre-vingt-dix, with exceptions like I've done above for "twelve" and so.

Steve Sea
12-03-2007, 08:59 PM
Sorry I must be blind, I will have a play with the code, HTML is more my thing but will have a play and let you know if I can get a heart beat.

Merci beaucoup

Steve C.

djr33
12-03-2007, 10:35 PM
Twey, instead of if num == 0: return "zero", I'd consider including "":"zero" in your list of exceptions.