Hey guys


Hey guys, 

How do I internationalize exception messages? Currently, I am using resourcestring for store the messages, but I am not sure if it translates the messages as well. Something like the image below :D

Thanks in advance :D

Comments

  1. I'm not a big fan of resource strings, because it makes it more difficult to understand the code. I prefer dxGetText instead. But resource strings do work.

    ReplyDelete
  2. I'm very happy with tsiLang. It's a commercial product, support all platforms and is very powerfull. All info on www.tsilang.com

    ReplyDelete
  3. +1 for dxGetText, Resourcestrings are translated

    ReplyDelete
  4. I am using tsilang too, and happy with it.

    ReplyDelete
  5. Thomas Mueller I really wonder what is difficult to understand on code like this:

    raise EProgrammerNotFound.CreateFmt(SProgrammerNotFound, [programmer.Name]);

    (apart from the fact that I could name the resourcestring even better to make clear it takes one string fmt arg)

    ReplyDelete
  6. Stefan Glienke in my book it's easier to understand something like this:

    raise ProgrammerNotFound.CreateFmt(_('Programmer %s not found'), programmer.Name);

    Especially since resource strings tend to be defined somewhere else in the code, possibly in a different unit.

    ReplyDelete
  7. Yup and the problem with your code is that the translation does not work anymore when someone decides to "fix" a typo in the string literal - been there, done that.

    In my book if the string that gets shown has any meaning to the understanding of the code, something is wrong.

    ReplyDelete
  8. Stefan Glienke if the string that gets shown should not have any meaning to the understanding of the code, that would mean that you can't use format for strings that get translated. If somebody botches the translation by removing the superfluous % or "translates" the s e.g. to German z for Zeichenkette the code breaks.

    (BorCoDero had such a bug in the error message "list index out of range (%d)" btw., they forgot to actually pass it to format.)

    ReplyDelete
  9. I uses i18n package. http://www.delphiarea.com/products/delphi-packages/i18n/
    It provide some special component like a calendar and some more. And it free and open-source :)

    ReplyDelete
  10. Thomas Mueller  BTW, GetText also converts into resource strings and hooking into resource string loading.
    Resourcestrings can be changed at run time by casting them to pResStringRec and changing its identifier under lock by Virtualprotect.

    ReplyDelete
  11. IMHO exception messages should be in plain English, then handled as expected by the UI level into translated messages, according to the context. Exceptions should not reach the end-user, but in the form of "detailed technical information": UI should display a clear and intuitive translated text, asking for further user action.
    For translating this end-user error messages, I usually use resource strings (and our https://github.com/synopse/mORMot/blob/master/SQLite3/mORMoti18n.pas on-the-fly translation system, based on plain text files).

    ReplyDelete
  12. All my Resourcestrings goes to a type of Data Module or a special unit. Simple that.

    ReplyDelete

Post a Comment