Skip to content

Instantly share code, notes, and snippets.

@bcse bcse/genpot.py
Last active Dec 21, 2015

Embed
What would you like to do?
Generate plexconnect.pot
#!/usr/bin/env python
import datetime
import glob
import os
import re
import sys
def main(base_path):
msgid = set()
# parse {{TEXT(...)}} in xml
for filename in glob.iglob(os.path.join(base_path, 'assets', 'templates', '*.xml')):
with open(filename, 'r') as fp:
content = fp.read()
msgid.update(re.findall(r'\{\{TEXT\((.+?)\)\}\}', content, re.DOTALL))
# parse {{TEXT(...)}} in js
for filename in glob.iglob(os.path.join(base_path, 'assets', 'js', '*.js')):
with open(filename, 'r') as fp:
content = fp.read()
msgid.update(re.findall(r'\{\{TEXT\((.+?)\)\}\}', content, re.DOTALL))
# parse _(...) or obj._(...) in py
for filename in glob.iglob(os.path.join(base_path, '*.py')):
with open(filename, 'r') as fp:
content = fp.read()
msgid.update(re.findall(r'[\.\s]_\(["\'](.+?)["\']\)', content))
# print results
print """msgid ""
msgstr ""
"Project-Id-Version: Plex Connect\\n"
"Report-Msgid-Bugs-To: \\n"
"POT-Creation-Date: %s\\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: LANGUAGE <LL@li.org>\\n"
"Language: \\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=CHARSET\\n"
"Content-Transfer-Encoding: 8bit\\n"
""" % datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S+0000')
for i in sorted(msgid):
print 'msgid "%s"' % i.replace('\n', '\\n"\n"')
print 'msgstr ""'
print
if __name__ == '__main__':
if len(sys.argv) == 1 or not os.path.isdir(sys.argv[1]):
print 'Usage: %s base_path > messages.pot' % __file__
else:
main(sys.argv[1])
@iBaa

This comment has been minimized.

Copy link

commented Aug 31, 2013

Add "#!/usr/bin/env python" as first line?
This would allow to call it without specifying "python"...
:-D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.