elizagamedev / wolftrans

Translation tool for Wolf RPG Editor games
Mozilla Public License 2.0
47 stars 9 forks source link

incompatible character encodings: UTF-8 and Windows-31J #2

Open N1nj4R4bb1D opened 8 years ago

N1nj4R4bb1D commented 8 years ago

wolftrans-0.2.0/lib/wolftrans/patch_text.rb:254:in `block (2 levels) in process_patch_file': incompatible character encodings: UTF-8 and Windows-31J (Encoding::CompatibilityError)

Encountered this problem with one game. I fixed it for myself by cobbling together an additional exception handling in patch_text.rb:254

begin
    output << "> CONTEXT " << context.to_s << " < UNTRANSLATED\n"
rescue => e
    if context.to_s.encoding != output.encoding
        output << context.to_s.encode!(output.encoding) << " < UNTRANSLATED\n"
    else
        raise e
    end
end
elizagamedev commented 8 years ago

Hmm, what OS are you running? And if you're running Windows, is your system codepage set to 932 (Japanese) by chance?

N1nj4R4bb1D commented 8 years ago

Windows 10 (64-bit) and indeed language for non-Unicode programs is set to Japanese (which is required to run Japanese games in many cases). What was interesting with this encounter was that it came up with only one game from those i tested (i can recheck with different locale if you want).

elizagamedev commented 8 years ago

No thanks, I think I've figured it out. I was a bit sloppy and assumed that Ruby would be using UTF-8 for string literals, but it seems it uses the encoding of the source file, which makes sense. However, if you don't specify in the source file that it's encoded in UTF-8, it assumes the system codepage (which in your case was CP932) which it can't concatenate with the strings that it read from the files which it explicitly encoded to UTF-8. (It worked for me because my codepage is UTF-8.)

I think I'm doing a poor job of explaining this, but I'm about to merge your pull request with my own code and that should hopefully be a bit clearer.

xephael commented 8 years ago

I'm getting a very similar error, "E:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wolftrans-0.2.0/lib/wolfrpg/filecoder.rb:86:in `encode': incomplete "\x81" on Windows-31J (Encoding::InvalidByteSequenceError)" My non-Unicode language is set to Japanese, I'm not sure if the project has been abandoned at this point, but is there anything I can do about this?