1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-19 04:53:12 +01:00

Add ability to get current language

This commit is contained in:
Ted John
2020-05-13 23:35:58 +01:00
parent c88bb9e2bd
commit 41d41df3a5

View File

@@ -13,6 +13,7 @@
# include "../Context.h"
# include "../config/Config.h"
# include "../localisation/LocalisationService.h"
# include "Duktape.hpp"
# include "ScriptEngine.h"
@@ -138,6 +139,7 @@ namespace OpenRCT2::Scripting
DukObject obj(ctx);
if (ns == "general")
{
obj.Set("general.language", gConfigGeneral.language);
obj.Set("general.showFps", gConfigGeneral.show_fps);
}
result = obj.Take();
@@ -160,7 +162,19 @@ namespace OpenRCT2::Scripting
auto ctx = GetContext()->GetScriptEngine().GetContext();
if (_isUserConfig)
{
if (key == "general.showFps")
if (key == "general.language")
{
auto& localisationService = GetContext()->GetLocalisationService();
auto language = localisationService.GetCurrentLanguage();
auto locale = "";
if (language >= 0 && static_cast<size_t>(language) < std::size(LanguagesDescriptors))
{
locale = LanguagesDescriptors[language].locale;
}
duk_push_string(ctx, locale);
return DukValue::take_from_stack(ctx);
}
else if (key == "general.showFps")
{
duk_push_boolean(ctx, gConfigGeneral.show_fps);
return DukValue::take_from_stack(ctx);