Re: [PATCH] Usage() help text is not completely translated



On Sat, Mar 21, 2009 at 2:42 PM, Stephen Kennedy <stevek gnome org> wrote:
>> was that string forgotten or is there something special about it ?
>>
>> The patch fixes other small glitches in the help texts...
>
> IIRC the string was so long, translations were getting stale as
> options were added.
> Perhaps you can break up the right hand sides into separate strings?

I didn't know how far you would like this split to go, so I over-engineered
the following patch...

It's split into 7 strings, which should be easy to translate. All
translatable text is exposed to gettext processing, even "file"
or "dir" in argument lists...

The output is:
"""
$ ./meld --toto
Usage:
meld                        Start with no window open
meld <dir>                  Start with Version Control browser in 'dir'
meld <file>                 Start with Version Control diff of 'file'
meld <file> <file> [<file>] Start with 2 or 3 way file comparison
meld <dir> <dir> [<dir>]    Start with 2 or 3 way directory comparison

meld: error: no such option: --toto
$
"""

That looks messed up in gmail but is in fact properly indented in a
terminal with fixed-width font...

I tried but failed to understand how to collect the new strings into
the .po files, so translation is not tested. But I promise to write
makefile rules to do the string update if someone explains how
to do it with xgettext, msgmerge, etc...

-- 
Vincent Legoll
Index: meldapp.py
===================================================================
--- meldapp.py	(revision 1285)
+++ meldapp.py	(working copy)
@@ -895,18 +895,40 @@
             [(gtk.STOCK_QUIT, gtk.RESPONSE_CANCEL), (gtk.STOCK_OK, gtk.RESPONSE_OK)] )
         if response == gtk.RESPONSE_CANCEL:
             sys.exit(0)
-        
+
+    def usage_msg(self):
+        usage_file = _("file")
+        usage_dir = _("dir")
+        usages = [[_("Start with no window open"), "", None],
+                  [_("Start with Version Control browser in '%s'"), "%s", usage_dir],
+                  [_("Start with Version Control diff of '%s'"), "%s", usage_file],
+                  [_("Start with 2 or 3 way file comparison"), "%s %s [%s]", usage_file],
+                  [_("Start with 2 or 3 way directory comparison"), "%s %s [%s]", usage_dir]]
+
+        ret = [""]
+        max_args_len = 0
+
+        for item in usages:
+            args = item[1]
+            if item[2]:
+                args = args % (("<%s>" % item[2],) * args.count("%s"))
+            item.append(args)
+            max_args_len = max(max_args_len, len(args))
+
+        for usage_message, notused, arg, args in usages:
+            if arg:
+                usage_message = usage_message % ((arg,) * usage_message.count("%s"))
+            ret.append("%prog " + "%s%s%s" %
+                       (args, " " * (1 + max_args_len - len(args)), usage_message))
+
+        return "\n".join(ret)
+
     def parse_args(self, rawargs):
         parser = optparse.OptionParser(
             option_class=misc.MeldOption,
-            usage="""
-            %prog                       Start with no windows open
-            %prog <dir>                 Start with VC browser in 'dir'
-            %prog <file>                Start with VC diff of 'file'
-            %prog <file> <file> [file]  Start with 2 or 3 way file comparison
-            %prog <dir>  <dir>  [dir]   Start with 2 or 3 way directory comparison""",
-            description="""Meld is a file and directory comparison tool.""",
-            version="%prog "+version)
+            usage=self.usage_msg(),
+            description=_("Meld is a file and directory comparison tool."),
+            version="%prog " + version)
         parser.add_option("-L", "--label", action="append", default=[], help=_("Set label to use instead of file name"))
         parser.add_option("-a", "--auto-compare", action="store_true", default=False, help=_("Automatically compare all differing files on startup"))
         parser.add_option("-u", "--unified", action="store_true", help=_("Ignored for compatibility"))
@@ -915,22 +937,22 @@
         parser.add_option("-r", "--recursive", action="store_true", help=_("Ignored for compatibility"))
         parser.add_option("", "--diff", action="diff_files", dest='diff',
                           default=[],
-                          help=_("Creates a diff tab for up to 3 supplied files."))
+                          help=_("Creates a diff tab for up to 3 supplied files or 3 directories."))
         options, args = parser.parse_args(rawargs)
         for files in options.diff:
             if len(files) not in (1, 2, 3):
                 self.usage(_("Invalid number of arguments supplied for --diff."))
             self.append_diff(files)
-        tab = self.open_paths(args, options.auto_compare)
-        if tab:
-            tab.set_labels( options.label )
+        if len(args) not in (1, 2, 3):
+            self.usage(_("Wrong number of arguments (Got %i)") % len(args))
+        else:
+            tab = self.open_paths(args, options.auto_compare)
+            if tab:
+                tab.set_labels(options.label)
 
     def open_paths(self, paths, auto_compare=False):
         tab = None
-        if len(paths) == 0:
-            pass
-
-        elif len(paths) == 1:
+        if len(paths) == 1:
             a = paths[0]
             if os.path.isfile(a):
                 doc = vcview.VcView(self.prefs)
@@ -946,8 +968,6 @@
                     
         elif len(paths) in (2,3):
             tab = self.append_diff(paths, auto_compare)
-        else:
-            self.usage( _("Wrong number of arguments (Got %i)") % len(paths))
         return tab
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]