Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # from http://archive.plugins.jquery.com/project/gettext
- # to extract strings to a .po file, you can use standard gettext utilities like xgettext and msgfmt; to generate the JSON, one could use the following Python snippet, assuming a domain.mo file exists under path/lang/LC_MESSAGES:
- import simplejson as enc
- import gettext
- def gettext_json(domain, path, lang = [], indent = False):
- try:
- tr = gettext.translation(domain, path, lang)
- # for unknown reasons, instead of having plural entries like
- # key: [sg, pl1...]
- # tr._catalog has (key, n): pln,
- keys = tr._catalog.keys()
- keys.sort()
- ret = {}
- for k in keys:
- v = tr._catalog[k]
- if type(k) is tuple:
- if k[0] not in ret:
- ret[k[0]] = []
- ret[k[0]].append(v)
- else:
- ret[k] = v
- return enc.dumps(ret, ensure_ascii = False, indent = indent)
- except IOError:
- return None
- # call our convert function
- print gettext_json('default', '/path/to/opac/locale/', 'en_US.UTF8')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement