MCPcopy
hub / github.com/django/django / Trans

Class Trans

django/utils/translation/__init__.py:50–82  ·  view source on GitHub ↗

The purpose of this class is to store the actual translation function upon receiving the first call to that function. After this is done, changes to USE_I18N will have no effect to which function is served upon request. If your tests rely on changing USE_I18N, you can delete all the

Source from the content-addressed store, hash-verified

48
49
50class Trans:
51 """
52 The purpose of this class is to store the actual translation function upon
53 receiving the first call to that function. After this is done, changes to
54 USE_I18N will have no effect to which function is served upon request. If
55 your tests rely on changing USE_I18N, you can delete all the functions
56 from _trans.__dict__.
57
58 Note that storing the function with setattr will have a noticeable
59 performance effect, as access to the function goes the normal path,
60 instead of using __getattr__.
61 """
62
63 def __getattr__(self, real_name):
64 from django.conf import settings
65
66 if settings.USE_I18N:
67 from django.utils.translation import trans_real as trans
68 from django.utils.translation.reloader import (
69 translation_file_changed,
70 watch_for_translation_changes,
71 )
72
73 autoreload_started.connect(
74 watch_for_translation_changes, dispatch_uid="translation_file_changed"
75 )
76 file_changed.connect(
77 translation_file_changed, dispatch_uid="translation_file_changed"
78 )
79 else:
80 from django.utils.translation import trans_null as trans
81 setattr(self, real_name, getattr(trans, real_name))
82 return getattr(trans, real_name)
83
84
85_trans = Trans()

Callers 1

__init__.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected