root/trunk/umitCore/I18N.py @ 1145

Revision 1145, 1.8 kB (checked in by boltrix, 6 years ago)

More test on I18N

Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# Copyright (C) 2005 Insecure.Com LLC.
5#
6# Author: Adriano Monteiro Marques <py.adriano@gmail.com>
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22from umitCore.Logging import log
23
24
25import locale
26LC_ALL = locale.setlocale(locale.LC_ALL, '')
27LANG, ENC = locale.getdefaultlocale()
28ERRORS = "ignore"
29
30# If not correct locale could be retrieved, set en_US.utf8 as default
31if not ENC:
32    ENC = "utf8"
33
34if not LANG:
35    LANG = "en_US"
36
37try:
38    import gettext
39    from gettext import gettext as _
40
41    gettext.install('umit', unicode=True)
42
43except ImportError:
44    log.critical("You don't have gettext module, no \
45internationalization will be used.")
46
47    # define _() so program will not fail
48    import __builtin__
49    __builtin__.__dict__["_"] = str
50
51
52def enc(string):
53    """Encoding conversion. This function is entended to receive a locale
54    created string with locale encoding and return an utf8 string.
55    """
56    log.debug(">>> Converting '%s' from '%s' to unicode" % (string, ENC))
57    string = unicode(string, ENC, ERRORS)
58    log.debug(">>> Converted to: '%s'" % string)
59
60    return string
61
62
63if __name__ == '__main__':
64    print _('UMIT - The nmap frontend')
Note: See TracBrowser for help on using the browser.