Code: Select all
// Language package, containing key-value pairs of translation, e.g.,
// g_LanguagePack["HELLO@1"] = "Hello, {}!"
// The "@N" suffix indicates that this format string has N parameters.
// When there is no parameter, the suffix can be omitted.
std::unordered_map g_LanguagePack;
// The translator function
template
std::sting Translate(const std::string& key, VA&&... params);
Code: Select all
key
Code: Select all
template
consteval void Checker(const char (&key)[N], VA&&... va)
{
std::string_view string_view(key, N - 1);
std::size_t param_cnt = 0;
auto indicator_index = string_view.find('@');
if (indicator_index == std::string_view::npos) // no params
{
assert(sizeof...(VA) == 0);
}
else
{
// parse param_cnt_
for (auto i = indicator_index + 1; string_view.begin() + i != string_view.end(); i++)
{
auto digit = string_view.at(i); // get digit
assert('0'