Article View: borland.public.delphi.nativeapi
Article #177Re: System error messages in other languages
From: Steve
Date: Thu, 29 Jan 2004 01:32
Date: Thu, 29 Jan 2004 01:32
87 lines
4650 bytes
4650 bytes
I'm trying to do something similar in C++.
Our application is localized with regard to our own messages but we
can't control the system messages, so I attempted to use the following
function to return a system message in the language of my choice.
mainLang and subLang are determined by the culture (i.e, "en-us",
"en-gb", fr")
lastError is the last system error that occurred.
I'm preserving it because the first FormatMessage may not work, and
then I'll try it again with the default language.
wStat = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM, NULL, lastError,
MAKELANGID (mainLang, subLang),
(LPTSTR)&pErrorMessage, 0, NULL);
Passing in anything other than the default language results in system
error code 1815: ERROR_RESOURCE_LANG_NOT_FOUND
"The specified resource language ID cannot be found in the image
file."
The error message is misleading since it implies that there is
something
I could do to correct the problem... like upgrading Windows for other
language support. I would have no problem with that.
However, the following code for FormatMessage tells what really
happens.
if ( ( dwFlags & FORMAT_MESSAGE_FROM_STRING ) &&
00580 ( dwFlags & FORMAT_MESSAGE_FROM_SYSTEM ) )
00581 {
00582 ERROR( "These flags cannot co-exist. You can either "
00583 "specify FORMAT_MESSAGE_FROM_STRING, or "
00584 "FORMAT_MESSAGE_FROM_SYSTEM.\n" );
00585 SetLastError( ERROR_INVALID_PARAMETER );
00586 goto exit;
00587 }
00588
00589 if ( !( dwFlags & FORMAT_MESSAGE_FROM_STRING ) &&
00590 ( dwLanguageId != 0 && dwLanguageId != MAKELANGID(
LANG_NEUTRAL, SUBLANG_DEFAULT ) ) )
00591 {
00592 ERROR( "Invalid language indentifier.\n" );
00593 SetLastError( ERROR_RESOURCE_LANG_NOT_FOUND );
00594 goto exit;
00595 }
If you are passing in the flag for a system error, it forces you to
use the default culture. So if your OS is in German and the client
also reads German, then I think you'd be OK. But say you have
customers in different languages pointing to the same server...??
I can't figure out how to do this, except for trying to change the
default language on the fly, and hope you don't break anything.
Could try Altavista(Babelfish) translation: "the printer name is
inadmissible"
Michael Winter <delphi.net@gmx.net> wrote in message news:<q4i2x9uc11la.dlg@news.michawinter.de>...
> Rob Kennedy wrote:
>
> > Could you just send the numeric error code, and let the client machine
> > generate the error message using the local language?
>
> Yes but since OS error messages are not too instructive somtimes, in many
> cases the final error message is generated combining information from
> inside the project and from the OS, as in
>
> Can't open the %s project, OS reports this error: %s - Try again later.
>
> OTOH, the same happens on the client: If the computer has a german OS
> installed, and my software is switched to english, OS messages still appear
> in german language.
>
> > You can pass a language identifier as the fourth parameter to
> > FormatMessage. The OS needs to know that language.
>
> I tried this but all I get is, depending on the language id, either the one
> installed language or an empty string.
>
> I assume that on a 'normal' Windows there is only one language available
> per module, and that seems to be true for the kernel modules, too. However,
> I've found two promising CDs labelled 'multilingual user interface' at my
> MSDN heap, and I'm going to try these in a Vmware box the next days.
>
> -Michael
Technical Details
Message-ID:
<460395d0.0401281732.33bae701@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mailReferences:
<l9dtev7hicyv.dlg@news.michawinter.de> <400da2e5$1@newsgroups.borland.com> <q4i2x9uc11la.dlg@news.michawinter.de>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f94dd,47c709fe6a10c938 X-Google-Attributes: gidf94dd,public X-Google-ArrivalTime: 2004-01-28 17:32:07 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail From: velcromagnon@yahoo.com (Steve) Newsgroups: borland.public.delphi.nativeapi Subject: Re: System error messages in other languages Date: 28 Jan 2004 17:32:06 -0800 Organization: http://groups.google.com Lines: 87 Message-ID: <460395d0.0401281732.33bae701@posting.google.com> References: <l9dtev7hicyv.dlg@news.michawinter.de> <400da2e5$1@newsgroups.borland.com> <q4i2x9uc11la.dlg@news.michawinter.de> NNTP-Posting-Host: 199.231.50.128 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1075339926 17930 127.0.0.1 (29 Jan 2004 01:32:06 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 29 Jan 2004 01:32:06 +0000 (UTC)