@matheusbsbs / matheus-bagliano / commits / ab0d33c438
Fork 0

git-gui: Protect against bad translation strings

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>

Shawn O. Pearce committed Oct 23, 2007 at 18:44 UTC ab0d33c43852b047c2a3e5ae960df9a146363e7c
1 file changed +11 -4
git-gui.sh
+11 -4
@@ -88,13 +88,20 @@ if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
88
89 package require msgcat
90
91 -proc mc {fmt args} {
92 - set fmt [::msgcat::mc $fmt]
91 +proc _mc_trim {fmt} {
92 set cmk [string first @@ $fmt]
93 if {$cmk > 0} {
95 - set fmt [string range $fmt 0 [expr {$cmk - 1}]]
94 + return [string range $fmt 0 [expr {$cmk - 1}]]
95 }
97 - return [eval [list format $fmt] $args]
96 + return $fmt
97 +}
98 +
99 +proc mc {en_fmt args} {
100 + set fmt [_mc_trim [::msgcat::mc $en_fmt]]
101 + if {[catch {set msg [eval [list format $fmt] $args]} err]} {
102 + set msg [eval [list format [_mc_trim $en_fmt]] $args]
103 + }
104 + return $msg
105 }
106
107 proc strcat {args} {