Solved

Multilingual project

Posted on 2000-04-26
9
346 Views
Last Modified: 2012-05-04
Hello,
I have finished a project recently. The User Interface is all in English. Then, on a last minute call, my boss asked me to do it in 2 languages.
How can I go about doing this?

Is it like, in the InitDialog, we load the labels to be converted to that particular language? I am not sure on how to get around to do this. Please show me a step by step method of handling this problem.

Thank you.
0
Comment
Question by:cheeonn
  • 4
  • 3
  • 2
9 Comments
 

Expert Comment

by:Le_Ron
ID: 2750569
Hi cheeonn,
If you are working under Visual C++, that's quite simple: there is a string table in the resource where all strings used by your program are. By the way, you just have to translate that table.
If you are not, a solution is to have a header file containing the definition of all your strings.
E.g.:
#define ID_STRING1 "My first string"
#define ID_STRING2 "Another string"
....

Then, include this file in all classes needing them and use ID_STRING1 in place of "My first String" in your code. If you do this for every strings in your app, changing only the header file and re-compiling will give you the program in another language.

Hope this helps
0
 
LVL 5

Accepted Solution

by:
proskig earned 25 total points
ID: 2750681
From codeguru:
Here is my way to change my App's language. It is tested under both Win98 and NT( Win95 will be good also). It looks good, but It needs more steps.

First, after you create you app, you should create a dll that contains all the resource of the application. the same resource ID but different language. The best way is add a new workspace of dll into your app's workspace, then drag and drop the resource. After doing that, modify the resource of the Dll to another language. This may take some time to do that.Complie and create the dll file.

The second is Modify you app source code.

In InitInstance( ) of your App class, before creating all windows or dialog, add code below:

(Japanese.dll is my resource dll file's name)


....
HINSTANCE hJapaneseDll      //Global var
......
CMultiLangApp::InitInstance()
{
.......
      //Get Language Setting from INI
      uLanguage = GetProfileInt("Language", "Language",0);

      if (uLanguage == 1)
      {
            //Language is set for Japanese.
            hJapaneseDll = AfxLoadLibrary("Japanese.dll");
            ASSERT(hJapaneseDll);
            AfxSetResourceHandle(hJapaneseDll);
      }
......
      //create dialog or main frame
......
}



Last, add a switch such like menus or radios to change settings of language, then the next time run the app, it will display the language your expected.

The core is function AfxSetResourceHandle(HINSTANCE), which changes the location to find the resource. The common dialog is based on the version of Windows. So I think that if you wanna create a real business international application, you should read the Register in InitInstance( ) to get the version of windows, then change to the appropriate language. This way can support as many languages as your like.

Because I create this sample under Japanese windows. So the sample's language dll is japanese, I hope you can see it. The complier environment is VC6.0 SP3 ,WindowsNT 4.0 SP4 and Windows 98
0
 
LVL 5

Expert Comment

by:proskig
ID: 2750688
You might also want to check this comment
http://codeguru.developer.com/mfc/comments/7038.shtml
0
 

Author Comment

by:cheeonn
ID: 2754023
Hello,
Err...in the String Table when I changed the language property to another language, some message about Code Page 950 comes out.
It means that I do not have the language installed?

Thank you for your solutions. I need more explanations on how to work on the solution.

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Expert Comment

by:proskig
ID: 2754249
proskig changed the proposed answer to a comment
0
 

Expert Comment

by:Le_Ron
ID: 2754571
Yes, that means a file is missing. Something may help you about that : open the READMEVC.HTM file in your visual studio root directory. Then, lokk after the title 'Multiple Language Resource Files'. Many things are explained there.

Once the corresponding .nls file is correctly installed on your machine, right-click on the 'string table' item in the resource tab and select 'insert copy'. You now have two string tables having their own language.

hope this helps
0
 

Author Comment

by:cheeonn
ID: 2771942
Adjusted points from 20 to 25
0
 

Author Comment

by:cheeonn
ID: 2771943
Hello,
This is what I have done so far:
Create a new project.
W32 Dynamaic Link Library (Project Name: ChineseRes.dll). A simple dll project. Finish.

Then, I copied all these from my program(which is in English) files over to the ChineseRes.dll directory.
a. Res directory
b. All my bitmaps
c. Resource.h
d. Itss.rc

Then in my ChineseRes.dll project, I included the Itss.rc file. After that, I open up all the dialog boxes and change the interface to the language I desire, which is Chinese and save and compile the simple dll project.

After that, I copied the dll that has already been compiled to my Windows/System directory.

In my actual program(the existing one, which is in English), I did some alterations to the code, as in what "proskig" told me to do, which is:

I add an HINSTANCE member variable to the application's CWinApp derived class.
HINSTANCE m_hChineseResDLL;

Then,
CWinApp::InitInstance definition:
m_hChineseResDLL=LoadLibrary("ChineseRes.dll");
ASSERT(m_hChineseResDLL !=NULL);
AfxSetResourceHandle(m_hChineseResDLL);

After that,
int CMyApp::ExitInstance()
{
  FreeLibrary(m_hChineseResDLL);
  return CWinApp::ExitInstance();
}

OK, that is a bit long story there.

Anyway, there is just one big problem. How about the MessageBox? How do I change the language in the message box itself, since it is only found in the code not in the resource file or in the string table.

I tried this method, which is: I made another copy of my actual program, and I changed the UI one by one and entered all the text in the messagebox to the string table and replaced the AfxMessageBox("Just a message");
to
AfxMessageBox(61447);
where 61447 is the value from the string table. Is that the correct way of doing?

And, how about the language from the
SetWindowsText? Can I use the same method as in the AfxMessageBox?
object.SetWindowsText(61447). But, this does not work.

Please help. Can you show me a correct way of doing this. The way I used is a little weird, isn't it?

Thank you.

If you do not understand what I have written here, I can be contacted at:
cheeonn@yahoo.com

Please help. I have until somewhere third week of May to complete this assignment. I know, all these multilingual stuff takes a really really long time to complete.
0
 

Author Comment

by:cheeonn
ID: 2809404
Thank you very much. It has been great pleasure having you as a personal guidance.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now