Make LazyUGettext a Promise so it deconstructs nicely.
[fnpdjango.git] / fnpdjango / utils / settings.py
1 """
2 Utilities for global settings.
3 """
4 from django.utils.encoding import python_2_unicode_compatible
5 from django.utils.functional import Promise
6
7 # Use Python3 str.
8 try:
9     unicode
10 except NameError:
11     pass
12 else:
13     str = unicode
14
15
16 @python_2_unicode_compatible
17 class LazyUGettextLazy(Promise):
18     """You can use it to internationalize strings in settings.
19
20     Just import this class as gettext.
21     """
22     _ = lambda s: s
23     real = False
24
25     def __init__(self, text):
26         self.text = text
27
28     def __str__(self):
29         if not self.real:
30             from django.utils.translation import ugettext_lazy
31             LazyUGettextLazy._ = staticmethod(ugettext_lazy)
32             LazyUGettextLazy.real = True
33         return str(self._(self.text))
34
35