Re: [PATCH 1/2] gitk: Initialize msgcat before first use

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 1/2] gitk: Initialize msgcat before first use

From: Bernt Hansen <hidden>
Date: 2016-06-15 22:47:39

Pat Thoyts [off-list ref] writes:
Bernt Hansen [off-list ref] writes:
quoted
The error text generated when your version of Tcl is too old is
translated with msgcat (mc) before msgcat is initialized.  This
causes Tcl to abort with:

   Error in startup script: invalid command name "mc"

We now initialize msgcat first before we check the Tcl version.  Msgcat
is available since Tcl 8.1.
This doesn't quite work. [file normalize] was introduced with Tcl 8.4
and when I test this by starting it using Tcl 8.3 I get an error:
 "bad option "normalize": must be atime, attributes, channels..."
from line 11014. It is probably sufficient to just drop the [file
normalize] here. On Windows $argv0 is fully qualified and 
[file dirname] works ok on it. By removing the [file normalize] I get
the expected error dialog when testing with 8.3.
However, on Windows we actually get a better looking result by not
catching the [package require Tcl 8.4] and just letting Tk bring up a
standard message box with the version conflict error message.

Well, actually if show_error just used tk_messageBox it would look
better on Windows.
You're right.  Thanks for catching this.  When I tested this code I
bumped the version number temporarily to 8.5 instead of downgrading TK
to 8.3.

The problem I was trying to fix was show_error using mc internally
before it was initialized.  Maybe it would be better to give show_error
an optional parameter that controls calling mc - so that the call for
the version check can just bypass the mc translation of the text and OK
buttons.  With this approach the code I moved around can just stay where
it is and all of the existing calls to show_error will use the default
parameter setting which invokes mc.

Would that be a better approach?

-Bernt

[PATCH] Skip translation of wrong Tcl version text

From: Bernt Hansen <hidden>
Date: 2016-06-15 22:47:39

We check the required Tcl version number before we setup msgcat for
language translation.  If the Tcl version is too old just display the
untranslated error text.

The caller of show_error can now pass an alternative function for mc.
The Tcl list function turns the transalation into a no-op.

This fixes the
    Error in startup script: invalid command name "mc"
when attempting to start gitk with Tcl 8.3.

Signed-off-by: Bernt Hansen <redacted>
---
I tested this patch with both Tcl 8.3 and 8.4.

This is an alternative to the previous 2 patches I sent attempting
to initialize msgcat before first use.  This patch is much simpler
but does not attempt to translate the wrong version message text.

This patch fixes the version number error message by displaying it
untranslated since msgcat is not initialized yet.  The current
initialization code for msgcat uses normalize which is only available as
of Tcl 8.4 so moving the code up front didn't work in Tcl 8.3.

 gitk |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/gitk b/gitk
index a0214b7..d1f32a9 100755
--- a/gitk
+++ b/gitk
@@ -1787,10 +1787,10 @@ proc make_transient {window origin} {
     }
 }
 
-proc show_error {w top msg} {
+proc show_error {w top msg {mc mc}} {
     message $w.m -text $msg -justify center -aspect 400
     pack $w.m -side top -fill x -padx 20 -pady 20
-    button $w.ok -text [mc OK] -command "destroy $top"
+    button $w.ok -text [$mc OK] -command "destroy $top"
     pack $w.ok -side bottom -fill x
     bind $top <Visibility> "grab $top; focus $top"
     bind $top <Key-Return> "destroy $top"
@@ -11006,8 +11006,8 @@ proc get_path_encoding {path} {
 
 # First check that Tcl/Tk is recent enough
 if {[catch {package require Tk 8.4} err]} {
-    show_error {} . [mc "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
-		     Gitk requires at least Tcl/Tk 8.4."]
+    show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
+		     Gitk requires at least Tcl/Tk 8.4." list
     exit 1
 }
 
-- 
1.6.5.2.141.gc8a58

Re: [PATCH] Skip translation of wrong Tcl version text

From: Paul Mackerras <hidden>
Date: 2016-06-15 22:47:39

Bernt Hansen writes:
We check the required Tcl version number before we setup msgcat for
language translation.  If the Tcl version is too old just display the
untranslated error text.

The caller of show_error can now pass an alternative function for mc.
The Tcl list function turns the transalation into a no-op.

This fixes the
    Error in startup script: invalid command name "mc"
when attempting to start gitk with Tcl 8.3.

Signed-off-by: Bernt Hansen <redacted>
Thanks, applied.

Paul.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help