Question

I'm localizing an MFC app into Japanese, and have the resources working right.

My current problem is that, when I use AfxMessageBox or MessageBox, the dialog title and button messages come up in English, and I haven't found anywhere to change that.

I haven't found anything useful searching MSDN or Google.

So,

Does this work? Does Windows come up with "OK" or "Yes/No" buttons in Japanese, Arabic, and Russian?

If not, what do I specify to change these?

Edit: I went with MessageBoxEx, writing a wrapper class to make it as convenient to use as AfxMessageBox. It does appear that MB_OK comes up as "OK" in both English and Japanese, but other button options like MB_YESNO are translated into something that I assume is correct Japanese. This was a fairly small application to translate, and we might want to use something automated for the larger ones.

Was it helpful?

Solution

Use MessageBoxEx and specify the WORD wLanguageId field.

wLanguageId [in] Specifies the language for the text displayed in the message box button(s). Specifying a value of zero (0) indicates to display the button text in the default system language. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used.

To specify a language other than the current language, use the MAKELANGID macro to create this parameter. For more information, see MAKELANGID.

More information on MAKELANGID can be found here.


If this does not work well for you, the alternative would be to make your own dialog box.

OTHER TIPS

The title is a string you specify, so you should be able to translate it. In AfxMessageBox(), the title is the application name (AfxGetAppName() IIRC).

Regarding the buttons, the text is part of the OS and cannot be translated.

MessageBoxEx (mentioned by Brian) never worked well regarding languages support. This MS KB article from over a decade ago says the language id will be correctly supported by Windows 2000. But it obviously never made it through.

So you're pretty much out of luck. Your only solution would be to use a 3rd party implementation such as the excellent XMessageBox and provide translations through your string table.

Note that appTranslator's glossary contains words such as Yes, no, cancel,... in 25 languages and would translate them automatically.

Create your own L10N macros/function and use this code:

static LRESULT __stdcall ChangeCaptions(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode == HCBT_ACTIVATE) {
        SetWindowText(GetDlgItem((HWND) wParam, IDOK), L10N(GUI_OK_MSG));
        SetWindowText(GetDlgItem((HWND) wParam, IDCANCEL), L10N(GUI_CANCEL_MSG));
        SetWindowText(GetDlgItem((HWND) wParam, IDYES), L10N(GUI_YES_MSG));
        SetWindowText(GetDlgItem((HWND) wParam, IDNO), L10N(GUI_NO_MSG));
    }
    return 0;
}

int addon_gui_messagebox(HWND parentHWnd, HINSTANCE hInstance, void *text, void *caption, int type)
{
    int ret;
    hook = SetWindowsHookEx(WH_CBT, ChangeCaptions, hInstance, GetCurrentThreadId());
    ret = MessageBox(parentHWnd, text, caption, type);
    UnhookWindowsHookEx(hook);
    return ret;
}

As I wrote previously MessageBoxEx currently ignore lang arg.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top