Package turbogears :: Package widgets :: Module i18n

Source Code for Module turbogears.widgets.i18n

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