def _build_js_translation(lang, source_filenames, entries, dest_filename):
 pos = [polib.pofile(fn) for fn in source_filenames]
 result = {}
 result[u''] = {}
 result[u''][u'plural-forms'] = pos[0].metadata[u'Plural-Forms']
 result[u''][u'lang'] = lang
 result[u''][u'domain'] = u'ckan'
 for po in pos:
  for entry in po:
   if (entry.msgid not in entries):
    continue
   if entry.msgstr:
    result[entry.msgid] = [None, entry.msgstr]
   elif entry.msgstr_plural:
    plural = result[entry.msgid] = [entry.msgid_plural]
    ordered_plural = sorted(entry.msgstr_plural.items())
    for (order, msgstr) in ordered_plural:
     plural.append(msgstr)
 with open(dest_filename, u'w') as f:
  s = json.dumps(result, sort_keys=True, indent=2, ensure_ascii=False)
  f.write(s.encode(u'utf-8'))

def _build_js_translation ( lang , source_filenames , entries , dest_filename ) : pos = [ polib . pofile ( fn ) for fn in source_filenames ] result = { } result [ u'' ] = { } result [ u'' ] [ u'plural-forms' ] = pos [ 0 ] . metadata [ u'Plural-Forms' ] result [ u'' ] [ u'lang' ] = lang result [ u'' ] [ u'domain' ] = u'ckan' for po in pos : for entry in po : if ( entry . msgid not in entries ) : continue if entry . msgstr : result [ entry . msgid ] = [ None , entry . msgstr ] elif entry . msgstr_plural : plural = result [ entry . msgid ] = [ entry . msgid_plural ] ordered_plural = sorted ( entry . msgstr_plural . items ( ) ) for ( order , msgstr ) in ordered_plural : plural . append ( msgstr ) with open ( dest_filename , u'w' ) as f : s = json . dumps ( result , sort_keys = True , indent = 2 , ensure_ascii = False ) f . write ( s . encode ( u'utf-8' ) )
build javascript translations for a single language .