~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/i18n.py

  • Committer: Vincent Ladeuil
  • Date: 2011-06-27 15:08:26 UTC
  • mto: (5993.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 5994.
  • Revision ID: v.ladeuil+lp@free.fr-20110627150826-lfdrvg65lqzn33f9
Fix test failures and make sure we don't rely on a default translation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import os
27
27
import sys
28
28
 
29
 
_translation = _gettext.NullTranslations()
 
29
_translations = None
30
30
 
31
31
 
32
32
def gettext(message):
34
34
    
35
35
    :returns: translated message as unicode.
36
36
    """
37
 
    return _translation.ugettext(message)
 
37
    return _translations.ugettext(message)
38
38
 
39
39
 
40
40
def ngettext(s, p, n):
42
42
 
43
43
    :returns: translated message as unicode.
44
44
    """
45
 
    return _translation.ungettext(s, p, n)
 
45
    return _translations.ungettext(s, p, n)
46
46
 
47
47
 
48
48
def N_(msg):
56
56
    :returns: concatenated translated message as unicode.
57
57
    """
58
58
    paragraphs = message.split(u'\n\n')
59
 
    ugettext = _translation.ugettext
 
59
    ugettext = _translations.ugettext
60
60
    # Be careful not to translate the empty string -- it holds the
61
61
    # meta data of the .po file.
62
62
    return u'\n\n'.join(ugettext(p) if p else u'' for p in paragraphs)
63
63
 
64
64
 
 
65
def installed():
 
66
    return _translations is not None
 
67
 
 
68
 
65
69
def install(lang=None):
66
 
    global _translation
 
70
    global _translations
67
71
    if lang is None:
68
72
        lang = _get_current_locale()
69
 
    _translation = _gettext.translation(
 
73
    _translations = _gettext.translation(
70
74
            'bzr',
71
75
            localedir=_get_locale_dir(),
72
76
            languages=lang.split(':'),
74
78
 
75
79
 
76
80
def uninstall():
77
 
    global _translation
78
 
    _translation = _gettext.NullTranslations()
 
81
    global _translations
 
82
    _translations = None
79
83
 
80
84
 
81
85
def _get_locale_dir():