/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/i18n.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-22 00:56:52 UTC
  • mfrom: (6621.2.26 py3_pokes)
  • Revision ID: jelmer@jelmer.uk-20170522005652-yjahcr9hwmjkno7n
Merge Python3 porting work ('py3 pokes')

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    :returns: translated message as unicode.
39
39
    """
40
40
    install()
41
 
    return _translations.ugettext(message)
 
41
    try:
 
42
        return _translations.ugettext(message)
 
43
    except AttributeError:
 
44
        return _translations.gettext(message)
42
45
 
43
46
 
44
47
def ngettext(singular, plural, number):
51
54
    :returns: translated message as unicode.
52
55
    """
53
56
    install()
54
 
    return _translations.ungettext(singular, plural, number)
 
57
    try:
 
58
        return _translations.ungettext(singular, plural, number)
 
59
    except AttributeError:
 
60
        return _translations.ngettext(singular, plural, number)
55
61
 
56
62
 
57
63
def N_(msg):
66
72
    """
67
73
    install()
68
74
    paragraphs = message.split(u'\n\n')
69
 
    ugettext = _translations.ugettext
70
75
    # Be careful not to translate the empty string -- it holds the
71
76
    # meta data of the .po file.
72
 
    return u'\n\n'.join(ugettext(p) if p else u'' for p in paragraphs)
 
77
    return u'\n\n'.join(gettext(p) if p else u'' for p in paragraphs)
73
78
 
74
79
 
75
80
def disable_i18n():
136
141
 
137
142
    :param base: plugins can specify their own local directory
138
143
    """
139
 
    fs_enc = sys.getfilesystemencoding()
 
144
    if sys.version_info > (3,):
 
145
        decode_path = str
 
146
    else:
 
147
        fs_enc = sys.getfilesystemencoding()
 
148
        def decode_path(path):
 
149
            return path.decode(fs_enc)
140
150
    if getattr(sys, 'frozen', False):
141
151
        if base is None:
142
 
            base = os.path.dirname(unicode(sys.executable, fs_enc))
 
152
            base = os.path.dirname(decode_path(sys.executable))
143
153
        return os.path.join(base, u'locale')
144
154
    else:
145
155
        if base is None:
146
 
            base = os.path.dirname(unicode(__file__, fs_enc))
 
156
            base = os.path.dirname(decode_path(__file__))
147
157
        dirpath = os.path.realpath(os.path.join(base, u'locale'))
148
158
        if os.path.exists(dirpath):
149
159
            return dirpath
150
 
    return os.path.join(unicode(sys.prefix, fs_enc), u"share", u"locale")
 
160
    return os.path.join(decode_path(sys.prefix), u"share", u"locale")
151
161
 
152
162
 
153
163
def _check_win32_locale():
179
189
 
180
190
def _get_current_locale():
181
191
    if not os.environ.get('LANGUAGE'):
182
 
        from breezy import config
 
192
        from . import config
183
193
        lang = config.GlobalStack().get('language')
184
194
        if lang:
185
195
            os.environ['LANGUAGE'] = lang