mail[Wesnoth-commits] r34315 - /trunk/data/tools/wmlxgettext


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by esr on March 31, 2009 - 01:26:
Author: esr
Date: Tue Mar 31 01:26:47 2009
New Revision: 34315

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34315&view=rev
Log:
Parsing stage for new wmlgettext is working.

Modified:
    trunk/data/tools/wmlxgettext

Modified: trunk/data/tools/wmlxgettext
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wmlxgettext?rev=34315&r1=34314&r2=34315&view=diff
==============================================================================
--- trunk/data/tools/wmlxgettext (original)
+++ trunk/data/tools/wmlxgettext Tue Mar 31 01:26:47 2009
@@ -95,8 +95,66 @@
 
         os.chdir(directory)
 
+        opener_stack = []
+        attributes_stack = []
+        translatables = []
+        contexts = {}
+        find_translatable = re.compile('_ *"[^"]*"')
+
+        def get_translatables(nav, fn):
+            "Mine translatable strings "
+            for match in find_translatable.findall(nav.text):
+                opener_stack.append((nav.element, fn, nav.lineno))
+                translatables.append((match, opener_stack[:]))
+                opener_stack.pop()
+
+        def inMacroContinuation(nav):
+            return opener_stack and type(opener_stack[-1][0]) == type("") \
+                   and opener_stack[-1][0].startswith("{")
+
+        def isInlineMacro(nav):
+            return type(nav.element) == type([]) and nav.element and 
nav.element[0].startswith("{")
+
+        def handle_element(nav, fn):
+            if isAttribute(nav):
+                attributes_stack[-1].append(nav.text.strip())
+                get_translatables(nav, fn)
+                if verbose > 1:
+                    print "Attribute", nav, "with ancestors", nav.ancestors()
+            elif isCloser(nav):
+                contexts[opener_stack.pop()] = attributes_stack.pop()
+                if verbose > 1:
+                    print "Closing scope", nav
+            elif isOpener(nav):
+                attributes_stack.append([])
+                opener_stack.append((nav.element, fn, nav.lineno))
+                if verbose > 1:
+                    print "Opening scope", nav
+            elif isMacroOpener(nav):
+                opener_stack.append((nav.element, fn, nav.lineno))
+                get_translatables(nav, fn)
+                if verbose > 1:
+                    print "Opening macro scope", nav
+            elif isMacroCloser(nav):
+                opener_stack.pop()
+                if verbose > 1:
+                    print "Closing macro scope", nav
+            elif inMacroContinuation(nav):
+                nav.element = "argument"
+                get_translatables(nav, fn)
+                if verbose > 1:
+                    print "In macro continuation", `nav.text`
+            elif isInlineMacro(nav):
+                if verbose > 1:
+                    print "Inline macro", nav
+                nav.element = nav.element[0]
+                get_translatables(nav, fn)
+            elif verbose > 1:
+                print "Unhandled", nav
+        # Gather a dictionary describing the context of every
+        # translatable string.
         for dir in arguments:
-            ofp = None
+            seqno = 0
             for fn in allcfgfiles(dir):
                 if verbose >= 2:
                     print fn + ":"
@@ -108,7 +166,14 @@
                             print "wmlgettext: skipping %s, wrong domain" % 
fn
                         continue
                 for nav in WmllintIterator(lines, fn):
-                    print "FOO!", `nav`
+                    handle_element(nav, fn)
+        # Generate a report from the dictionary.
+        print "Translatables:"
+        for (translatable, context) in translatables:
+            print "%s: %s" % (translatable, context)
+        print "Contexts:"
+        for (key, value) in contexts.items():
+            print key, "->", value
     except KeyboardInterrupt:
-        print >>sys.stderr, "wmlgettext: aborted."
+        print >>sys.stderr, "wmlxgettext: aborted."
         




Related Messages


Powered by MHonArc, Updated Tue Mar 31 02:00:28 2009