def javascript_catalog(request, domain='djangojs', packages=None):
 if request.GET:
  if ('language' in request.GET):
   if check_for_language(request.GET['language']):
    activate(request.GET['language'])
 if (packages is None):
  packages = ['django.conf']
 if isinstance(packages, basestring):
  packages = packages.split('+')
 packages = [p for p in packages if ((p == 'django.conf') or (p in settings.INSTALLED_APPS))]
 default_locale = to_locale(settings.LANGUAGE_CODE)
 locale = to_locale(get_language())
 t = {}
 paths = []
 en_selected = locale.startswith('en')
 en_catalog_missing = True
 for package in packages:
  p = importlib.import_module(package)
  path = os.path.join(os.path.dirname(p.__file__), 'locale')
  paths.append(path)
 paths.extend(list(reversed(settings.LOCALE_PATHS)))
 for path in paths:
  try:
   catalog = gettext_module.translation(domain, path, ['en'])
   t.update(catalog._catalog)
  except IOError:
   pass
  else:
   if en_selected:
    en_catalog_missing = False
 if (default_locale != 'en'):
  for path in paths:
   try:
    catalog = gettext_module.translation(domain, path, [default_locale])
   except IOError:
    catalog = None
   if (catalog is not None):
    t.update(catalog._catalog)
 if (locale != default_locale):
  if (en_selected and en_catalog_missing):
   t = {}
  else:
   locale_t = {}
   for path in paths:
    try:
     catalog = gettext_module.translation(domain, path, [locale])
    except IOError:
     catalog = None
    if (catalog is not None):
     locale_t.update(catalog._catalog)
   if locale_t:
    t = locale_t
 src = [LibHead]
 plural = None
 if ('' in t):
  for l in t[''].split('\n'):
   if l.startswith('Plural-Forms:'):
    plural = l.split(':', 1)[1].strip()
 if (plural is not None):
  plural = [el.strip() for el in plural.split(';') if el.strip().startswith('plural=')][0].split('=', 1)[1]
  src.append((PluralIdx % plural))
 else:
  src.append(SimplePlural)
 csrc = []
 pdict = {}
 for (k, v) in t.items():
  if (k == ''):
   continue
  if isinstance(k, basestring):
   csrc.append(("catalog['%s'] = '%s';\n" % (javascript_quote(k), javascript_quote(v))))
  elif isinstance(k, tuple):
   if (k[0] not in pdict):
    pdict[k[0]] = k[1]
   else:
    pdict[k[0]] = max(k[1], pdict[k[0]])
   csrc.append(("catalog['%s'][%d] = '%s';\n" % (javascript_quote(k[0]), k[1], javascript_quote(v))))
  else:
   raise TypeError(k)
 csrc.sort()
 for (k, v) in pdict.items():
  src.append(("catalog['%s'] = [%s];\n" % (javascript_quote(k), ','.join((["''"] * (v + 1))))))
 src.extend(csrc)
 src.append(LibFoot)
 src.append(InterPolate)
 src.append(LibFormatHead)
 src.append(get_formats())
 src.append(LibFormatFoot)
 src = ''.join(src)
 return http.HttpResponse(src, 'text/javascript')

def javascript_catalog ( request , domain = 'djangojs' , packages = None ) : if request . GET : if ( 'language' in request . GET ) : if check_for_language ( request . GET [ 'language' ] ) : activate ( request . GET [ 'language' ] ) if ( packages is None ) : packages = [ 'django.conf' ] if isinstance ( packages , basestring ) : packages = packages . split ( '+' ) packages = [ p for p in packages if ( ( p == 'django.conf' ) or ( p in settings . INSTALLED_APPS ) ) ] default_locale = to_locale ( settings . LANGUAGE_CODE ) locale = to_locale ( get_language ( ) ) t = { } paths = [ ] en_selected = locale . startswith ( 'en' ) en_catalog_missing = True for package in packages : p = importlib . import_module ( package ) path = os . path . join ( os . path . dirname ( p . __file__ ) , 'locale' ) paths . append ( path ) paths . extend ( list ( reversed ( settings . LOCALE_PATHS ) ) ) for path in paths : try : catalog = gettext_module . translation ( domain , path , [ 'en' ] ) t . update ( catalog . _catalog ) except IOError : pass else : if en_selected : en_catalog_missing = False if ( default_locale != 'en' ) : for path in paths : try : catalog = gettext_module . translation ( domain , path , [ default_locale ] ) except IOError : catalog = None if ( catalog is not None ) : t . update ( catalog . _catalog ) if ( locale != default_locale ) : if ( en_selected and en_catalog_missing ) : t = { } else : locale_t = { } for path in paths : try : catalog = gettext_module . translation ( domain , path , [ locale ] ) except IOError : catalog = None if ( catalog is not None ) : locale_t . update ( catalog . _catalog ) if locale_t : t = locale_t src = [ LibHead ] plural = None if ( '' in t ) : for l in t [ '' ] . split ( '\n' ) : if l . startswith ( 'Plural-Forms:' ) : plural = l . split ( ':' , 1 ) [ 1 ] . strip ( ) if ( plural is not None ) : plural = [ el . strip ( ) for el in plural . split ( ';' ) if el . strip ( ) . startswith ( 'plural=' ) ] [ 0 ] . split ( '=' , 1 ) [ 1 ] src . append ( ( PluralIdx % plural ) ) else : src . append ( SimplePlural ) csrc = [ ] pdict = { } for ( k , v ) in t . items ( ) : if ( k == '' ) : continue if isinstance ( k , basestring ) : csrc . append ( ( "catalog['%s'] = '%s';\n" % ( javascript_quote ( k ) , javascript_quote ( v ) ) ) ) elif isinstance ( k , tuple ) : if ( k [ 0 ] not in pdict ) : pdict [ k [ 0 ] ] = k [ 1 ] else : pdict [ k [ 0 ] ] = max ( k [ 1 ] , pdict [ k [ 0 ] ] ) csrc . append ( ( "catalog['%s'][%d] = '%s';\n" % ( javascript_quote ( k [ 0 ] ) , k [ 1 ] , javascript_quote ( v ) ) ) ) else : raise TypeError ( k ) csrc . sort ( ) for ( k , v ) in pdict . items ( ) : src . append ( ( "catalog['%s'] = [%s];\n" % ( javascript_quote ( k ) , ',' . join ( ( [ "''" ] * ( v + 1 ) ) ) ) ) ) src . extend ( csrc ) src . append ( LibFoot ) src . append ( InterPolate ) src . append ( LibFormatHead ) src . append ( get_formats ( ) ) src . append ( LibFormatFoot ) src = '' . join ( src ) return http . HttpResponse ( src , 'text/javascript' )
returns the selected language catalog as a javascript library .