]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: Protect against bad translation strings
authorShawn O. Pearce <spearce@spearce.org>
Tue, 23 Oct 2007 22:44:55 +0000 (18:44 -0400)
committerShawn O. Pearce <spearce@spearce.org>
Fri, 26 Oct 2007 07:08:37 +0000 (03:08 -0400)
If a translation string uses a format character we don't have an
argument for then it may throw an error when we attempt to format
the translation.  In this case switch back to the default format
that comes with the program (aka the English translation).

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
git-gui.sh

index 38c6e595d85db2f2314a5fc671436bc891ac0e67..a7227ac1b6fddaad0f197b13ee26af9d372ebeca 100755 (executable)
@@ -88,13 +88,20 @@ if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
 
 package require msgcat
 
-proc mc {fmt args} {
-       set fmt [::msgcat::mc $fmt]
+proc _mc_trim {fmt} {
        set cmk [string first @@ $fmt]
        if {$cmk > 0} {
-               set fmt [string range $fmt 0 [expr {$cmk - 1}]]
+               return [string range $fmt 0 [expr {$cmk - 1}]]
        }
-       return [eval [list format $fmt] $args]
+       return $fmt
+}
+
+proc mc {en_fmt args} {
+       set fmt [_mc_trim [::msgcat::mc $en_fmt]]
+       if {[catch {set msg [eval [list format $fmt] $args]} err]} {
+               set msg [eval [list format [_mc_trim $en_fmt]] $args]
+       }
+       return $msg
 }
 
 proc strcat {args} {