~ubuntu-branches/ubuntu/oneiric/command-not-found/oneiric

« back to all changes in this revision

Viewing changes to command-not-found

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt, Zygmunt Krynicki
  • Date: 2011-08-25 15:15:50 UTC
  • Revision ID: james.westby@ubuntu.com-20110825151550-m6gycva2g7fnn91m
Tags: 0.2.43ubuntu1
[ Zygmunt Krynicki ]
* lp:~zkrynicki/command-not-found/rework-locale-support:
  - improved gettext handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
# (c) Zygmunt Krynicki 2005, 2006, 2007, 2008
3
3
# Licensed under GPL, see COPYING for the whole text
4
4
 
 
5
from __future__ import absolute_import
 
6
 
 
7
 
5
8
__version__ = "0.2.21"
6
 
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/+source/command-not-found"
 
9
BUG_REPORT_URL = "https://bugs.launchpad.net/command-not-found/+filebug"
7
10
 
8
11
try:
9
12
    import sys
10
 
    import CommandNotFound
11
 
    from CommandNotFound.util import crash_guard, gettext_wrapper as _
 
13
    import gettext
 
14
    from optparse import OptionParser
 
15
 
 
16
    from CommandNotFound.util import crash_guard
12
17
    from CommandNotFound import CommandNotFound
13
 
    from optparse import OptionParser
14
18
except KeyboardInterrupt:
15
19
    sys.exit(127)
16
20
 
 
21
 
 
22
def enable_i18n():
 
23
    cnf = gettext.translation("command-not-found", fallback=True)
 
24
    cnf.install(unicode=True)
 
25
 
 
26
 
 
27
class LocaleOptionParser(OptionParser):
 
28
    """
 
29
    OptionParser is broken as its implementation of _get_encoding() uses
 
30
    sys.getdefaultencoding() which is ascii, what it should be using is
 
31
    locale.getpreferredencoding() which returns value based on LC_CTYPE (most
 
32
    likely) and allows for UTF-8 encoding to be used.
 
33
    """
 
34
    def _get_encoding(self, file):
 
35
        encoding = getattr(file, "encoding", None)
 
36
        if not encoding:
 
37
            encoding = locale.getpreferredencoding()
 
38
        return encoding
 
39
 
 
40
 
17
41
def main():
18
 
    parser = OptionParser(version = __version__, usage=_("%prog [options] <command-name>"))
 
42
    enable_i18n()
 
43
    parser = LocaleOptionParser(
 
44
        version=__version__,
 
45
        usage=_("%prog [options] <command-name>"))
19
46
    parser.add_option('-d', '--data-dir', action='store',
20
47
                      default="/usr/share/command-not-found",
21
48
                      help=_("use this path to locate data fields"))