Title: Function &#8211; string translation
Last modified: April 7, 2017

---

# Function – string translation

 *  [mathew07](https://wordpress.org/support/users/mathew07/)
 * (@mathew07)
 * [9 years ago](https://wordpress.org/support/topic/function-string-translaton/)
 * Hey,
 * first of all – thank you for this awesome plugin 🙂
 * I have some issue with translating my page. I can’t translate some strings (ex.
   text on buttons). I tried to register those strings with function and then translate
   them but nothing happened. Next I try to translate them in .po file but again–
   nothing happened.
 * Finally, I used this function to get those text translated:
 *     ```
       function change_translate_text( $translated_text ) {
       	if ( $translated_text == 'View' ) {
       	$translated_text = 'new text';
       	}
       	return $translated_text;
       }
       add_filter( 'gettext', 'change_translate_text', 20 );
       ```
   
 * Unfortunatelly, I have 3 languages on my site and I need some help with this 
   code – it should detect user language and then display correct translation. I
   was trying to add:
 *     ```
       $curlang = pll_current_language();
       if ($curlang=='ru')
       ```
   
 * but this also didn’t work.
    -  This topic was modified 9 years ago by [mathew07](https://wordpress.org/support/users/mathew07/).

Viewing 1 replies (of 1 total)

 *  Thread Starter [mathew07](https://wordpress.org/support/users/mathew07/)
 * (@mathew07)
 * [9 years ago](https://wordpress.org/support/topic/function-string-translaton/#post-9014932)
 * Hello again,
 * I couldn’t edit previous post so I had to post new one.
 * I edit my code and now it looks like this:
 *     ```
       add_filter('gettext', 'translate_text3');
       add_filter('ngettext', 'translate_text3');
       function translate_text3($translated) {
       		if ( pll_current_language() == 'ru' ) {
       			$translated = str_ireplace('View Cart', 'ten', $translated);   
       	}
       		else { 
       			$translated = str_ireplace('View Cart', 'inny', $translated);
       	}
       return $translated;
       }
       ```
   
 * but stil no luck. It seems that parameter pll_current_language is not working
   at all. Any help with that will be appreciated 🙂
 * BR, Mat

Viewing 1 replies (of 1 total)

The topic ‘Function – string translation’ is closed to new replies.

 * ![](https://ps.w.org/polylang/assets/icon-256x256.png?rev=3433336)
 * [Polylang](https://wordpress.org/plugins/polylang/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/polylang/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/polylang/)
 * [Active Topics](https://wordpress.org/support/plugin/polylang/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/polylang/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/polylang/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [mathew07](https://wordpress.org/support/users/mathew07/)
 * Last activity: [9 years ago](https://wordpress.org/support/topic/function-string-translaton/#post-9014932)
 * Status: not resolved