开发者

How to do i18n and create Windows Installer of Haskell programs?

开发者 https://www.devze.com 2023-02-10 22:48 出处:网络
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 del

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:

  1. I18n of Haskell programs: the method described in Internationalization of Haskell programs did work (partially) if I change the command of executing the program from 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.
  2. Distribution on Windows: I'm used to work under Linux and build & package my Haskell programs using Cabal, but what is the most natural way to create a one-click Windows Installer from a cabalized Haskell package? Is the package bamse the right way to go?

------ 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:

How to do i18n and create Windows Installer of Haskell programs?

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.


for the first question, is it possible that you didn't install correct font or the font is not set to be used in the terminal.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号