Jump to page: 1 2
Thread overview
How to print Chinese characters in console in window XP?
Jun 27, 2009
Sam Hu
Jun 27, 2009
Sam Hu
Jun 27, 2009
Sam Hu
Jun 27, 2009
Elrood
Jun 27, 2009
Rainer Deyke
Jun 27, 2009
Derek Parnell
Jun 27, 2009
Rainer Deyke
Jun 27, 2009
Elrood
Jun 28, 2009
Sam Hu
Jun 29, 2009
Rainer Deyke
Jun 29, 2009
Elrood
June 27, 2009
In DMD2030 I just found that Chinese characters the like can not print properly into console.

//Below code does not show output properly in windows console:
void main()
{
wstring country="Öйú";
writefln(country);
}



Is this an OS issue or is there any way to reach the goal?

Thanks in advance.
June 27, 2009
On Sat, Jun 27, 2009 at 5:53 AM, Sam Hu<samhudotsamhu@gmail.com> wrote:
> In DMD2030 I just found that Chinese characters the like can not print properly into console.
>
> //Below code does not show output properly in windows console:
> void main()
> {
> wstring country="中国";
> writefln(country);
> }
>
>
>
> Is this an OS issue or is there any way to reach the goal?

It's an OS issue.  Someone asks about this once every two weeks.  You have to set up cmd.exe to use Unicode.  You have to change the fonts to Lucida, I think, and use 'chcp 65001' before running your program.
June 27, 2009
Jarrett Billingsley Wrote:

> On Sat, Jun 27, 2009 at 5:53 AM, Sam Hu<samhudotsamhu@gmail.com> wrote:
> > In DMD2030 I just found that Chinese characters the like can not print properly into console.
> >
> > //Below code does not show output properly in windows console:
> > void main()
> > {
> > wstring country="Öйú";
> > writefln(country);
> > }
> >
> >
> >
> > Is this an OS issue or is there any way to reach the goal?
> 
> It's an OS issue.  Someone asks about this once every two weeks.  You have to set up cmd.exe to use Unicode.  You have to change the fonts to Lucida, I think, and use 'chcp 65001' before running your program.

Thanks so much for your help.
Below is my try:
1.source(wrote in notepad.exe)

module test;
import std.stdio;
import std.c.windows.windows;
extern(Windows) {BOOL SetConsoleOutputCP(UINT wCodePageID);}

void main()
{
SetConsoleOutputCP(65001);
wstring country="Öйú";
writefln(country);
}

2.set notepad font Lucida Console (acutally tried Lucida Sans Unicode also);
3.Save test.d in Unicode (actually also tried UTF-8);
4.Compile and run.But the output still doesn't make sense.

Regards,
Sam

June 27, 2009
and I start cmd.exe with /u switch.

I also tried being inspired by below article: http://www.codeproject.com/KB/cpp/unicode_console_output.aspx?display=Print

but unfortunately also failed.

June 27, 2009
On Sat, Jun 27, 2009 at 10:55 AM, Sam Hu<samhudotsamhu@gmail.com> wrote:
> and I start cmd.exe with /u switch.
>
> I also tried being inspired by below article: http://www.codeproject.com/KB/cpp/unicode_console_output.aspx?display=Print
>
> but unfortunately also failed.
>
>

Well I don't know how else to help, I just know that cmd.exe sucks when it comes to Unicode :\
June 27, 2009
Sorry to have to disappoint you, but Chinese output to a Windows console is non-trivial if not entirely impossible (you'd probably have to ask someone using a Chinese Windows version for a definitive answer).

Your approach will work for more common unicode characters, like eg. the greek alphabet, the problem is that the fonts included with your standard Windows just don't come with Chinese glyphs.

In theory you *could* hack the registry to enable different fonts for the console (HKLM/SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont, add a string entry named 00, 000, 000 etc. and your desired font as value), but you'd still have to find a font including Chinese glyphs which works for this purpose. There are fonts like for example GNU unifont and something called SimSun from Micro$oft which contain these glyphs, but to my knowledge none these work in the console.

So the short answer is no, afaik there isn't any practical way to get Chinese output in the Windows console.
June 27, 2009
Elrood wrote:
> Sorry to have to disappoint you, but Chinese output to a Windows console is non-trivial if not entirely impossible (you'd probably have to ask someone using a Chinese Windows version for a definitive answer).

No, it's not.  In Python, unicode text output just plain works.

Program:
  # coding=utf-8
  print u'中国'
Output:
  中国

This is a bug in D, full stop.

(Yes, you do need to to set a codepage that contains these characters (I am using CP932) and you need an font that can represent these characters.  I assume OP already has both.  Note that CP65001 does not work.)


-- 
Rainer Deyke - rainerd@eldwood.com
June 27, 2009
On Sat, 27 Jun 2009 16:13:03 -0600, Rainer Deyke wrote:

> Elrood wrote:
>> Sorry to have to disappoint you, but Chinese output to a Windows console is non-trivial if not entirely impossible (you'd probably have to ask someone using a Chinese Windows version for a definitive answer).
> 
> No, it's not.  In Python, unicode text output just plain works.
> 
> Program:
>   # coding=utf-8
>   print u'中国'
> Output:
>   中国
> 
> This is a bug in D, full stop.
> 
> (Yes, you do need to to set a codepage that contains these characters (I am using CP932) and you need an font that can represent these characters.  I assume OP already has both.  Note that CP65001 does not work.)

I'm having troubles with this ...


C:\temp>chcp 932
Invalid code page
C:\temp>chcp 65001
Active code page: 65001

It seems that my Windows XP doesn't know about CP932.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
June 27, 2009
Derek Parnell wrote:
> C:\temp>chcp 932
> Invalid code page
> C:\temp>chcp 65001
> Active code page: 65001
> 
> It seems that my Windows XP doesn't know about CP932.

Yeah, it looks like some more setup work is required.  I got the same
error message when trying to use CP932 or CP950.  Under Windows XP, in
Regional and Language Options under the control panel:
  - On the Languages pane, make sure East Asian languages checked.
  - On the Advanced pane, make sure that the code pages you want to use
are checked.
  - Also on the Advanced pane, you may need to select the language you
want to use as the language for non-Unicode programs.

However, I assume that the OP already has his computer set up to support Chinese characters from the console, or he wouldn't be asking this question.  I can confirm that on my computer, unicode text output works in Python but not in D.


-- 
Rainer Deyke - rainerd@eldwood.com
June 27, 2009
@Rainer Deyke:
> In Python, unicode text output just plain works.
> 

While it certainly wasn't my intent to spread false info, nor to defend D or sidetrack from its bugs, I cannot confirm that unicode output *just plain works*, neither with Python, and I'd be highly interested in more info on how you got it to work. CP932 is invalid on my machine as well, and I don't know of a font that supports Chinese symbols and is available for the Windows console. Could you post some further clues like which font and which version of Windows you use, please? That'd be highly appreciated, thanks in advance.
« First   ‹ Prev
1 2