Lua: Add wesnoth.get_language returning the current locale

As @ProditorMagnus points out, Lua code can already figure out the
locale by calling wesnoth.textdomain("wesnoth")(s) where s is any string
from po/wesnoth/wesnoth.pot.  https://forums.wesnoth.org/viewtopic.php?p=638560#p638562
This commit is contained in:
josteph 2019-02-15 17:38:56 +00:00
parent 0f06d37602
commit 3c3e73ac2d

View file

@ -22,6 +22,7 @@
#include "random.hpp"
#include "seed_rng.hpp"
#include "deprecation.hpp"
#include "language.hpp" // for get_language
#ifdef DEBUG_LUA
#include "scripting/debug_lua.hpp"
@ -401,6 +402,12 @@ static int intf_format_list(lua_State* L)
return 1;
}
static int intf_get_language(lua_State* L)
{
lua_push(L, get_language().localename);
return 1;
}
/**
* Dumps a wml table or userdata wml object into a pretty string.
* - Arg 1: wml table or vconfig userdata
@ -546,6 +553,7 @@ lua_kernel_base::lua_kernel_base()
{ "format", &intf_format },
{ "format_conjunct_list", &intf_format_list<true> },
{ "format_disjunct_list", &intf_format_list<false> },
{ "get_language", &intf_get_language },
{ nullptr, nullptr }
};