This idea of localization as code has significant history from Perl: https://perldoc.perl.org/Locale::Maketext::TPJ13
Currently Mozilla Fluent seems like a good compromise implementation. The type checking is maybe not as advanced, but it is intended to be compatible with the tools most often used in localization to enable translators to handle all the data and organize the task. Very straightforward getting generated localized strings to agree in number, tense, gender, and so on.