mirror of
				https://github.com/Mibew/i18n.git
				synced 2025-11-01 01:36:57 +03:00 
			
		
		
		
	Add ability for client-side plugins to use own locale strings
This commit is contained in:
		
							parent
							
								
									438824fa36
								
							
						
					
					
						commit
						5798c2399d
					
				| @ -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) | ||||
| 	); | ||||
| } | ||||
|  | ||||
| @ -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(); | ||||
|  | ||||
| @ -31,6 +31,7 @@ | ||||
| 
 | ||||
|         ${page:additional_js} | ||||
|         <script type="text/javascript"><!-- | ||||
|             // Localized strings for the core | ||||
|             Mibew.Localization.set({ | ||||
|                 'chat.close.confirmation': ${msgjs:chat.close.confirmation}, | ||||
|                 'typing.remote': ${msgjs:typing.remote}, | ||||
| @ -70,6 +71,8 @@ | ||||
|                 'presurvey.title': ${msgjs:presurvey.title}, | ||||
|                 'presurvey.intro': ${msgjs:presurvey.intro} | ||||
|             }); | ||||
|             // Plugins localization | ||||
|             Mibew.Localization.set(${page:additional_localized_strings}); | ||||
|         //--></script> | ||||
| 
 | ||||
|         <!-- Run application --> | ||||
|  | ||||
| @ -46,6 +46,7 @@ function tpl_header() { global $page, $webimroot; | ||||
| 
 | ||||
| <!-- Localization constants --> | ||||
| <script type="text/javascript"><!-- | ||||
| 	// Localized strings for the core
 | ||||
| 	Mibew.Localization.set({ | ||||
| 		'pending.table.speak': "<?php echo getlocal('pending.table.speak') ?>", | ||||
| 		'pending.table.view': "<?php echo getlocal('pending.table.view') ?>", | ||||
| @ -86,6 +87,8 @@ function tpl_header() { global $page, $webimroot; | ||||
| 		'chat.client.spam.prefix': "<?php echo getstring('chat.client.spam.prefix'); ?>", | ||||
| 		'pending.errors.network': "<?php echo getlocal('pending.errors.network'); ?>" | ||||
| 	}); | ||||
| 	// Plugins localization
 | ||||
| 	Mibew.Localization.set(<?php echo $page['additional_localized_strings']; ?>);
 | ||||
| //--></script>
 | ||||
| 
 | ||||
| <script type="text/javascript"><!-- | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user