Title: Function Call by Reference
Last modified: September 5, 2016

---

# Function Call by Reference

 *  [revigbreizh](https://wordpress.org/support/users/revigbreizh/)
 * (@revigbreizh)
 * [10 years ago](https://wordpress.org/support/topic/function-call-by-reference/)
 * Hi everybody,
 * I am using the following code in a plugin in order to change some specific translated
   strings for a plugin and for my theme. (I could change the translations itself
   into the .po .mo files, but I would have to do it after each update of the plugin
   or of the theme. Including this code in a separate plugin avoids these updates.)
 *     ```
       register_activation_hook( __FILE__, 'Corrections_install' );
       function Corrections_install() {
       	global $wp_version;
       	if (version_compare($wp_version, '4.1', '<' )) wp_die( 'This plugin requires WordPress version 4.1 or higher.' );
       };
   
       /*
        * Filter the translation string before it is displayed.
        *
        * @param $translation The current translation
        * @param $text        The text to translate
        * @param $domain      The domain for the translation
        * @return string      The translated / filtered text.
        */
        function filter_gettext($translation, $text, $domain) {
       	$translations = &get_translations_for_domain($domain);
   
       	/* Menus de langues et de pages sur les appareils mobiles */
   
       	if ($domain == 'catch-box') {
   
       		/* Menu de gauche (les langues) */
   
       		if (($text == 'Menu') && (function_exists('pll_current_language'))) {
       			switch (pll_current_language()) {
       				case 'en': return $translations->translate('Languages');
       				case 'fr': return $translations->translate('Langues');
       				case 'ar': return $translations->translate('اللغات');
       			};
       		};
   
       		/* Menu de droite (les pages) */
   
       		if ($text == 'Secondary Menu') return $translations->translate('&nbsp;');
       	};
   
       	/* Typos dans les messages du widget calendrier */
   
       	if (($domain == 'google-calendar-events') && ($text == 'Nothing from %1$s to %2$s.')) {
       		switch ($translation) {
       			case 'Rien de %1$s à %2$s.': return $translations->translate('Rien du %1$s au %2$s.');
       			case 'لا شيئ من %1$s إلى %2$s.': return $translations->translate('لا شيء من %1$s إلى %2$s.');
       		};
       	};
       	return $translation;
       };
       add_filter('gettext', 'filter_gettext', 10, 3);
       ```
   
 * It works perfectly, but I am using **$translations = &get_translations_for_domain(
   $domain);**, which seems not to be strongly recommanded.
 * What do you think? Should I change my code? And how?
 * Thanks!
 * Rémi

 The topic ‘Function Call by Reference’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [revigbreizh](https://wordpress.org/support/users/revigbreizh/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/function-call-by-reference/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
