Commits

Andréas Kühne committed c3dccea

Fixed encoding problems in export command. Fixed import error in parser.
Should now work with both Pyton 2.5 > and Python 3. Tested in Python 3.3 and 2.7.5

  • Participants
  • Parent commits 2cede3a

Comments (0)

Files changed (2)

File dbgettext/management/commands/dbgettext_export.py

 
         def write(file, string):
             string = string.replace('"','\\"') # prevent """"
+            string = '# -*- coding: utf-8 -*-\ngettext("""%s""")\n' % string
             string = string.encode('utf8')
-            file.write('# -*- coding: utf-8 -*-\ngettext("""%s""")\n' % string)
+            file.write(string)
 
         root = os.path.join(self.path, self.root)
 
                 for attr_name in options.attributes:
                     attr = get_field_or_callable_content(obj, attr_name)
                     if attr:
-                        f = open(os.path.join(path, '%s.py' % attr_name), 'w')
+                        f = open(os.path.join(path, '%s.py' % attr_name), 'wb')
                         write(f, sanitise_message(attr))
                         f.close()
 
                 for attr_name in options.parsed_attributes:
-                    f = open(os.path.join(path, '%s.py' % attr_name), 'w')
+                    f = open(os.path.join(path, '%s.py' % attr_name), 'wb')
                     for s in parsed_gettext(obj, attr_name, export=True):
                         write(f, sanitise_message(s))
                     f.close()

File dbgettext/parser.py

 from django.conf import settings
-from registry import registry
+from .registry import registry
 import re
 
 SENTENCE_RE = getattr(settings, 'DBGETTEXT_SENTENCE_RE', re.compile(r'^(.*?\S[\!\?\.])(\s+)(\S+.*)$', re.DOTALL))