From: Pat Thoyts Date: Thu, 19 Jun 2008 12:54:23 +0000 (+0100) Subject: make use of msgcat to support i18n X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=97f6f840225b2378062544503d79136027ec749e;p=Bullfrog make use of msgcat to support i18n --- diff --git a/bin/bf_xmpp.tcl b/bin/bf_xmpp.tcl index d9a984d..1122e4b 100644 --- a/bin/bf_xmpp.tcl +++ b/bin/bf_xmpp.tcl @@ -152,13 +152,13 @@ proc ::xmppplugin::post {ctx channel msg} { if {[regexp {^/invite\s+(\S+)\s+(.*)$} $msg -> who reason]} { $xmpp(jlib) muc invite $channel $who -reason $reason } else { - Callback $ctx system $channel "usage: /invite jid ?reason?" + Callback $ctx system $channel [mc "usage: %s" "/invite jid ?reason?"] } return } "/me *" { } default { - Callback $ctx system $channel "unrecognised chat command '$msg'" + Callback $ctx system $channel [mc "unrecognised chat command '%s'" $msg] return } } @@ -319,11 +319,11 @@ proc ::xmppplugin::OnMucEnter {ctx channel jlib xmldata} { set code [wrapper::getattribute $e code] set msg {} switch -exact -- $code { - 401 { set msg "This conference is password protected." } - 403 { set msg "You have been banned from this conference." } - 404 { set msg "The requested server does not exist." } - 405 { set msg "The maximum number of participants has been reached."} - 407 { set msg "You must be a member to enter this conference." } + 401 { set msg [mc "This conference is password protected."] } + 403 { set msg [mc "You have been banned from this conference."] } + 404 { set msg [mc "The requested server does not exist."] } + 405 { set msg [mc "The maximum number of participants has been reached."]} + 407 { set msg [mc "You must be a member to enter this conference."] } 409 { # nick conflict upvar #0 $ctx xmpp @@ -333,12 +333,12 @@ proc ::xmppplugin::OnMucEnter {ctx channel jlib xmldata} { JoinMUC $ctx $channel $jlib $xmpp(-nick) } default { - set msg "An unknown error was returned on attempting to join the\ - conference." + set msg [mc "An unknown error was returned on attempting\ + to join the conference."] } } if {$msg ne {}} { - tk_messageBox -icon error -title "Failed to join conference" \ + tk_messageBox -icon error -title [mc "Failed to join conference"] \ -message $msg } } @@ -385,7 +385,7 @@ proc ::xmppplugin::OnMucConfigured {ctx channel jlib type subiq} { proc ::xmppplugin::ShowForm {ctx form} { set dlg [toplevel .xmppform -class Dialog] - wm title $dlg "Configure room" + wm title $dlg [mc "Configure room"] wm withdraw $dlg set f [ttk::frame $dlg.f] set wid 0 @@ -496,7 +496,7 @@ proc ::xmppplugin::OnIqVersionResult {ctx jlib from subiq args} { } } err]} { tk_messageBox -icon error -message $err \ - -title "Error handling version result" + -title [mc "Error handling version result"] } return 1 ;# handled } @@ -809,7 +809,7 @@ proc XmppLogin {app} { set dlg [toplevel $dlg -class Dialog] wm withdraw $dlg wm transient $dlg $app - wm title $dlg "Login" + wm title $dlg [mc "Login"] set f [ttk::frame $dlg.f] set g [ttk::frame $f.g] @@ -866,9 +866,9 @@ proc XmppLogin {app} { Grid $fa row 2 column 1 EnableChildren $f.ac [Var xmpp -autoconnect] - ttk::button $f.ok -text Login -default active \ + ttk::button $f.ok -text [mc "Login"] -default active \ -command [list set [namespace which -variable $dlg] "ok"] - ttk::button $f.cancel -text Cancel \ + ttk::button $f.cancel -text [mc "Cancel"] \ -command [list set [namespace which -variable $dlg] "cancel"] @@ -937,7 +937,7 @@ proc XmppAddXmlConsole {app} { grid $w.text $w.vs -sticky news -padx 1 -pady 1 grid rowconfigure $w 0 -weight 1 grid columnconfigure $w 0 -weight 1 - $app.nb add $w -text XML + $app.nb add $w -text [mc "XML"] jlib::setdebug 2 if {[info commands ::jlib::_Debug] eq {}} { rename ::jlib::Debug ::jlib::_Debug @@ -1111,11 +1111,11 @@ proc XmppChannelNickMenu {Chat w x y} { set m [menu $w.nickmenupopup -tearoff 0] $m add command -label "$nick" -state disabled $m add separator - $m add command -label "Chat" -underline 0 \ + $m add command -label [mc "Chat"] -underline 0 \ -command [namespace code [list XmppChannelNickCommand $Chat chat $nick]] - $m add command -label "Whois" -underline 0 -state disabled \ + $m add command -label [mc "Whois"] -underline 0 -state disabled \ -command [namespace code [list XmppChannelNickCommand $Chat whois $nick]] - $m add command -label "Version" -state normal \ + $m add command -label [mc "Version"] -state normal \ -command [namespace code [list XmppChannelNickCommand $Chat version $nick]] tk_popup $m [winfo pointerx $w] [winfo pointery $w] } @@ -1237,23 +1237,23 @@ proc XmppCallback {Session context state args} { #puts stderr [list $Session $context $state $args] switch -exact -- $state { init { - Status $Session "Attempting to connect to $xmpp(-server)" + Status $Session [mc "Attempting to connect to %s" $xmpp(-server)] } connect { XmppCallback $Session $context debug \ - "Logging into $xmpp(-server) as $xmpp(-username)" + [mc "Logging into %s as %s" $xmpp(-server) $xmpp(-username)] Status $Session "Connection to XMPP server established." State $Session connected } disconnect { foreach {reason} $args break if {$reason ne {}} { set reason ": $reason" } - Status $Session "Disconnected$reason" + Status $Session [mc "Disconnected%s" $reason] State $Session disconnected } close { foreach {target} $args break - Debug $Session "closing $target" + Debug $Session [mc "closing $s" $target] XmppRemoveWindow $Session $target } addchat { @@ -1309,7 +1309,7 @@ proc XmppCallback {Session context state args} { -jid {} -role { } -version { - Status $Session "$nick using $value" + Status $Session [mc "%s using %s" $nick $value] } } } @@ -1366,16 +1366,17 @@ proc XmppCallback {Session context state args} { joining { XmppCreateWindow $Session $target -type groupchat} entered { eval [linsert $args 0 $w name add $nick] - $w message "$nick $action" -nick $nick -type system + $w message [mc "%s entered" $nick] -nick $nick -type system } left { $w name delete $nick - $w message "$nick $action" -nick $nick -type system + $w message [mc "%s left" $nick] -nick $nick -type system } nickchange { $w name delete $nick eval [linsert $args 0 $w name add $new] - $w message "$nick is now known as $new" -nick $nick -type system + $w message [mc "%s is now known as %s" $nick $new] \ + -nick $nick -type system } default { $w message "$nick $action" -nick $nick -type system diff --git a/bin/bullfrog.tcl b/bin/bullfrog.tcl index 43d8262..765b3e6 100644 --- a/bin/bullfrog.tcl +++ b/bin/bullfrog.tcl @@ -5,22 +5,25 @@ # jabberlib from the coccinella project). # It makes use of the chatwidget from tklib # -# Copyright (C) 2007 Pat Thoyts +# Copyright (C) 2007-2008 Pat Thoyts # # See the file "license.terms" for information on usage and redistribution of # this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# $Id: picoirc.tcl,v 1.2 2007/10/24 10:35:25 patthoyts Exp $ +# $Id$ package require Tk 8.5 package require chatwidget 1.1; # tklib package require tooltip 1.4; # tklib +package require msgcat; # tcl core +namespace import ::msgcat::mc if {![catch {package require autoproxy}]} { autoproxy::init } set root [file dirname [info script]] +::msgcat::mcload [file join $root msgs] source [file join $root message.tcl] source [file join $root tab.tcl] @@ -61,17 +64,19 @@ proc Main {args} { set menu [menu $app.menu -tearoff 0] # File menu $menu add cascade -label Network -menu [menu $menu.file -tearoff 0] - $menu.file add command -label "IRC Login..." -underline 0 \ + $menu.file add command -label [mc "IRC Login..."] -underline 0 \ -command [namespace code [list IrcLogin $app]] if {[llength [info commands XmppLogin]] != 0} { - $menu.file add command -label "Jabber Login..." -underline 0 \ + $menu.file add command -label [mc "Jabber Login..."] -underline 0 \ -command [namespace code [list XmppLogin $app]] } $menu.file add separator - $menu.file add command -label Exit \ + $menu.file add command -label [mc "Exit"] \ -command [namespace code [list Exit $app]] - # Windows menu - $menu add cascade -label Window \ + $menu add cascade -label [mc "Action"] \ + -menu [menu $menu.action -tearoff 0 \ + -postcommand [namespace code [list OnPostAction $app $menu.action]]] + $menu add cascade -label [mc "Window"] \ -menu [menu $menu.window -tearoff 0 \ -postcommand [namespace code [list OnPostWindow $app $menu.window]]] @@ -79,23 +84,23 @@ proc Main {args} { ttk::notebook $app.nb -style ButtonNotebook - if {$opts(-debug)} { - set debugf [frame $app.nb.debugf -borderwidth 0 -highlightthickness 0] - set debug [ttk::frame $app.nb.debugf.debug -style ChatwidgetFrame] - text $debug.text -relief flat -borderwidth 0 -wrap word \ - -state disabled -font DebugFont \ - -yscrollcommand [list $debug.vs set] - $debug.text tag configure read -foreground blue3 - $debug.text tag configure write -foreground red3 - ttk::scrollbar $debug.vs -command [list $debug.text yview] - grid $debug.text $debug.vs -sticky news -padx 1 -pady 1 - grid rowconfigure $debug 0 -weight 1 - grid columnconfigure $debug 0 -weight 1 - grid $debug -sticky news - grid rowconfigure $debugf 0 -weight 1 - grid columnconfigure $debugf 0 -weight 1 - $app.nb add $debugf -text Debug - } + # Always create the debug tab - but hide it unless -debug given + set debugf [frame $app.nb.debugf -borderwidth 0 -highlightthickness 0] + set debug [ttk::frame $app.nb.debugf.debug -style ChatwidgetFrame] + text $debug.text -relief flat -borderwidth 0 -wrap word \ + -state disabled -font DebugFont \ + -yscrollcommand [list $debug.vs set] + $debug.text tag configure read -foreground blue3 + $debug.text tag configure write -foreground red3 + ttk::scrollbar $debug.vs -command [list $debug.text yview] + grid $debug.text $debug.vs -sticky news -padx 1 -pady 1 + grid rowconfigure $debug 0 -weight 1 + grid columnconfigure $debug 0 -weight 1 + grid $debug -sticky news + grid rowconfigure $debugf 0 -weight 1 + grid columnconfigure $debugf 0 -weight 1 + $app.nb add $debugf -state hidden -text [mc "Debug"] + if {$opts(-debug)} { $app.nb tab $debugf -state normal } set status [ttk::frame $app.status] ttk::label $status.pane0 -anchor w @@ -186,16 +191,45 @@ proc Debug {Chat message {type debug}} { } proc bgerror {args} { - tk_messageBox -icon error -title "Error" -message $::errorInfo + tk_messageBox -icon error -title [mc "Error"] -message $::errorInfo +} + +# The action window will depend upon the currently active tab. +# if it is a jabber or irc link we call different bits. +proc OnPostAction {app menu} { + set ndx 0 + $menu delete 0 end + set mod [expr {[tk windowingsystem] eq "aqua" ? "Cmd" : "Ctrl"}] + + # NB: window name (xmpp1) maps to an array variable. + # var(type) will be the connectin type + switch -glob -- [winfo name [$app.nb select]] { + xmpp* { + # main: xmpp1 + # muc: xmpp1tcl@tach_tclers_tk + # user: xmpp1tcl@tach_tclers_tk/rmax + $menu add command -label [mc "Join channel..."] -underline 0 \ + -command [namespace code [list OnPostActionJoinChannel $app]] + } + irc* { + # main: irc0 + # channel: irc0#tcltest + } + xmlconsole - + debug* - + default { + # error + } + } } proc OnPostWindow {app menu} { set ndx 0 $menu delete 0 end set mod [expr {[tk windowingsystem] eq "aqua" ? "Cmd" : "Ctrl"}] - $menu add command -label "Close tab" -underline 0 \ + $menu add command -label [mc "Close tab"] -underline 0 \ -command [namespace code [list CloseWindow $app]] - $menu add command -label "Detach tab" -underline 0 \ + $menu add command -label [mc "Detach tab"] -underline 0 \ -command [namespace code [list DetachWindow $app]] $menu add separator set tabs [$app.nb tabs] @@ -271,7 +305,6 @@ proc WindowTitle {Session w {title {}}} { } } - proc UrlEnter {w} { variable cursor:$w set cursor:$w [$w cget -cursor] @@ -293,7 +326,8 @@ proc UrlClick {w x y} { } if {[string length $url] > 0} { if {[catch {GotoURL $w $url} err]} { - tk_messageBox -icon error -type ok -title "An error occurred"\ + tk_messageBox -icon error -type ok \ + -title [mc "An error occurred"]\ -message $err } } @@ -328,9 +362,10 @@ proc GotoURL {w url} { if {[catch { eval exec [auto_execok start] [list $url] & } err]} then { + set msg [mc "Error displaying \"%s\" in browser" $url] + append msg "\n" $err tk_messageBox -icon error -type ok \ - -title "Failed top open url" \ - -message "Error displaying \"$url\" in browser\n$err" + -title [mc "Failed to open url"] -message $msg } } } @@ -342,9 +377,9 @@ proc GotoURL {w url} { } default { tk_messageBox -icon error -type ok \ - -title "Unsupported platform" \ - -message "Your platform \"$tcl_platform(platform)\"\ - is not supported. Contact the developers." + -title [mc "Unsupported platform"] \ + -message [mc "Your platform \"%s\" is not supported.\ + Contact the developers." $tcl_platform(platform)] } } $dlg configure -cursor {} diff --git a/bin/msgs/en.msg b/bin/msgs/en.msg new file mode 100644 index 0000000..bfb3e9f --- /dev/null +++ b/bin/msgs/en.msg @@ -0,0 +1,63 @@ +# -*- tcl -*- +package require msgcat +namespace import ::msgcat::mcset + +# Tab names +mcset en "Debug" "Debug" +mcset en "XML" "XML" + +# Error items +mcset en "Error" "Error" +mcset en "An error occurred" "An error occurred" +mcset en "Failed to open url" "Failed to open url" +mcset en "Error displaying \"%s\" in browser" "Error displaying \"%s\" in browser" +mcset en "Error handling version result" "Error handling version result" +mcset en "Unsupported platform" "Unsupported platform" +mcset en "Your platform \"%s\" is not supported. Contact the developers." \ + "Your platform \"%s\" is not supported. Contact the developers." +mcset en "unrecognised chat command '%s'" "unrecognised chat command '%s'" +mcset en "usage: %s" "usage: %s" + +# Menu items +mcset en "Network" "Network" +mcset en "IRC Login..." "IRC Login..." +mcset en "Jabber Login..." "Jabber Login..." +mcset en "Exit" "Exit" +mcset en "Action" "Action" +mcset en "Window" "Window" +mcset en "Close tab" "Close tab" +mcset en "Detach tab" "Detach tab" +mcset en "Chat" "Chat" +mcset en "Whois" "Whois" +mcset en "Version" "Version" + +# Chat channel/room actions +mcset en "%s is now known as %s" "%s is now known as %s" +mcset en "%s entered" "%s entered" +mcset en "%s left" "%s left" +mcset en "%s using %s" "%s using %s" +mcset en "Attempting to connect to %s" "Attempting to connect to %s" +mcset en "Logging into %s as %s" "Logging into %s as %s" +mcset en "Disconnected%s" "Disconnected%s" +mcset en "closing %s" "closing %s" + +# Dialog items +mcset en "OK" "OK" +mcset en "Cancel" "Cancel" +mcset en "Login" "Login" +mcset en "Configure room" "Configure room" + +# Jabber error messages +mcset en "Failed to join conference" "Failed to join conference" +mcset en "This conference is password protected."\ + "This conference is password protected." +mcset en "You have been banned from this conference."\ + "You have been banned from this conference." +mcset en "The requested server does not exist."\ + "The requested server does not exist." +mcset en "The maximum number of participants has been reached."\ + "The maximum number of participants has been reached." +mcset en "You must be a member to enter this conference."\ + "You must be a member to enter this conference." +mcset en "An unknown error was returned on attempting to join the conference" \ + "An unknown error was returned on attempting to join the conference" \ No newline at end of file