From bba44c074c4c307d26811ec214782ece669c40d1 Mon Sep 17 00:00:00 2001 From: Micha Ober Date: Sat, 29 Oct 2022 19:01:46 +0200 Subject: [PATCH] Add config option to set language used for notifications --- acp/discord_notifications_module.php | 2 ++ adm/style/acp_discord_notifications.html | 6 +++++ event/notification_event_listener.php | 10 ++++++++ migrations/add_language_config.php | 29 ++++++++++++++++++++++++ notification_service.php | 9 ++++++++ 5 files changed, 56 insertions(+) create mode 100644 migrations/add_language_config.php diff --git a/acp/discord_notifications_module.php b/acp/discord_notifications_module.php index f5f3cd2..5175837 100644 --- a/acp/discord_notifications_module.php +++ b/acp/discord_notifications_module.php @@ -100,6 +100,7 @@ public function main($id, $mode) $this->template->assign_vars(array( 'DN_MASTER_ENABLE' => $this->config['discord_notifications_enabled'], 'DN_POST_PREVIEW_LENGTH' => $this->config['discord_notifications_post_preview_length'], + 'DN_DEFAULT_LANG' => $this->config['discord_notifications_default_lang'], 'DN_TEST_MESSAGE_TEXT' => $this->language->lang('DN_TEST_MESSAGE_TEXT'), 'DN_CONNECT_TIMEOUT' => $this->config['discord_notifications_connect_timeout'], 'DN_EXEC_TIMEOUT' => $this->config['discord_notifications_exec_timeout'], @@ -278,6 +279,7 @@ private function process_form_submit() $this->config->set('discord_notifications_connect_timeout', $connect_timeout); $this->config->set('discord_notifications_exec_timeout', $exec_timeout); + $this->config->set('discord_notifications_default_lang', $this->request->variable('dn_default_lang', '')); $this->config->set('discord_notification_type_post_create', $this->request->variable('dn_post_create', 0)); $this->config->set('discord_notification_type_post_update', $this->request->variable('dn_post_update', 0)); $this->config->set('discord_notification_type_post_delete', $this->request->variable('dn_post_delete', 0)); diff --git a/adm/style/acp_discord_notifications.html b/adm/style/acp_discord_notifications.html index feeb7aa..885c142 100644 --- a/adm/style/acp_discord_notifications.html +++ b/adm/style/acp_discord_notifications.html @@ -19,6 +19,12 @@

{{ lang('ACP_DISCORD_NOTIFICATIONS') }}

+
+

{{ lang('DN_DEFAULT_LANG_DESCRIPTION') }}
+
+ +
+

{{ lang('DN_CONNECT_TO_DESCRIPTION') }}
diff --git a/event/notification_event_listener.php b/event/notification_event_listener.php index 9cbcb1b..2f34052 100644 --- a/event/notification_event_listener.php +++ b/event/notification_event_listener.php @@ -65,7 +65,17 @@ public function __construct( $this->php_ext = $php_ext; // Add notifications text from the langauge file + $lang = $notification_service->get_language(); + if (!empty($lang)) + { + $user_language = $this->language->get_used_language(); + $this->language->set_user_language($lang); + } $this->language->add_lang('discord_notification_messages', 'mober/discordnotifications'); + if (!empty($lang)) + { + $this->language->set_user_language($user_language); + } } /** diff --git a/migrations/add_language_config.php b/migrations/add_language_config.php new file mode 100644 index 0000000..43c0c2f --- /dev/null +++ b/migrations/add_language_config.php @@ -0,0 +1,29 @@ +config['discord_notifications_default_lang']); + } + + public function update_data() + { + return array( + array('config.add', array('discord_notifications_default_lang', '')) + ); + } +} diff --git a/notification_service.php b/notification_service.php index 9c2c7d1..b184779 100644 --- a/notification_service.php +++ b/notification_service.php @@ -60,6 +60,15 @@ public function is_notification_type_enabled($notification_type) return $this->config['discord_notifications_enabled'] == 1 && $this->config[$notification_type] == 1; } + public function get_language() + { + if (isset($this->config['discord_notifications_default_lang'])) + { + return $this->config['discord_notifications_default_lang']; + } + return ''; + } + /** * Check whether notifications that occur on a specific forum should be generated *