/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: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

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