{"thread":{"id":"11553","subject":"[PATCH] gitk: Fix the Makefile to cope with systems lacking msgfmt","startedAt":"2008-01-09T14:31:09Z","lastAt":"2008-01-09T14:31:09Z","messageCount":1,"participants":["Charles Bailey"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"64855","messageId":"20080109143109.GA15069@hashpling.org","threadId":"11553","inReplyTo":null,"subject":"[PATCH] gitk: Fix the Makefile to cope with systems lacking msgfmt","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2008-01-09T14:31:09Z","receivedAt":"2008-01-09T14:31:09Z","isPatch":true,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"The po2msg.sh script and the .gitignore in the po directory have been\nshamelessly copied from the current git-gui.  This enables the top\nlevel \"make NO_MSGFMT\" to work consistently for git across the git-gui\nand gitk sub-projects.\n\nThis is the same effective patch that has previously been posted as a\ngit.git patch which more succinctly described the copying of\npo/.gitignore and po/po2msg.sh from git-gui.\n\nSigned-off-by: Charles Bailey <charles@hashpling.org>\n---\n Makefile      |    7 +++-\n po/.gitignore |    2 +\n po/po2msg.sh  |  133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 141 insertions(+), 1 deletions(-)\n create mode 100644 po/.gitignore\n create mode 100644 po/po2msg.sh\n\ndiff --git a/Makefile b/Makefile\nindex 6158504..ae2b80b 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -18,7 +18,12 @@ TCLTK_PATH_SQ = $(subst ','\\'',$(TCLTK_PATH))\n \n ## po-file creation rules\n XGETTEXT   ?= xgettext\n-MSGFMT     ?= msgfmt\n+ifdef NO_MSGFMT\n+\tMSGFMT ?= $(TCL_PATH) po/po2msg.sh\n+else\n+\tMSGFMT ?= msgfmt\n+endif\n+\n PO_TEMPLATE = po/gitk.pot\n ALL_POFILES = $(wildcard po/*.po)\n ALL_MSGFILES = $(subst .po,.msg,$(ALL_POFILES))\ndiff --git a/po/.gitignore b/po/.gitignore\nnew file mode 100644\nindex 0000000..a89cf44\n--- /dev/null\n+++ b/po/.gitignore\n@@ -0,0 +1,2 @@\n+*.msg\n+*~\ndiff --git a/po/po2msg.sh b/po/po2msg.sh\nnew file mode 100644\nindex 0000000..c63248e\n--- /dev/null\n+++ b/po/po2msg.sh\n@@ -0,0 +1,133 @@\n+#!/bin/sh\n+# Tcl ignores the next line -*- tcl -*- \\\n+exec tclsh \"$0\" -- \"$@\"\n+\n+# This is a really stupid program, which serves as an alternative to\n+# msgfmt.  It _only_ translates to Tcl mode, does _not_ validate the\n+# input, and does _not_ output any statistics.\n+\n+proc u2a {s} {\n+\tset res \"\"\n+\tforeach i [split $s \"\"] {\n+\t\tscan $i %c c\n+\t\tif {$c<128} {\n+\t\t\t# escape '[', '\\' and ']'\n+\t\t\tif {$c == 0x5b || $c == 0x5d} {\n+\t\t\t\tappend res \"\\\\\"\n+\t\t\t}\n+\t\t\tappend res $i\n+\t\t} else {\n+\t\t\tappend res \\\\u[format %04.4x $c]\n+\t\t}\n+\t}\n+\treturn $res\n+}\n+\n+set output_directory \".\"\n+set lang \"dummy\"\n+set files [list]\n+set show_statistics 0\n+\n+# parse options\n+for {set i 0} {$i < $argc} {incr i} {\n+\tset arg [lindex $argv $i]\n+\tif {$arg == \"--statistics\"} {\n+\t\tincr show_statistics\n+\t\tcontinue\n+\t}\n+\tif {$arg == \"--tcl\"} {\n+\t\t# we know\n+\t\tcontinue\n+\t}\n+\tif {$arg == \"-l\"} {\n+\t\tincr i\n+\t\tset lang [lindex $argv $i]\n+\t\tcontinue\n+\t}\n+\tif {$arg == \"-d\"} {\n+\t\tincr i\n+\t\tset tmp [lindex $argv $i]\n+\t\tregsub \"\\[^/\\]$\" $tmp \"&/\" output_directory\n+\t\tcontinue\n+\t}\n+\tlappend files $arg\n+}\n+\n+proc flush_msg {} {\n+\tglobal msgid msgstr mode lang out fuzzy\n+\tglobal translated_count fuzzy_count not_translated_count\n+\n+\tif {![info exists msgid] || $mode == \"\"} {\n+\t\treturn\n+\t}\n+\tset mode \"\"\n+\tif {$fuzzy == 1} {\n+\t\tincr fuzzy_count\n+\t\tset fuzzy 0\n+\t\treturn\n+\t}\n+\n+\tif {$msgid == \"\"} {\n+\t\tset prefix \"set ::msgcat::header\"\n+\t} else {\n+\t\tif {$msgstr == \"\"} {\n+\t\t\tincr not_translated_count\n+\t\t\treturn\n+\t\t}\n+\t\tset prefix \"::msgcat::mcset $lang \\\"[u2a $msgid]\\\"\"\n+\t\tincr translated_count\n+\t}\n+\n+\tputs $out \"$prefix \\\"[u2a $msgstr]\\\"\"\n+}\n+\n+set fuzzy 0\n+set translated_count 0\n+set fuzzy_count 0\n+set not_translated_count 0\n+foreach file $files {\n+\tregsub \"^.*/\\(\\[^/\\]*\\)\\.po$\" $file \"$output_directory\\\\1.msg\" outfile\n+\tset in [open $file \"r\"]\n+\tfconfigure $in -encoding utf-8\n+\tset out [open $outfile \"w\"]\n+\n+\tset mode \"\"\n+\twhile {[gets $in line] >= 0} {\n+\t\tif {[regexp \"^#\" $line]} {\n+\t\t\tif {[regexp \", fuzzy\" $line]} {\n+\t\t\t\tset fuzzy 1\n+\t\t\t} else {\n+\t\t\t\tflush_msg\n+\t\t\t}\n+\t\t\tcontinue\n+\t\t} elseif {[regexp \"^msgid \\\"(.*)\\\"$\" $line dummy match]} {\n+\t\t\tflush_msg\n+\t\t\tset msgid $match\n+\t\t\tset mode \"msgid\"\n+\t\t} elseif {[regexp \"^msgstr \\\"(.*)\\\"$\" $line dummy match]} {\n+\t\t\tset msgstr $match\n+\t\t\tset mode \"msgstr\"\n+\t\t} elseif {$line == \"\"} {\n+\t\t\tflush_msg\n+\t\t} elseif {[regexp \"^\\\"(.*)\\\"$\" $line dummy match]} {\n+\t\t\tif {$mode == \"msgid\"} {\n+\t\t\t\tappend msgid $match\n+\t\t\t} elseif {$mode == \"msgstr\"} {\n+\t\t\t\tappend msgstr $match\n+\t\t\t} else {\n+\t\t\t\tputs stderr \"I do not know what to do: $match\"\n+\t\t\t}\n+\t\t} else {\n+\t\t\tputs stderr \"Cannot handle $line\"\n+\t\t}\n+\t}\n+\tflush_msg\n+\tclose $in\n+\tclose $out\n+}\n+\n+if {$show_statistics} {\n+\tputs [concat \"$translated_count translated messages, \" \\\n+\t\t\"$fuzzy_count fuzzy ones, \" \\\n+\t\t\"$not_translated_count untranslated ones.\"]\n+}\n-- \n1.5.4.rc2.60.gb2e62\n"}]}