3

Delphi comes localized in various languages (English, Japanese, German, French I think). The command line compiler (dcc32) also has been localized so the German version writes "Fehler" rather than "Error" and "Warnung" rather than "Warning" to the console.

I have written a program that parses this output and (as one of its features) counts Errors and Warnings. This fails with the localized strings.

I could adapt the program to also detect the localized text but that feels wrong. I'd rather force the compiler to use English for its output. Is there a command line switch or any other option to do that?

I'd like to support all Delphi versions that use msbuild, that is >=2007.

EDIT:

As for reading the error code rather than the message, consider the following error:

C:\[...]\Borland.Delphi.Targets(113,3): error : blub.pas(56) Error: E2029 ',' expected but identifier 'bla' found

The error code is E2029 but it is rather difficult for a program to detect it. Detecting the text "Error: " is much simpler and less error prone.

dummzeuch
  • 10,975
  • 4
  • 51
  • 158
  • It feels less wrong to use the wrong localization than to use the right localization? – Morgan Thrapp Aug 28 '15 at 15:20
  • I would think reading the error *code* rather than *message* or *name* would be the appropriate thing to do. – Jerry Dodge Aug 28 '15 at 15:29
  • 1
    Most programmers can read and understand English, but only a few (including me) can even read Japanese. I'd like my program to be able to work with all versions. If the user doesn't like the fact that it switches the output to English, he is free to not use my program. – dummzeuch Aug 28 '15 at 15:30
  • @JerryDodge see edited question – dummzeuch Aug 28 '15 at 15:36
  • 1
    I don't see how detecting `Error` is any easier than detecting `E2029` - you presumably would want to handle each specific error type differently anyway. – Jerry Dodge Aug 28 '15 at 15:37
  • @JerryDodge Maybe in the future, I'd want to handle some specific ones but right now I am only interested in knowing that a line contains an error message. But even if that were not the case: Detecting the string "Error:" is definitely simpler than detecting a string of the form "E<4digitnumber>". – dummzeuch Aug 28 '15 at 15:45
  • And what if it's just a `[Warning]` which has some output message containing the word `Error`? – Jerry Dodge Aug 28 '15 at 15:46
  • @JerryDodge And what if it is just a [Warning] which has some output message containing a string of the form "E<4digitnumer>"? We have discussed this option now and I have decided to not got this way. Thanks for the suggestion. – dummzeuch Aug 28 '15 at 15:52
  • Some time a go I wrote a small class that can call MS build and compile a Delphi project, and capture the output to a TStrings object You can get it here. It is not realy an answer to you question but only some help. https://www.dropbox.com/s/shueqyxfcmtof2u/MSBuild.7z?dl=0 – Jens Borrisholt Aug 28 '15 at 16:48
  • 1
    Thanks @JensBorrisholt I already have code for capturing (and interpreting) the output. – dummzeuch Aug 28 '15 at 16:51
  • 1
    @Jerry, it's pretty common to filter compiler messages like this, and what you do is look for something matching, say, a regex: `Error: [EW]\d{4}`. Of course, it *could* just search for `[EW]\d{4}`, but you're much less likely to get false positives if you can include more of the surrounding text; in this case, `Error:`. We can't assume that this tool would do something special for each different error code. My company wrote a tool that merely counts each type of message for later tracking. – Rob Kennedy Aug 28 '15 at 20:56
  • 1
    As counterintuitive as it may sound, @Morgan, yes. When you're running a command programmatically, you generally want the output to be in as predictable a format as possible. I would assume that no human will actually see the compiler's output when it's run by Dummzeuch's program. The Git toolset uses the terms *porcelain* and *plumbing* to distinguish between user-facing commands and commands meant to be consumed by other programs, respectively. You wouldn't generally want to localize plumbing commands because it would interfere with other programs' parsing of their output. – Rob Kennedy Aug 28 '15 at 21:01

2 Answers2

5

As with most Delphi applications the used locale is set in the registry under HKEY_CURRENT_USER\Software\Embarcadero\Locales. Older versions may use HKEY_CURRENT_USER\Software\Borland\Locales.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • On my machine this seems to work for Delphi XE and up, but not for earlier versions. I just found that I don't have dcc32.de files for these earlier versions, so maybe that's why I doesn't work. – dummzeuch Aug 28 '15 at 16:47
  • Renaming the dcc32.de and dcc32.fr files for the newer versions resulted in English messages. So, I see two options to reach my goal: Hook registry access and return EN for the path or hook file access to the .de/.fr files and make the compiler think they don't exist. I don't know whether hooking would work though, since dcc32 is not called directly but through msbuild. – dummzeuch Aug 28 '15 at 16:50
  • I have a machine with Delphi 6 on it and I can confirm that HKEY_CURRENT_USER\SOFTWARE\Borland\Locales exists – Jens Borrisholt Aug 28 '15 at 17:02
  • You can just write a program that changes the entry and run it before and after the compile - either inside the build script or in a batch. You can even run BdsSetLang.exe with EN or DE from the command line, but you have to use the right version corresponding to the Delphi version. – Uwe Raabe Aug 28 '15 at 20:39
  • Why change the entry? Just read the entry and use also localized keywords to catch. – Sir Rufo Aug 29 '15 at 13:03
  • @UweRaabe I'd rather not make any changes to the user's computer. What if my program crashes and fails to reset the entries? – dummzeuch Aug 30 '15 at 16:19
  • After reading an answer i got to a different question a few years ago j it occurred to me that RegOverridePredefKey ( https://msdn.microsoft.com/en-us/library/ms724901(VS.85).aspx ) might be an option here. – dummzeuch Aug 30 '15 at 18:11
1

I'd use a regular expression to parse these statements and grab the various pieces -- the error number in this case. (I realize a lot of folks hate regular expressions, but when you've got one or two format statements used to create all of the output following the exact same template, regex is perfect.)

David Schwartz
  • 1,756
  • 13
  • 18
  • That would work well, if the text were really created using the same format strings. But since the text is localized there are 4 times as many format strings in use. – dummzeuch Aug 28 '15 at 16:55
  • Regular expressions are nice when you've got a fairly constrained set of templates to parse. The main objections I hear like this are from people who really don't understand their flexibility or how to write them properly. I've discovered that whenever I suggest they'd be useful in a particular situation here on SO, I'll get far more detractors than supporters. I've also noticed that, aside from poo-pooing the use of regular expressions in general, nobody has much of an alternative to suggest. So thanks for the downvote and out-of-hand rejection, but it doesn't change anything. – David Schwartz Aug 29 '15 at 21:57