I'm considering using Haskell to develop for a little commercial project. The program must be internationalized (to Simplified Chinese, to be specific), and my customer requests that it should be delivered in a one-click Windows Installer form. So basically these are the two problems I'm facing now:
LOCALE=zh_CN.UTF-8 ./Main
to LANG=zh_CN.UTF-8 ./Main
(I'm working on Ubuntu 10.10), however, the Chinese output is garbled, and I've no idea why is that.------ Details for the first problem ------
What I did was:
$ hgettext -k __ -o messages.pot Main.hs
$ msginit --input=messages.pot --locale=zh_CN.UTF-8
(Edit the zh_CN.po file, adding Chinese translation)
$ mkdir -p zh_CN/LC_MESSAGES
$ msgfmt --output-file=zh_CN/LC_MESSAGES/hello.mo zh_CN.po
$ ghc --make Main.hs
$ LANG=zh_CN.UTF-8 ./Main
And the output was like:
This indicates gettext is actually working, but for some reason the generated zh_CN.mo file is broken (my guess). I'm pretty sure my zh_CN.po file is encoded in UTF-8. Plus, aside from using System.IO.putStrLn
, I also tried System.IO.UTF8.putStrLn
to output the string, which didn't work either.
For the first question, the solution is to add decodeString
from Codec.Binary.UTF8.String
to the gettext function __
, like this:
__ :: String -> String
__ = decodeString . unsafePerformIO . getText
And then everything works just fine.