[Richard Suchenwirth] 2002-08-09 - In the [Tcl chatroom] we often notice what difference in greeting a timezone makes: morning in Germany is afternoon in Australia, etc. This brought me to think a little on the algorithm leading to selection of the appropriate greeting. Even just on the examples of English and German I notice that the boundaries appear not to be the same - "good afternoon" just cannot be translated to "guten Nachmittag", it is too un-idiomatic. Contributions for other languages are gladly taken (as usual!-) proc greet'en {} { scan [clock format [clock sec] -format %H] %d hr foreach {maxhr word} { 12 morning 18 afternoon 22 evening 99 night } {if {$hr < $maxhr} break} ;# (1) return "good $word" } proc greet'en-au {} { return "G'day" ;# stevel } proc greet'de {} { scan [clock format [clock sec] -format %H] %d hr foreach {maxhr word} { 11 "n Morgen" 17 "n Tag" 22 "n Abend" 99 " Nacht" } {if {$hr < $maxhr} break} return Gute$word } proc greet'es-ar {} { scan [clock format [clock sec] -format %H] %d hr foreach {maxhr word} { 12 "os i����as" 19 "as tardes" 99 "as noches" } {if {$hr < $maxhr} break} return buen$word } proc greet'fr {} { scan [clock format [clock sec] -format %H] %d hr foreach {maxhr word} { 19 "jour" 99 "soir" } {if {$hr < $maxhr} break} return bon$word } proc greet'pt {} { scan [clock format [clock sec] -format %H] %d hr foreach {maxhr word} { 12 "bom dia" 19 "boa tarde" 99 "boa noite" } {if {$hr < $maxhr} break} return $word } proc greet'nl {} { scan [clock format [clock sec] -format %H] %d hr foreach {maxhr word} { 12 "goeie morgen" 17 "goeie middag" 99 "goeienavond" } {if {$hr < $maxhr} break} return $word } proc greet'nl_nl_polite {} { scan [clock format [clock sec] -format %H] %d hr foreach {maxhr word} { 12 "goede morgen" 17 "goede middag" 99 "goedenavond" } {if {$hr < $maxhr} break} return $word } proc greet'nl_nl_informal {} { scan [clock format [clock sec] -format %H] %d hr foreach {maxhr word} { 12 "mogge" 17 "middag" 99 "n'avond" } {if {$hr < $maxhr} break} return $word } proc greet'nl_nl_impolite {} { scan [clock format [clock sec] -format %H] %d hr foreach {maxhr word} { 12 "hoi" 17 "hoi" 99 "(silence)" } {if {$hr < $maxhr} break} return $word } proc greet'sv {} { return Hej! } ---- % greet'en good afternoon % greet'de Guten Tag ---- (1): [kennykb]: "Good night" is non-idiomatic as a greeting. How about "Good heavens, why are you awake at this hour?" "Good night" would be something that might be used as a farewell though. For a greeting after about 6:00 PM, in my part of the US, you would hear "Good evening!" most frequently. ---- [RS]: Thanks for all who contributed! Looking at the code above, it is evident that cutting and pasting was in action. Maybe it's better (in many ways) to factor out the common parts, so the specific proc can concentrate on the specific details. Also, rearranging the maxhr/word list to word/maxhr puts the boundaries in the natural place and allows to do without the senseless "99": proc greet_ {format details} { scan [clock format [clock sec] -format %H] %d hr foreach {word maxhr} $details {if {$hr < $maxhr} break} format $format $word } proc greet'de {} {greet_ Gute%s {Morgen 11 "n Tag" 17 "n Abend"}} ... ---- [Natural languages] | [Arts and crafts of Tcl-Tk programming]