Error message and trace translations
Feature request checklist
- [ x ] There are no issues that match the desired change
- [ x ] The change is large enough it can't be addressed with a simple Pull Request
Change I am using CEL as a rule compute engine within my product. I have a need to be able to provide translated error messages to users and am wondering if there is any way for this to be accomplished in CEL. I am happy to inject the translation files in my code, if a mechanism exists.
Happy to submit a pull request if some pointers can be given.
Example
Undeclared reference to 'test' (in container '')
Ideally, I would like to be able to translate messages of this sort.
Alternatives considered N/A
Hi @vivshankar, if you'd like to contribute here, I can offer you some advice for the parser and checker errors in a manner that permits the use of alternative language for the error message information. Would that work for your needs?
The runtime errors are in need of love and #25 and #189 are the specific changes that need to improve runtime stack traces and error messaging.
@TristonianJones Happy to take a shot at this.
@vivshankar Thanks for being patient on this. I spent a little time thinking about this the other day and both the parser/errors.go and the checker\errors.go introduce an abstraction layer between the parser / checker and the common.Errors object. These minor abstractions introduce standard error messages and formats for each component.
My recommendation is as follows:
- Introduce a
Localizerinterface in thecommon/localizer(new) package.
type Localizer interface {
Localize(int msgID, args ...interface{})
}
- Establish constants for the existing English messages in
common/localizer/codes.goand a mapping from the message id to a struct containing the localized message and the number of expected arguments to the message for the sake of linting. This first mapping for English can be incommon/localizer/en_us.go - Create functional options for configuring the localizer for the parser and checker which adjust the localizer used when creating the
parserErrorsandcheckerErrorsobjects.
This will probably take a bit of time to do, but the above is the rough idea. Please feel free to ask questions as you work through the code.