[Mono-list] mcs use codepage and program with chinese

Jonathan Pryor jonpryor@vt.edu
Tue, 10 Aug 2004 08:05:42 -0400


On Tue, 2004-08-10 at 00:09,
=?gb2312?q?=FFffffb8=FFffffb8=20=FFffffbf=FFffffe4?= wrote:
<snip/>
> We use the tool "native2ascii" of JDK and run "native2ascii Hello.cs
> hello1.cs",then we get Hello1.cs in ascii coding.
> 
> run "mcs -codepage:utf8 Hello1.cs" ,then get Hello1.ex.Run hello1.exe,
> In windows we get right output "你好";
> 
> but in Linux it output some strange characters.

It's strange because you're doing *really* strange things.  native2ascii
doesn't convert to UTF-8, it converts to a custom ASCII-compatible
encoding.  It *isn't* UTF-8.  But then you go and tell mcs that the
codepage is UTF-8, and since 0x00-0x7F of UTF-8 *is* ASCII, this is akin
to just printing out the native2ascii text.  No wonder it looks
strange.  I do have to wonder why Windows prints the right text, except
in my experience the Windows console *sucks* when it comes to i18n, at
least compared with Linux.  Redirecting to a file and opening with
NOTEPAD.EXE gives me better success on Windows than sticking with the
console....

On Linux, make life easy: Skip native2ascii, save the file as UTF-8, and
compile with mcs -codepage:utf8:

        jon@melchior:tmp$ cat hwc.cs
        // Hello World, Chinese version
        using System;
        namespace Test
        {
           public class Hello
           {
             public static void Main()
             {
                 Console.WriteLine("你好");
             }
           }
        }
         
        jon@melchior:tmp$ mcs -codepage:utf8 hwc.cs
        Compilation succeeded
        jon@melchior:tmp$ mono hwc.exe
        你好

It may be that the reason your original compilation attempt didn't work
is that mcs didn't understand codpage 936.

Alternatively, it may not have worked for you originally because your
LANG environment variable isn't set properly.  Mine is set to
en_US.UTF-8, so your chinese text is rendered properly in the console.

 - Jon