[Frhed-commits] SF.net SVN: frhed:[812] trunk/Translations/Web/CreateMasterPotFile.py
Brought to you by:
kimmov
From: <ge...@us...> - 2009-08-10 09:42:19
|
Revision: 812 http://frhed.svn.sourceforge.net/frhed/?rev=812&view=rev Author: gerundt Date: 2009-08-10 09:42:09 +0000 (Mon, 10 Aug 2009) Log Message: ----------- Web: Support multi-line translations in Python script Modified Paths: -------------- trunk/Translations/Web/CreateMasterPotFile.py Modified: trunk/Translations/Web/CreateMasterPotFile.py =================================================================== --- trunk/Translations/Web/CreateMasterPotFile.py 2009-08-09 12:22:49 UTC (rev 811) +++ trunk/Translations/Web/CreateMasterPotFile.py 2009-08-10 09:42:09 UTC (rev 812) @@ -34,11 +34,34 @@ def getTranslationsFromPhpFile(filepath, translations): ''' Get the translations from a php file ''' - rGettext = re.compile('_e?\([\'"](.*?)[\'"]', re.IGNORECASE) - + rGettext = re.compile('_e?\([\'"](.+?)[\'"]', re.DOTALL) + rGettextTestMultiLine = re.compile('_e?\([\'"]([^\'"\n]+)\n') + + phpfile = open(filepath, 'r') + lines = phpfile.readlines() + phpfile.close() + i = 0 - phpfile = open(filepath, 'r') - for line in phpfile: #For all lines... + for line in lines: #For all lines... + #-------------------------------------------------------------------------------- + # Multi-line translations... + #-------------------------------------------------------------------------------- + tmps = rGettextTestMultiLine.findall(line) + if tmps: #If found a multi-line gettext function... + tmps = rGettext.findall("".join(lines[i:])) + for tmp in tmps: #For all translations... + if string.find(tmp, '\n') > 0: #If a multi-line translation... + translation = string.replace(tmp, '\n', '\\n') + if translation in translations: #If the translation is already exists... + translations[translation] += [(filepath, i)] + else: #If the translation is NOT already exists... + translations[translation] = [(filepath, i)] + break #Use only the FIRST multi-line translation! + #-------------------------------------------------------------------------------- + + #-------------------------------------------------------------------------------- + # Normal translations... + #-------------------------------------------------------------------------------- i += 1 tmps = rGettext.findall(line) if tmps: #If found a gettext function... @@ -48,7 +71,7 @@ translations[translation] += [(filepath, i)] else: #If the translation is NOT already exists... translations[translation] = [(filepath, i)] - phpfile.close() + #-------------------------------------------------------------------------------- def main(): translations = {} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |