Reading some of the other issues already open, and based on some old code I wrote which provides a custom specialization for get_variable_value(), I'm not really sure this is not possible yet. In short, client code should be able to provide a custom function that takes a string as input and returns whatever the translation of that string is.
I've been trying to implement this myself. My approach has been to look for an optional method std::string tag_callback(const std::string&) in the context provided to generate(). If current tag can't be found in the context, and tag_callback() is provided, I invoke it.
This is working so far but I'm not 100% satisfied because:
each call to render() (and similarly for test()) has to pass one extra parameter that is the original context. As render navigates through the context, it loses the reference to the top level one, so at the moment it needs to call the provided callback it needs a second, unaltered reference to the top level context to check if user provided any custom methods;
the test callback bool if_callback(const std::string&) returns a bool, but I'm not sure how to extend it to return a list;
related to issue #12, parent context is not searched. At some point, apply_visitor() will call render() with an std::map as the top level context, thus custom methods won't be found.
I'm not sure I'm doing this the right way, comments are welcome.
Reading some of the other issues already open, and based on some old code I wrote which provides a custom specialization for get_variable_value(), I'm not really sure this is not possible yet. In short, client code should be able to provide a custom function that takes a string as input and returns whatever the translation of that string is.
I've been trying to implement this myself. My approach has been to look for an optional method
std::string tag_callback(const std::string&)
in the context provided togenerate()
. If current tag can't be found in the context, andtag_callback()
is provided, I invoke it. This is working so far but I'm not 100% satisfied because:render()
(and similarly fortest()
) has to pass one extra parameter that is the original context. As render navigates through the context, it loses the reference to the top level one, so at the moment it needs to call the provided callback it needs a second, unaltered reference to the top level context to check if user provided any custom methods;bool if_callback(const std::string&)
returns a bool, but I'm not sure how to extend it to return a list;apply_visitor()
will callrender()
with an std::map as the top level context, thus custom methods won't be found.I'm not sure I'm doing this the right way, comments are welcome.