Last active
December 21, 2015 19:58
Revisions
-
bcse revised this gist
Sep 25, 2013 . 1 changed file with 51 additions and 41 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,44 +1,54 @@ #!/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 ""' 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]) -
bcse created this gist
Aug 27, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ import os import re import glob import datetime base_path = r'/Volumes/OMEGA/Source/PlexConnect' 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 ""' print ''