Title: Get translated string
Last modified: June 2, 2020

---

# Get translated string

 *  Resolved [tlouwet](https://wordpress.org/support/users/tlouwet/)
 * (@tlouwet)
 * [6 years ago](https://wordpress.org/support/topic/get-translated-string/)
 * Probably a weird question,
 * I’m busy with an image generator, and it requests the title of the page, but 
   I would need it in multiple languages.
 * is there a way to get the translation of a string within php, without going to
   that language?
    For example `trp('nl_nl','string');`
 * Went through the documentation but couldn’t find any mention of it.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [robert7k](https://wordpress.org/support/users/robert7k/)
 * (@robert7k)
 * [5 years, 12 months ago](https://wordpress.org/support/topic/get-translated-string/#post-12961630)
 * This hack kind-of works for me:
 *     ```
       if ( class_exists( 'TRP_Translate_Press' ) ){
       $target_language = get_locale();
       $translator = TRP_Translate_Press::get_trp_instance()->get_component('translation_render');
       $translation = $translator->process_strings(array($original_name),target_language);
       if ($translation) $new_name = $translation[0];}
       ```
   
 * But be warned – this hack isn’t stable – you should filter your input – bad input
   can cause exceptions or even sql injection vulnerabilities (the target language
   must exist in your translatepress and can’t be the default language). It also
   may slow down your site (i didn’t test the preformance of this ugly hack)
 * i’m waiting for a reply too (hopefully to get better code).
    -  This reply was modified 5 years, 12 months ago by [robert7k](https://wordpress.org/support/users/robert7k/).
    -  This reply was modified 5 years, 12 months ago by [robert7k](https://wordpress.org/support/users/robert7k/).
    -  This reply was modified 5 years, 12 months ago by [robert7k](https://wordpress.org/support/users/robert7k/).
 *  Thread Starter [tlouwet](https://wordpress.org/support/users/tlouwet/)
 * (@tlouwet)
 * [5 years, 12 months ago](https://wordpress.org/support/topic/get-translated-string/#post-12965907)
 * Really nice find [@robert7k](https://wordpress.org/support/users/robert7k/)
 * It does the trick.
    (for my use I did change get_locale() to an array and cycled
   it)
 * Small note, ‘target_language’ doesn’t have a $ under $translation in your posted
   code. But I assume that’s just an example error.
 * Sadly I’m not that knowledgeable when it comes to sql injections.
    I guess you
   mean that I should protect/sanatize the $original_name? I’m pulling the page 
   id from a GET[] > sanatize it > get_the_title(). Should be sufficient?
 * And I appreciate the help.
 *  [robert7k](https://wordpress.org/support/users/robert7k/)
 * (@robert7k)
 * [5 years, 12 months ago](https://wordpress.org/support/topic/get-translated-string/#post-12966018)
 * no idea about security.
    Yes, it was a typo. this is a part of the code i currently
   use:
 *     ```
       $trp_instance = TRP_Translate_Press::get_trp_instance();
       $translator = $trp_instance->get_component('translation_render');
       $translator_original_language = $trp_instance->get_component('settings')->get_setting('default-language');
       if (get_locale()!==$translator_original_language) {
       		$translation = $translator->process_strings(array($original_name),get_locale());
       		if ($translation) $new_name = $translation[0];
       }
       ```
   
 * after experimenting with this kind of code just open the translatepress settings
   to make sure no scary errors show up (wrong code got me errors about missing 
   sql tables!!!)
    -  This reply was modified 5 years, 12 months ago by [robert7k](https://wordpress.org/support/users/robert7k/).
 *  Thread Starter [tlouwet](https://wordpress.org/support/users/tlouwet/)
 * (@tlouwet)
 * [5 years, 12 months ago](https://wordpress.org/support/topic/get-translated-string/#post-12966101)
 * [@robert7k](https://wordpress.org/support/users/robert7k/) and thanks for the
   lead.
 * Noticed the function was getting it’s query from class-query.php,
    wherein function**
   process_strings** pretty much does what process_strings does. Though that function
   does sort of note where the translations were kept.
 * `$title_fr = $wpdb->get_row("SELECT * from wpvk_trp_dictionary_nl_nl_fr_fr WHERE
   original = '{$original_name}'")->translated;`
    gives me the french translation
   of $original_name (does require ‘global $wpdb;’)
 * Table name will probably be different for you, which you could find in your sql.
   
   For me (mostlikely for you too), is a table with column names: id, original, 
   translated, status, block_type, original_id.
 * Will probably do it that way as for what I’m working on it already uses $wpdb.
    -  This reply was modified 5 years, 12 months ago by [tlouwet](https://wordpress.org/support/users/tlouwet/).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Get translated string’ is closed to new replies.

 * ![](https://ps.w.org/translatepress-multilingual/assets/icon.svg?rev=3166541)
 * [TranslatePress - Translate Multilingual sites with AI Translation](https://wordpress.org/plugins/translatepress-multilingual/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/translatepress-multilingual/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/translatepress-multilingual/)
 * [Active Topics](https://wordpress.org/support/plugin/translatepress-multilingual/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/translatepress-multilingual/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/translatepress-multilingual/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [tlouwet](https://wordpress.org/support/users/tlouwet/)
 * Last activity: [5 years, 12 months ago](https://wordpress.org/support/topic/get-translated-string/#post-12966101)
 * Status: resolved