From 5798c2399d25bb85338db09a031a7c4c4c2491cd Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 11 Apr 2013 10:04:19 +0000 Subject: [PATCH] Add ability for client-side plugins to use own locale strings --- src/messenger/webim/libs/common/response.php | 34 +++++++++++++++++++ src/messenger/webim/operator/users.php | 6 ++-- .../styles/dialogs/default/templates/chat.tpl | 3 ++ src/messenger/webim/view/pending_users.php | 3 ++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/messenger/webim/libs/common/response.php b/src/messenger/webim/libs/common/response.php index 1db5f363..e77917e2 100644 --- a/src/messenger/webim/libs/common/response.php +++ b/src/messenger/webim/libs/common/response.php @@ -130,6 +130,37 @@ function get_additional_js($page_name) { return implode("\n", $result); } +/** + * Add additional localized strings for JavaScript application + * + * Triggers 'pageAddLocalizedStrings' and pass listeners associative array with + * following keys: + * - 'page': string, name of page to which localized strings will be added. + * - 'localized_strings': associative array with localized strings. + * + * @param string $page_name Localized strings add to this page + * @return string JSON encoded localized strings + */ +function get_additional_localized_strings($page_name) { + // Prepare event arguments array + $args = array( + 'page' => $page_name, + 'localized_strings' => array() + ); + + // Trigger event + $dispatcher = EventDispatcher::getInstance(); + $dispatcher->triggerEvent('pageAddLocalizedStrings', $args); + + // Build result + $result = array(); + if (! empty($args['localized_strings']) + && is_array($args['localized_strings'])) { + $result = $args['localized_strings']; + } + + return json_encode($result); +} /** * Build Javascript code that contains initializing options for JavaScript @@ -166,6 +197,8 @@ function get_js_plugin_options($page_name) { * @return array Associative array of plugins data. It contains following keys: * - 'additional_css': contains results of the 'get_additional_css function * - 'additional_js': contains results of the 'get_additional_js' function + * - 'additional_localized_strings': contains results of the + * 'get_additional_localized_strings' function * - 'js_plugin_options': contains results of the 'get_js_plugin_options' * function */ @@ -173,6 +206,7 @@ function get_plugins_data($page_name) { return array( 'additional_css' => get_additional_css($page_name), 'additional_js' => get_additional_js($page_name), + 'additional_localized_strings' => get_additional_localized_strings($page_name), 'js_plugin_options' => get_js_plugin_options($page_name) ); } diff --git a/src/messenger/webim/operator/users.php b/src/messenger/webim/operator/users.php index b119150c..8e5e44a9 100644 --- a/src/messenger/webim/operator/users.php +++ b/src/messenger/webim/operator/users.php @@ -52,10 +52,8 @@ $page['coreStyles.trackedVisitorWindowParams'] = $style_config['tracked']['visit $page['coreStyles.inviteWindowParams'] = $style_config['invitation']['window_params']; $page['coreStyles.banWindowParams'] = $style_config['ban']['window_params']; -// Get additional files -$page['additional_css'] = get_additional_css('users'); -$page['additional_js'] = get_additional_js('users'); -$page['js_plugin_options'] = get_js_plugin_options('users'); +// Get additional plugins data +$page = array_merge($page, get_plugins_data('users')); prepare_menu($operator); start_html_output(); diff --git a/src/messenger/webim/styles/dialogs/default/templates/chat.tpl b/src/messenger/webim/styles/dialogs/default/templates/chat.tpl index 0918e87d..55f64a69 100644 --- a/src/messenger/webim/styles/dialogs/default/templates/chat.tpl +++ b/src/messenger/webim/styles/dialogs/default/templates/chat.tpl @@ -31,6 +31,7 @@ ${page:additional_js} diff --git a/src/messenger/webim/view/pending_users.php b/src/messenger/webim/view/pending_users.php index e8b2eb6a..c317101a 100644 --- a/src/messenger/webim/view/pending_users.php +++ b/src/messenger/webim/view/pending_users.php @@ -46,6 +46,7 @@ function tpl_header() { global $page, $webimroot;