Package turbogears :: Package widgets :: Module i18n

Source Code for Module turbogears.widgets.i18n

  1  """Internationalization support for TurboGears widgets""" 
  2   
  3  __all__ = ['LocalizableJSLink', 'CalendarLangFileLink'] 
  4   
  5  import os 
  6  import codecs 
  7  from cherrypy import request 
  8  from turbogears.i18n import get_locale 
  9  from turbogears import startup, config 
 10  from turbogears.util import parse_http_accept_header 
 11  from turbogears.widgets.base import JSLink, CoreWD, RenderOnlyWD 
 12   
 13   
 41   
 42   
43 -class LocalizableJSLinkDesc(CoreWD, RenderOnlyWD):
44 45 name = "Localizable JS Link" 46 for_widget = LocalizableJSLink('turbogears', 'js/yourscript-%(lang)s.js')
47 48 49 _norm_tag = ''.join([(c.islower() or c.isdigit() or c == '-') 50 and c or c.isupper() and c.lower() or ' ' for c in map(chr, xrange(256))]) 51
52 -def norm_tag(tag):
53 """Normalize string to alphanumeric ascii chars, hyphens and underscores. 54 55 The length is limited to 16 characters and other characters are 56 collapsed to single underscore, or ignored at the start or end. 57 58 """ 59 if tag is not None: 60 return '_'.join(str(tag)[:16].translate(_norm_tag).split())
61 62
63 -def norm_charset(charset):
64 """Normalize the name of a character set.""" 65 if charset is not None: 66 charset = norm_tag(charset) 67 try: 68 charset = norm_tag(codecs.lookup(charset).name) 69 except (LookupError, AttributeError): 70 # AttributeError only needed for Py < 2.5 71 pass 72 return charset
73 74 120