How to display and edit Japanese in VC++ source files?

Norman Diamond 101 Reputation points
2020-12-08T18:54:56.8+00:00

I installed Japanese Visual Studio 2010 Pro and Japanese Visual Studio 2015 Pro on an English-Canada Windows 10 Pro system. Visual Studio displays its own UI in Japanese correctly. But when opening Visual C++ source files to edit in the C++ Source Code Editor, Japanese text in strings and comments gets pushed through an 8-bit font and displays as mojibake. I have changed environmental options for Font and Colour in both Text Editor and All Text Tool Windows from Consolas to MS Gothic but the source code editor still displays Japanese text as mojibake.

Google searches found a "solution" of sorts. EVERY TIME I OPEN A SOURCE FILE, right-click it, select to open with an application, select the C++ Source Code Editor With Encoding, scroll down to find Shift-JIS (code page 932) and open the file.

Supposedly the source code editor autodetects the encoding of the source file to be opened, but Japanese Visual Studio doesn't autodetect Japanese source files and I have to go through the above steps EVERY TIME.

Is there really no way to set encoding (code page) in the same manner as the environmental options for fonts? So that I can continue editing source code that I had worked on in Japan?

Late breaking news: Although this is an English-Canada Windows 10 system matching the region where I now live (except that lots of Windows 10 stuff alters it to English-UK in a big regression from Windows 7), it is possible to set the system locale, i.e. the default code page for non-Unicode programs, to Japanese. However, this doesn't just impact one non-Unicode program i.e. the C++ Source Code Editor, it also impacts all other non-Unicode programs on the entire PC.

Can Japanese Visual Studio be set to recognize Japanese text?

Developer technologies C++
Developer technologies Visual Studio Other
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Darran Rowe 1,986 Reputation points
    2020-12-09T08:06:22.267+00:00

    Unfortunately, this is what Unicode is there for.
    Your best option is to open the files one by one and then save them to one of the Unicode formats. This is made easier on Windows 10 by using UTF-8 as the codepage for non Unicode programs.

    1 person found this answer helpful.
    0 comments No comments

  2. Norman Diamond 101 Reputation points
    2020-12-10T01:02:14.337+00:00

    After changing the Windows 10 system locale (default code page for non-Unicode programs such as the Visual Studio C++ code editor), I didn't have to convert Japanese source files to Unicode.

    But I still had to convert Chinese source files. I had to open them in Notepad and store them as UTF-16 LE. Notepad could store them as UTF-8 with BOM but Visual Studio hanged. I had to do something else in addition to storing them in UTF-16 LE because for a while Visual Studio gave weird error messages about not finding files, but I don't remember how I solved it. Since I use Visual Studio 2015 with the Visual Studio 2010 tool chain, I think the editing problems are in Visual Studio 2015 and the weird error messages are in Visual Studio 2010. Fortunately I only had 3 Chinese source files.

    If Microsoft had to do this to all of their source files, I bet they'd fix Visual Studio's autodetection.

    1 person found this answer helpful.

  3. Tianyu Sun-MSFT 34,436 Reputation points Microsoft External Staff
    2020-12-09T08:01:11.453+00:00

    Hello @Norman Diamond ,

    Thank you for taking time to post this issue in Microsoft Q&A forum.

    I’m afraid, there isn’t an easier way to display and edit Japanese in VS++ source files in VS. The default(Auto-Detect) Encoding may not choose the specified Encoding when using C++ Source Code Editor (with encoding) option.

    Choosing Japanese (Shift-JIS) – Codepage 932 is a workaround, but as you mentioned above, EVERY TIME. So I suggest you directly suggest a feature (or report this issue) to Visual Studio Product Team in our Developer Community.

    Best Regards,
    Tianyu

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.