Time-dependent greetings

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 días" 19 "as tardes" 99 "as noches"
    } {if {$hr < $maxhr} break}
    return buen$word
}
proc greet'es-es {} {
    scan  [clock format [clock sec] -format %H] %d hr
    foreach {maxhr word} {
        14 "os días" 21 "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'fr-fr {} {
           return "Salut" ;# Kroc
}
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!
}

proc greet'is {} {
    set tmp(morning) [list "Góðann daginn" "Góðan dag"]
    set tmp(noon)      $tmp(morning)
    set tmp(afternoon) $tmp(noon)
    set tmp(evening) [list "Gott kvöld" "Kvöldið"]
    set tmp(night) "Góða nótt"
}
% 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_ "Guten %s" {Morgen 11 Tag 17 Abend}}
...

RS 2004-06-11: A generalization of this kind of range partitioning is at comb, so e.g for English one could write

puts "Good [comb $hr {morning 12 afternoon 18 evening}]"

LV Anyone want to discuss how one might code with msgcat in this case?


See also: Universal Greeting (a msgcat solution)