extradoc.py: Use more of Unicode internally.

master
François Pinard 13 years ago
parent d1faa7686a
commit 50795980c3
  1. 15
      extradoc.py

@ -37,6 +37,7 @@ any included sections is specified, then either be part of one of them or
within the introduction (that is, before the first header). within the introduction (that is, before the first header).
""" """
import codecs
import os import os
import polib import polib
import re import re
@ -109,7 +110,7 @@ class Main:
# Prepare the work. # Prepare the work.
if not self.split and (self.html or self.org or self.pdf): if not self.split and (self.html or self.org or self.pdf):
self.org_file = open(self.prefix + '.org', 'w') self.org_file = codecs.open(self.prefix + '.org', 'w', encoding)
else: else:
self.org_file = None self.org_file = None
if self.pot: if self.pot:
@ -122,14 +123,16 @@ class Main:
'Last-Translator': 'you <you@example.com>', 'Last-Translator': 'you <you@example.com>',
'Language-Team': 'English <yourteam@example.com>', 'Language-Team': 'English <yourteam@example.com>',
'MIME-Version': '1.0', 'MIME-Version': '1.0',
'Content-Type': 'text/plain; charset=utf-8', 'Content-Type': 'text/plain; charset=%s' % encoding,
'Content-Transfer-Encoding': '8bit', 'Content-Transfer-Encoding': '8bit',
} }
# Process all source files. # Process all source files.
if arguments: if arguments:
for argument in arguments: for argument in arguments:
self.extract_org_fragments(open(argument), argument) self.extract_org_fragments(
codecs.open(argument, 'r', encoding),
argument)
else: else:
self.extract_org_fragments(sys.stdin, '<stdin>') self.extract_org_fragments(sys.stdin, '<stdin>')
@ -160,8 +163,8 @@ class Main:
if self.split: if self.split:
if self.html or self.org or self.pdf: if self.html or self.org or self.pdf:
name = line[7:].strip() name = line[7:].strip()
self.org_file = open( self.org_file = codecs.open(
'%s/%s' % (self.prefix, name), 'w') '%s/%s' % (self.prefix, name), 'w', encoding)
level = None level = None
continue continue
if line.startswith('*'): if line.startswith('*'):
@ -199,7 +202,7 @@ class Main:
text = text[3:-3].replace('\\\n', '') text = text[3:-3].replace('\\\n', '')
if self.pot: if self.pot:
self.po.append(polib.POEntry( self.po.append(polib.POEntry(
msgid=text.decode(encoding), msgid=text,
occurrences=[(name, str(line_no))])) occurrences=[(name, str(line_no))]))
for line in text.splitlines(): for line in text.splitlines():
if line.startswith('#+IF '): if line.startswith('#+IF '):

Loading…
Cancel
Save