Last active
December 21, 2015 19:58
-
-
Save bcse/6357484 to your computer and use it in GitHub Desktop.
Generate plexconnect.pot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 <[email protected]>\\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 ""' | |
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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add "#!/usr/bin/env python" as first line?
This would allow to call it without specifying "python"...
:-D