/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: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
"""i18n and l10n support for Bazaar."""
24
24
 
 
25
from __future__ import absolute_import
 
26
 
25
27
import gettext as _gettext
26
28
import os
27
29
import sys
31
33
 
32
34
 
33
35
def gettext(message):
34
 
    """Translate message.
35
 
 
 
36
    """Translate message. 
 
37
    
36
38
    :returns: translated message as unicode.
37
39
    """
38
40
    install()
97
99
 
98
100
def install_translations(lang=None, domain='brz', locale_base=None):
99
101
    """Create a gettext translation object.
100
 
 
 
102
    
101
103
    :param lang: language to install.
102
104
    :param domain: translation domain to install.
103
105
    :param locale_base: plugins can specify their own directory.
111
113
    else:
112
114
        languages = None
113
115
    translation = _gettext.translation(
114
 
        domain,
115
 
        localedir=_get_locale_dir(locale_base),
116
 
        languages=languages,
117
 
        fallback=True)
 
116
            domain,
 
117
            localedir=_get_locale_dir(locale_base),
 
118
            languages=languages,
 
119
            fallback=True)
118
120
    return translation
119
121
 
120
122
 
139
141
 
140
142
    :param base: plugins can specify their own local directory
141
143
    """
 
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)
142
150
    if getattr(sys, 'frozen', False):
143
151
        if base is None:
144
 
            base = os.path.dirname(sys.executable)
 
152
            base = os.path.dirname(decode_path(sys.executable))
145
153
        return os.path.join(base, u'locale')
146
154
    else:
147
155
        if base is None:
148
 
            base = os.path.dirname(__file__)
 
156
            base = os.path.dirname(decode_path(__file__))
149
157
        dirpath = os.path.realpath(os.path.join(base, u'locale'))
150
158
        if os.path.exists(dirpath):
151
159
            return dirpath
152
 
    return os.path.join(sys.prefix, u"share", u"locale")
 
160
    return os.path.join(decode_path(sys.prefix), u"share", u"locale")
153
161
 
154
162
 
155
163
def _check_win32_locale():
200
208
 
201
209
    :param domain: Gettext domain name (usually 'brz-PLUGINNAME')
202
210
    """
203
 
    locale_base = os.path.dirname(__file__)
 
211
    locale_base = os.path.dirname(
 
212
        unicode(__file__, sys.getfilesystemencoding()))
204
213
    translation = install_translations(domain=domain,
205
 
                                       locale_base=locale_base)
 
214
        locale_base=locale_base)
206
215
    add_fallback(translation)
207
216
    return translation