Rev 6137: (jr) add class GettextIndentedHelpFormatter to add gettext translations to in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Sep 7 18:12:35 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6137 [merge]
revision-id: pqm at pqm.ubuntu.com-20110907181233-bqblr4015tngodbc
parent: pqm at pqm.ubuntu.com-20110907171815-23mzb6ugdi25bto1
parent: jriddell at canonical.com-20110907163211-u1ahle3y8xsjcp1u
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-09-07 18:12:33 +0000
message:
(jr) add class GettextIndentedHelpFormatter to add gettext translations to
option help (Jonathan Riddell)
modified:
bzrlib/option.py option.py-20051014052914-661fb36e76e7362f
bzrlib/tests/test_help.py test_help.py-20070419045354-6q6rq15j9e2n5fna-1
bzrlib/tests/test_i18n.py test_i18n.py-20110517012016-wjj0ai7qrasnj49p-1
=== modified file 'bzrlib/option.py'
--- a/bzrlib/option.py 2011-06-27 15:42:09 +0000
+++ b/bzrlib/option.py 2011-09-01 15:45:57 +0000
@@ -25,6 +25,7 @@
from bzrlib import (
errors,
revisionspec,
+ i18n,
)
""")
@@ -429,9 +430,23 @@
DEFAULT_VALUE = object()
+ def __init__(self):
+ optparse.OptionParser.__init__(self)
+ self.formatter = GettextIndentedHelpFormatter()
+
def error(self, message):
raise errors.BzrCommandError(message)
+class GettextIndentedHelpFormatter(optparse.IndentedHelpFormatter):
+ """Adds gettext() call to format_option()"""
+ def __init__(self):
+ optparse.IndentedHelpFormatter.__init__(self)
+
+ def format_option(self, option):
+ """code taken from Python's optparse.py"""
+ if option.help:
+ option.help = i18n.gettext(option.help)
+ return optparse.IndentedHelpFormatter.format_option(self, option)
def get_optparser(options):
"""Generate an optparse parser for bzrlib-style options"""
=== modified file 'bzrlib/tests/test_help.py'
--- a/bzrlib/tests/test_help.py 2011-08-11 10:19:32 +0000
+++ b/bzrlib/tests/test_help.py 2011-09-02 16:34:17 +0000
@@ -347,10 +347,10 @@
}}zz{{:Usage: bzr WithSeeAlso
}}
zz{{:Options:
- --usage Show usage message and options.
- -v, --verbose Display more information.
- -q, --quiet Only display errors and warnings.
- -h, --help Show help message.
+ --usage zz{{Show usage message and options.}}
+ -v, --verbose zz{{Display more information.}}
+ -q, --quiet zz{{Only display errors and warnings.}}
+ -h, --help zz{{Show help message.}}
}}
zz{{:See also: bar, foo}}
''',
@@ -365,10 +365,10 @@
}}zz{{:Usage: bzr Demo
}}
zz{{:Options:
- --usage Show usage message and options.
- -v, --verbose Display more information.
- -q, --quiet Only display errors and warnings.
- -h, --help Show help message.
+ --usage zz{{Show usage message and options.}}
+ -v, --verbose zz{{Display more information.}}
+ -q, --quiet zz{{Only display errors and warnings.}}
+ -h, --help zz{{Show help message.}}
}}
''',
cmd_Demo())
@@ -381,9 +381,9 @@
helptext = cmd.get_help_text(['gam'])
self.assertEndsWith(
helptext,
- ' -v, --verbose Display more information.\n'
- ' -q, --quiet Only display errors and warnings.\n'
- ' -h, --help Show help message.\n'
+ ' -v, --verbose zz{{Display more information.}}\n'
+ ' -q, --quiet zz{{Only display errors and warnings.}}\n'
+ ' -h, --help zz{{Show help message.}}\n'
'}}\n'
'zz{{:See also: bar, foo, gam}}\n')
@@ -395,10 +395,10 @@
self.assertEndsWith(
helptext,
'zz{{:Options:\n'
- ' --usage Show usage message and options.\n'
- ' -v, --verbose Display more information.\n'
- ' -q, --quiet Only display errors and warnings.\n'
- ' -h, --help Show help message.\n'
+ ' --usage zz{{Show usage message and options.}}\n'
+ ' -v, --verbose zz{{Display more information.}}\n'
+ ' -q, --quiet zz{{Only display errors and warnings.}}\n'
+ ' -h, --help zz{{Show help message.}}\n'
'}}\n'
'zz{{:See also: gam}}\n')
@@ -427,10 +427,10 @@
}}zz{{:Usage: bzr Demo
}}
zz{{:Options:
- --usage Show usage message and options.
- -v, --verbose Display more information.
- -q, --quiet Only display errors and warnings.
- -h, --help Show help message.
+ --usage zz{{Show usage message and options.}}
+ -v, --verbose zz{{Display more information.}}
+ -q, --quiet zz{{Only display errors and warnings.}}
+ -h, --help zz{{Show help message.}}
}}
Description:
zz{{zz{{Blah blah blah.}}
@@ -470,10 +470,10 @@
}}
zz{{:Options:
- --usage Show usage message and options.
- -v, --verbose Display more information.
- -q, --quiet Only display errors and warnings.
- -h, --help Show help message.
+ --usage zz{{Show usage message and options.}}
+ -v, --verbose zz{{Display more information.}}
+ -q, --quiet zz{{Only display errors and warnings.}}
+ -h, --help zz{{Show help message.}}
}}
Description:
zz{{zz{{Blah blah blah.}}
=== modified file 'bzrlib/tests/test_i18n.py'
--- a/bzrlib/tests/test_i18n.py 2011-09-07 14:20:10 +0000
+++ b/bzrlib/tests/test_i18n.py 2011-09-07 16:32:11 +0000
@@ -124,7 +124,9 @@
workingtree.WorkingTree.open('./foo')
except errors.NotBranchError,e:
err = str(e)
- self.assertContainsRe(err, u"zz\xe5{{Not a branch: .*}}".encode("utf-8"))
+ self.assertContainsRe(err,
+ u"zz\xe5{{Not a branch: .*}}".encode("utf-8"))
+
def test_topic_help_translation(self):
"""does topic help get translated?"""
from bzrlib import help
More information about the bazaar-commits
mailing list