Skip to content

Commit ab0d33c

Browse files
committed
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>
1 parent f4e9996 commit ab0d33c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

git-gui.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,20 @@ if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
8888

8989
package require msgcat
9090

91-
proc mc {fmt args} {
92-
set fmt [::msgcat::mc $fmt]
91+
proc _mc_trim {fmt} {
9392
set cmk [string first @@ $fmt]
9493
if {$cmk > 0} {
95-
set fmt [string range $fmt 0 [expr {$cmk - 1}]]
94+
return [string range $fmt 0 [expr {$cmk - 1}]]
9695
}
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
98105
}
99106

100107
proc strcat {args} {

0 commit comments

Comments
 (0)