catala icon indicating copy to clipboard operation
catala copied to clipboard

Refactor error handling in Catala towards internationalization of error messages

Open denismerigoux opened this issue 9 months ago • 3 comments

The errors should be first-class values passed around instead of exceptions, so that the messages inside them can be translated to other languages.

denismerigoux avatar Mar 25 '25 13:03 denismerigoux

Related: menhir parsing errors (from compiler/surface/parser.messages) should be able to tell the errors and examples with the proper syntax

AltGr avatar Mar 25 '25 14:03 AltGr

After thinking about it a bit more, I am not convinced that the advantages of adding values for errors outweight just using strings as translation keys. Indeed, the other approach (gettext-like) is to use english strings in the source, but use those as keys in a runtime map to retrieve translations of the message.

While I admit having a specific type is cleaner, here are some points that should be considered:

  • having an additional indirection for every error message is quite heavy-weight to maintain
  • gettext shines for the updates of translations: if an english message changes, it will be noticed and the user prompted to update the translations
  • it also allows translations to "lag behind" (and be filled by the english messages), which is necessary if we support languages that the developers don't speak.

now, it's clearly not a silver bullet, it has its downsides and a clunky file format; but it is tested and proven. In fact, the overall added weight may be the same, but it separates the concern from the codebase -- is it worth it ?

AltGr avatar Mar 28 '25 09:03 AltGr

Thanks Louis for your analysis. There is another argument in favor of having a centralized sum type for every kind of error in the compiler : be able to arbitrarily fine-tune the printing of the error message depending on whether it appears on the CLI or inside an IDE plugin. This feature is orthogonal to the issue of localization but cannot be solved by gettext.

denismerigoux avatar Mar 28 '25 10:03 denismerigoux