re: #25308 (review)
In commit “refactor: Reduce number of LoadChainstate return values” (ed3c27ae5034f27f6240d2dcafbdbfd9bc55b9d7)
Could we just use std::string
here?
It’s not possible to do this without changing behavior. Error messages like “Error opening block database” and “Incorrect or no genesis block found. Wrong datadir for network?” are translated and can’t be returned through std::string
.
I don’t want to introduce further coupling with translation.
I think there are only upsides not downsides to using bilingual_str
for messages that may be shown to the users.
Using bilingual_str
instead of std::string
only adds a dependency on the bilingual_str
struct struct which is a simple pair of std::string
’s. This is a very minimal dependency, and it doesn’t require the caller to use translations or the kernel library to provide them. It just allows translations to be passed along if they are present.
In general, I think it is a good practice to use bilingual_str
for user messages, whether or not they will be translated. Using the bilingual_str
type distinguishes user messages from other types of strings, and helps future-proof code so API’s don’t have to change if translations are added or removed. The choice of whether or not to translate an string can be context dependent, and may depending on how frequently a specific message will be shown or how complicated it is to translate. Just using bilingual_str
everywhere means APIs can pass translations along and not be tied to these implementation details.