From c788cacf1dbd88e1fc590a79d00aa88d49d18822 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 15 Apr 2025 04:37:23 +0500 Subject: feat: get localization names using bundle.localization --- bot/src/commands/lua.cpp | 16 ++++++++++++++-- bot/src/commands/lua.hpp | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'bot/src/commands') diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index 2665b68..748a75e 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -295,7 +295,8 @@ namespace bot::command::lua { }); } - void add_l10n_library(std::shared_ptr state) { + void add_l10n_library(std::shared_ptr state, + const InstanceBundle &bundle) { state->set_function( "l10n_custom_formatted_line_request", [](const sol::table &request, const sol::table &lines, @@ -346,6 +347,17 @@ namespace bot::command::lua { return line; }); + + state->set_function("l10n_get_localization_names", [state, &bundle]() { + sol::table o = state->create_table(); + + auto locales = bundle.localization.get_loaded_localizations(); + + std::for_each(locales.begin(), locales.end(), + [&o](const std::string &x) { o.add(x); }); + + return o; + }); } void add_string_library(std::shared_ptr state) { @@ -472,7 +484,6 @@ namespace bot::command::lua { add_json_library(state); add_net_library(state); add_string_library(state); - add_l10n_library(state); } void add_chat_libraries(std::shared_ptr state, @@ -482,6 +493,7 @@ namespace bot::command::lua { lua::library::add_irc_library(state, bundle); lua::library::add_twitch_library(state, request, bundle); lua::library::add_db_library(state, bundle.configuration); + lua::library::add_l10n_library(state, bundle); } void add_irc_library(std::shared_ptr state, diff --git a/bot/src/commands/lua.hpp b/bot/src/commands/lua.hpp index 9a5c344..bf48ab6 100644 --- a/bot/src/commands/lua.hpp +++ b/bot/src/commands/lua.hpp @@ -31,6 +31,8 @@ namespace bot::command::lua { const Configuration &config); void add_irc_library(std::shared_ptr state, const InstanceBundle &bundle); + void add_l10n_library(std::shared_ptr state, + const InstanceBundle &bundle); void add_base_libraries(std::shared_ptr state); void add_chat_libraries(std::shared_ptr state, -- cgit v1.2.3