~ubuntu-branches/debian/sid/bzr/sid

« back to all changes in this revision

Viewing changes to bzrlib/i18n.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij, Jelmer Vernooij, Max Bowsher
  • Date: 2011-07-14 15:35:42 UTC
  • mfrom: (1.5.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110714153542-7m3m8jpt6c167g2a
Tags: 2.4.0~beta5-1
[ Jelmer Vernooij ]
* Fix typo in package description. Thanks Paul Stewart.
* Mark python-bzrlib as breaking with older versions of bzr that
  predate python-bzrlib. LP: #803362

[ Max Bowsher ]
* New upstream release.

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)
38
 
 
39
 
 
40
 
def ngettext(s, p, n):
41
 
    """Translate message based on `n`.
 
37
    return _translations.ugettext(message)
 
38
 
 
39
 
 
40
def ngettext(singular, plural, number):
 
41
    """Translate message with plural forms based on `number`.
 
42
 
 
43
    :param singular: English language message in singular form
 
44
    :param plural: English language message in plural form
 
45
    :param number: the number this message should be translated for
42
46
 
43
47
    :returns: translated message as unicode.
44
48
    """
45
 
    return _translation.ungettext(s, p, n)
 
49
    return _translations.ungettext(singular, plural, number)
46
50
 
47
51
 
48
52
def N_(msg):
56
60
    :returns: concatenated translated message as unicode.
57
61
    """
58
62
    paragraphs = message.split(u'\n\n')
59
 
    ugettext = _translation.ugettext
 
63
    ugettext = _translations.ugettext
60
64
    # Be careful not to translate the empty string -- it holds the
61
65
    # meta data of the .po file.
62
66
    return u'\n\n'.join(ugettext(p) if p else u'' for p in paragraphs)
63
67
 
64
68
 
 
69
def installed():
 
70
    return _translations is not None
 
71
 
 
72
 
65
73
def install(lang=None):
66
 
    global _translation
 
74
    global _translations
67
75
    if lang is None:
68
76
        lang = _get_current_locale()
69
 
    _translation = _gettext.translation(
 
77
    _translations = _gettext.translation(
70
78
            'bzr',
71
79
            localedir=_get_locale_dir(),
72
80
            languages=lang.split(':'),
74
82
 
75
83
 
76
84
def uninstall():
77
 
    global _translation
78
 
    _translation = _null_translation
 
85
    global _translations
 
86
    _translations = None
79
87
 
80
88
 
81
89
def _get_locale_dir():