Results 1 to 6 of 6

Thread: can this be done client side

  1. #1
    Join Date
    Apr 2007
    Location
    Southwest France
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default can this be done client side

    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

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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):
    Code:
    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 + tandu
    It still uses tabs, I must've written this ages ago :-\
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2007
    Location
    Southwest France
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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 " (quatre-vingt-dix-neuf) 99 to the laymen of you.

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

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Apr 2007
    Location
    Southwest France
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Twey, instead of if num == 0: return "zero", I'd consider including "":"zero" in your list of exceptions.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •