b1fca01996-11-12Per Hedbor /* Bugs by: Per */
2f2cc71997-08-19Per Hedbor /* * name = "English language plugin "; * doc = "Handles the conversion of numbers and dates to English. You have to restart the server for updates to take effect."; */
b1fca01996-11-12Per Hedbor 
bacc0c2000-01-17Martin Nilsson inherit "abstract.pike";
ced8b32000-01-26Martin Nilsson constant cvs_version = "$Id: english.pike,v 1.11 2000/01/26 00:29:54 nilsson Exp $"; // English is a special case, since it is also the standard language... constant _id = ({ "en", "standard", "english" });
bacc0c2000-01-17Martin Nilsson constant _aliases = ({ "en", "eng", "english" }); constant months = ({ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }); constant days = ({ "Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday" }); constant languages=([ "ca":"catalan", "cs":"czech", "du":"dutch", "fi":"finnish", "fr":"french", "de":"german", "en":"english", "es":"spanish", "hr":"croatian", "hu":"hungarian", "it":"italian", "jp":"japanese", "mi":"maori", "no":"norwegian", "pl":"polish", "pt":"portuguese", "ru":"russian", "si":"slovenian", "sr":"serbian", "sv":"swedish" ]);
b1fca01996-11-12Per Hedbor  string ordered(int i) { switch(i) { case 0: return "buggy"; case 1:
bacc0c2000-01-17Martin Nilsson  return "1st";
b1fca01996-11-12Per Hedbor  case 2: return "2nd"; case 3: return "3rd"; default: if((i%100 > 10) && (i%100 < 14)) return i+"th";
bacc0c2000-01-17Martin Nilsson  if((i%10) == 1)
b1fca01996-11-12Per Hedbor  return i+"st";
bacc0c2000-01-17Martin Nilsson  if((i%10) == 2)
b1fca01996-11-12Per Hedbor  return i+"nd"; if((i%10) == 3) return i+"rd"; return i+"th"; } } string date(int timestamp, mapping|void m) { mapping t1=localtime(timestamp); mapping t2=localtime(time(0)); if(!m) m=([]); if(!(m["full"] || m["date"] || m["time"])) { if(t1["yday"] == t2["yday"] && t1["year"] == t2["year"]) return "today, "+ ctime(timestamp)[11..15];
bacc0c2000-01-17Martin Nilsson 
b1fca01996-11-12Per Hedbor  if(t1["yday"]+1 == t2["yday"] && t1["year"] == t2["year"]) return "yesterday, "+ ctime(timestamp)[11..15];
bacc0c2000-01-17Martin Nilsson 
b1fca01996-11-12Per Hedbor  if(t1["yday"]-1 == t2["yday"] && t1["year"] == t2["year"]) return "tomorrow, "+ ctime(timestamp)[11..15];
bacc0c2000-01-17Martin Nilsson 
b1fca01996-11-12Per Hedbor  if(t1["year"] != t2["year"]) return (month(t1["mon"]+1) + " " + (t1["year"]+1900)); return (month(t1["mon"]+1) + " " + ordered(t1["mday"])); } if(m["full"]) return ctime(timestamp)[11..15]+", "+ month(t1["mon"]+1) + " the "
54af481997-01-09Janne K Edelman  + ordered(t1["mday"]) + ", " +(t1["year"]+1900);
b1fca01996-11-12Per Hedbor  if(m["date"]) return month(t1["mon"]+1) + " the " + ordered(t1["mday"])
54af481997-01-09Janne K Edelman  + " in the year of " +(t1["year"]+1900);
b1fca01996-11-12Per Hedbor  if(m["time"]) return ctime(timestamp)[11..15]; } string number(int num) { if(num<0) return "minus "+number(-num); switch(num) { case 0: return ""; case 1: return "one"; case 2: return "two"; case 3: return "three"; case 4: return "four"; case 5: return "five"; case 6: return "six"; case 7: return "seven"; case 8: return "eight"; case 9: return "nine"; case 10: return "ten"; case 11: return "eleven"; case 12: return "twelve"; case 13: return "thirteen"; case 14: return "fourteen"; case 15: return "fifteen"; case 16: return "sixteen"; case 17: return "seventeen"; case 18: return "eighteen"; case 19: return "nineteen"; case 20: return "twenty"; case 30: return "thirty"; case 80: return "eighty"; case 40: return "forty"; case 60: case 70: case 90: return number(num/10)+"ty"; case 50: return "fifty";
bacc0c2000-01-17Martin Nilsson  case 21..29: case 31..39: case 51..59: case 61..69: case 71..79: case 81..89: case 91..99: case 41..49:
b1fca01996-11-12Per Hedbor  return number((num/10)*10)+number(num%10);
969ba11998-03-19Henrik Grubbström (Grubba)  case 100: case 200: case 300: case 400: case 500: case 600: case 700: case 800: case 900: return number(num/100)+" hundred"; case 101..199: case 201..299: case 301..399: case 401..499: case 501..599: case 601..699: case 701..799: case 801..899: case 901..999: return number(num/100)+" hundred and "+number(num%100);
fbcc9e1998-09-22Henrik Grubbström (Grubba)  case 1001..1099:
32f3421998-09-22Johan Sundström  return number(num/1000)+" thousand and "+number(num%1000);
fbcc9e1998-09-22Henrik Grubbström (Grubba)  case 1000: case 1100..999999:
32f3421998-09-22Johan Sundström  return number(num/1000)+" thousand "+number(num%1000); case 1000001..1000099: return number(num/1000000)+" million and "+number(num%1000000); case 1000000: case 1000100..999999999:
b1fca01996-11-12Per Hedbor  return number(num/1000000)+" million "+number(num%1000000); default: return "many"; } }