SHIBUKAWA Yoshiki avatar SHIBUKAWA Yoshiki committed 7940fac

msgid must be unique.
comment contains position information.

Comments (0)

Files changed (1)

sphinx/builders/intl.py

         Builder.init(self)
         VersioningBuilderMixin.init(self)
         self.catalogs = defaultdict(OrderedDict)
+        self.last_source = None
 
     def get_target_uri(self, docname, typ=None):
         return ''
         self.handle_versioning(docname, doctree, nodes.TextElement)
 
         for node, msg in extract_messages(doctree):
-            catalog.setdefault(node.uid, msg)
+            if node.source is None:
+                if self.last_source is not None:
+                    source = self.last_source
+                else:
+                    source = "(unknown)"
+            else:
+                source = self.last_source = path.basename(node.source)
+            if node.line is None:
+                line = 0
+            else:
+                line = node.line 
+            catalog.setdefault(msg, []).append((source, line))
 
     def finish(self):
         Builder.finish(self)
             pofile = open(pofn, 'w', encoding='utf-8')
             try:
                 pofile.write(POHEADER % data)
-                for uid, message in messages.iteritems():
+                for message, poss in messages.iteritems():
                     # message contains *one* line of text ready for translation
+                    pos = self._join(
+                        ["%s(%d)" % (s, l) for s, l in poss])
                     message = message.replace(u'\\', ur'\\'). \
                                       replace(u'"', ur'\"')
-                    pomsg = u'#%s\nmsgid "%s"\nmsgstr ""\n\n' % (uid, message)
+                    pomsg = u'%s\nmsgid "%s"\nmsgstr ""\n\n' % (pos, message)
                     pofile.write(pomsg)
             finally:
                 pofile.close()
+
+    def _join(self, strings, prefix="# ", sep=", ", max_length=70):
+        lines = [[prefix, strings[0]]]
+        strings = strings[1:]
+        length = max_length - len(prefix)
+        while strings:
+            next = strings[0]
+            del strings[0]
+            if length - len(next) - len(sep) < 0:
+                length = max_length - len(next) - len(prefix)
+                lines[-1] = "".join(lines[-1])
+                lines.append([prefix, next])
+            else:
+                lines[-1].append(sep)
+                lines[-1].append(next)
+                length = length - len(sep) - len(next)
+        lines[-1] = "".join(lines[-1])
+        return "\n".join(lines)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.