@@ -14,21 +14,17 @@ class TxNative(object):
1414 """The main class of the framework, responsible for orchestrating all
1515 behavior."""
1616
17- def __init__ (self ):
18- # The class uses an untypical initialization scheme, defining
19- # an init() method, instead of initializing inside the constructor
20- # This is necessary for allowing it to be initialized by its clients
21- # with proper arguments, while at the same time being very easy
22- # to import and use a single "global" instance
23- self ._cache = None
17+ def __init__ (self , ** kwargs ):
2418 self ._languages = []
25- self ._missing_policy = None
26- self ._cds_handler = None
19+ self ._missing_policy = SourceStringPolicy ()
20+ self ._cds_handler = CDSHandler ()
21+ self ._cache = MemoryCache ()
22+ self ._error_policy = SourceStringErrorPolicy ()
2723
28- def init (
29- self , languages , token , secret = None , cds_host = None ,
30- missing_policy = None , error_policy = None
31- ):
24+ self . setup ( ** kwargs )
25+
26+ def setup ( self , languages = None , token = None , secret = None , cds_host = None ,
27+ missing_policy = None , error_policy = None ):
3228 """Create an instance of the core framework class.
3329
3430 Also warms up the cache by fetching the translations from the CDS.
@@ -45,13 +41,17 @@ def init(
4541 :param AbstractErrorPolicy error_policy: an optional policy
4642 to determine how to handle rendering errors
4743 """
48- self ._languages = languages
49- self ._cache = MemoryCache ()
50- self ._missing_policy = missing_policy or SourceStringPolicy ()
51- self ._error_policy = error_policy or SourceStringErrorPolicy ()
52- self ._cds_handler = CDSHandler (configured_languages = self ._languages ,
53- token = token , secret = secret ,
54- host = cds_host )
44+ if languages is not None :
45+ self ._languages = languages
46+ if missing_policy is not None :
47+ self ._missing_policy = missing_policy
48+ if error_policy is not None :
49+ self ._error_policy = error_policy
50+
51+ self ._cds_handler .setup (configured_languages = languages ,
52+ token = token ,
53+ secret = secret ,
54+ host = cds_host )
5555
5656 def translate (
5757 self , source_string , language_code , is_source = False ,
0 commit comments