e5ee292000-09-24Martin Nilsson // // --- Abstract language class --- // Handles the conversion of numbers and dates. You have to restart the server for updates to take effect. //
ecd4982000-01-17Martin Nilsson  // Array(string) with the months of the year, beginning with January constant months = ({ "", "", "", "", "", "", "", "", "", "", "", "" }); // Array(string) with the days of the week, beginning with Sunday constant days = ({ "", "", "", "", "", "", "" });
e0c79f2016-08-22Jonas Walldén // Separator to implode list like ({ "foo", "bar", "fie", fum" }) => // "foo, bar, fie SEPARATOR fum". constant implode_conjunction = "and";
ecd4982000-01-17Martin Nilsson // Array(string) with all the language's identifiers constant _aliases = ({});
ced8b32000-01-26Martin Nilsson // Array(string) with language code, the language in english // and the native language description. constant _id = ({ "??", "Unknown", "Unknown" });
ecd4982000-01-17Martin Nilsson 
d103152000-09-09Martin Nilsson constant languages = ([]);
ecd4982000-01-17Martin Nilsson array id() { return _id; } string month(int num) { return months[ num - 1 ]; }
70c91e2013-03-22Henrik Grubbström (Grubba) // Some languages (eg russian) have a different form // of the month name if it's part of a date. string numbered_month(int num) { return month(num); }
cc99262003-07-15Anders Johansson string short_month(int num) { return months[ num - 1 ][..2]; }
ecd4982000-01-17Martin Nilsson string day(int num) { return days[ num - 1 ]; }
cc99262003-07-15Anders Johansson string short_day(int num) {
f952052004-08-05Henrik Grubbström (Grubba)  return days[ num - 1 ][..2];
cc99262003-07-15Anders Johansson }
ecd4982000-01-17Martin Nilsson array aliases() { return _aliases; } string language(string code) {
d103152000-09-09Martin Nilsson  if(sizeof(code)==2) code=Standards.ISO639_2.map_639_1(code);
e527fd2002-08-12Jonas Wallden  if(sizeof(code || "")!=3) return 0;
d103152000-09-09Martin Nilsson  if(languages[code]) return languages[code]; return Standards.ISO639_2.get_language(code);
ecd4982000-01-17Martin Nilsson }
0d5cc42000-03-21Martin Nilsson mapping list_languages() {
d103152000-09-09Martin Nilsson  mapping iso639_1=Standards.ISO639_2.list_639_1(); return Standards.ISO639_2.list_languages()+ mkmapping(indices(iso639_1), map(values(iso639_1), Standards.ISO639_2.get_language));
0d5cc42000-03-21Martin Nilsson }
ecd4982000-01-17Martin Nilsson string number(int i) { return (string)i; } string ordered(int i) { return (string)i; } string date(int i, mapping|void m) { mapping lt=localtime(i); return sprintf("%4d-%02d-%02d", lt->year+1900, lt->mon+1, lt->mday); }
e0c79f2016-08-22Jonas Walldén  string implode(array(string) items) { return String.implode_nicely(items, implode_conjunction); }