fadingred / Greenwich

A Cocoa framework for localization
MIT License
236 stars 19 forks source link

Run script failing with UTF-16 error #12

Closed kevinhoctor closed 11 years ago

kevinhoctor commented 11 years ago

I'm trying to use Greenwich with our MoneyWell project, but the run script is failing and it looks like it's happening on a system Python file. Any ideas how to work around this?

Traceback (most recent call last):
  File "/Users/kevin/Development/Projects/MoneyWell/Scripts/actions/create", line 160, in <module>
    create_strings(config)
  File "/Users/kevin/Development/Projects/MoneyWell/Scripts/actions/create", line 111, in create_strings
    lang.integrate_changes(localizable)
  File "/Users/kevin/Development/Projects/MoneyWell/Scripts/lib/scriptlib/i18n/strings.py", line 114, in integrate_changes
    translation = self.translation()
  File "/Users/kevin/Development/Projects/MoneyWell/Scripts/lib/scriptlib/i18n/strings.py", line 54, in translation
    self._create_translation()
  File "/Users/kevin/Development/Projects/MoneyWell/Scripts/lib/scriptlib/i18n/strings.py", line 68, in _create_translation
    self._translation = Parser(self.name, langdir, base=base)
  File "/Users/kevin/Development/Projects/MoneyWell/Scripts/lib/scriptlib/i18n/strings.py", line 146, in __init__
    self.lines = strings.readlines()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 679, in readlines
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 588, in readlines
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 477, in read
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_16.py", line 112, in decode
UnicodeError: UTF-16 stream does not start with BOM
Command /bin/sh failed with exit code 1
wbyoung commented 11 years ago

Do you have any strings files lying around from however you were handling localization before? In strings.py, if you add print os.path.join(directory, '%s.strings' % name) just before line 146, you should be able to figure out what file it's failing for. Can you check the encoding of that file?

I'm planning on adding some changes that move to UTF-8 which is easier to handle in most version control systems, so this issue may not be something that causes problems going forward. Presumably those changes will be backwards compatible and we'll be able to read UTF-8 and UTF-16 and write UTF-8 files.

kevinhoctor commented 11 years ago

That was the problem: There was an existing Localizable.strings file. I removed it and the script went through. Thanks for the quick solution!

wbyoung commented 11 years ago

Glad to hear that fixed it!