<s> from django . template import Node <EOL> from django . template import TemplateSyntaxError , Library <EOL> from django . utils import formats <EOL> from django . utils . encoding import force_unicode <EOL> register = Library ( ) <EOL> @ register . filter ( is_safe = False ) <EOL> def localize ( value ) : <EOL> """<STR_LIT>""" <EOL> return force_unicode ( formats . localize ( value , use_l10n = True ) ) <EOL> @ register . filter ( is_safe = False ) <EOL> def unlocalize ( value ) : <EOL> """<STR_LIT>""" <EOL> return force_unicode ( value ) <EOL> class LocalizeNode ( Node ) : <EOL> def __init__ ( self , nodelist , use_l10n ) : <EOL> self . nodelist = nodelist <EOL> self . use_l10n = use_l10n <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def render ( self , context ) : <EOL> old_setting = context . use_l10n <EOL> context . use_l10n = self . use_l10n <EOL> output = self . nodelist . render ( context ) <EOL> context . use_l10n = old_setting <EOL> return output <EOL> @ register . tag ( '<STR_LIT>' ) <EOL> def localize_tag ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> use_l10n = None <EOL> bits = list ( token . split_contents ( ) ) <EOL> if len ( bits ) == <NUM_LIT:1> : <EOL> use_l10n = True <EOL> elif len ( bits ) > <NUM_LIT:2> or bits [ <NUM_LIT:1> ] not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" % bits [ <NUM_LIT:0> ] ) <EOL> else : <EOL> use_l10n = bits [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> nodelist = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> parser . delete_first_token ( ) <EOL> return LocalizeNode ( nodelist , use_l10n ) </s>
