Title: How to translate strings programatically
Last modified: December 29, 2023

---

# How to translate strings programatically

 *  Resolved [asfo](https://wordpress.org/support/users/asfo/)
 * (@asfo)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/how-to-translate-strings-programatically/)
 * Hello Team,
 * I’m writting a custom theme for a client and I’m using TranslatePress for translations,
   but they have a custom role for handling specific things (this is a menu for 
   restaurants, so they have roles for editing the specific branch menu) but right
   now they want to translate on the branch the menus so they don’t need an admin,
   I know this plugin has the “premium version” which allow us to show the “Translation
   Editor” on custom roles, but we DON’T want to show the editor, ONLY specific 
   things.
 * For example, we have a Burguer, so in Spanish it’s:
 * “Hamburguesa” they want to translate it manually to “Burguer” if there are no
   translations already.
 * I know already that we have the `trp_translate` function to show a string translated
   like “Bebidas” which was already translated to “Drinks”, so that works to print
   the current translations, but I want to do something like: `translate_string(
   $original, $translation)` so it’s saved and on the pages, it start to show, we
   only want to translate 2 things, and not show anything that the branch managers
   to know that we’re using WordPress
 * Is that possible? or do I need the premium version or how I can achieve that?…
 * I already tried the `query` component with `insert` and `update` functions, but
   don’t work, and the `process_strings` needs an already translated string, so 
   I’m not sure if this is even possible… so I hope it is and I’m not watching something.
   If I need to buy the premium version, please let me know with the attached source
   that I need to use for this specific code.
 * Thanks in advance!

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

 *  Thread Starter [asfo](https://wordpress.org/support/users/asfo/)
 * (@asfo)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/how-to-translate-strings-programatically/#post-17326164)
 * Any help here?
 *  [Andrei](https://wordpress.org/support/users/andrei202/)
 * (@andrei202)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/how-to-translate-strings-programatically/#post-17331285)
 * Hello,
   ​I appreciate you reaching out to us!​​Unfortunately the trp_translate
   function returns the translated strings but it does not save them. ​For saving
   and using the manual translations, I would suggest making use of the gettext 
   function along with WordPress hooks. They will allow you to translate strings
   programmatically in an efficient way.​Please refer to this link for more information
   and usage of gettext: [https://developer.wordpress.org/reference/hooks/gettext/](https://developer.wordpress.org/reference/hooks/gettext/)​
   I hope this helps in achieving the functionality you need for your custom theme.
   If you have any more questions or need further clarification, please, do not 
   hesitate to let us know.​Best regards,
 *  Thread Starter [asfo](https://wordpress.org/support/users/asfo/)
 * (@asfo)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/how-to-translate-strings-programatically/#post-17332722)
 * Thanks [@andrei202](https://wordpress.org/support/users/andrei202/) for your 
   answer but that’s not what I’m looking for. The page is being translated in general
   by “TranslatePress”, because there is a guy using the UI to translate everything,
   but we have, like said, an special page just for “Chefs” (or a “manager”) who
   can create new items to add to the menu, so they don’t have any “admin access”
   but I don’t want them to see the “TranslatePress” UI, just the page where they
   can translate the item.
 * Maybe if there is no code for translate programatically using TranslatePress 
   even in the premium plugin, is there an option to understand how the tables works?
   if I’m not wrong TranslatePress use the database to save the translations, so
   maybe, if you can share me how to achieve it by using the database, I could do
   it by running direct queries to the tables that I need and that should do the
   trick?
 * Regards.
 *  Thread Starter [asfo](https://wordpress.org/support/users/asfo/)
 * (@asfo)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/how-to-translate-strings-programatically/#post-17388852)
 * Up
 *  Plugin Support [Alex](https://wordpress.org/support/users/alexcozmoslabs/)
 * (@alexcozmoslabs)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/how-to-translate-strings-programatically/#post-17538060)
 * We need to take the pulse of this ticket. Is it still relevant?
   In the meantime,
   I set this ticket as Resolved. You can also change its status back to unresolved
   and let us know by replying to this topic if your request still needs attention.
   However, we encourage you to leave this ticket as it is and open a new one where
   to mention the issue again and ask for support. You can mention the link to this
   thread in the new ticket.
 *  Thread Starter [asfo](https://wordpress.org/support/users/asfo/)
 * (@asfo)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/how-to-translate-strings-programatically/#post-17538129)
 * It’s still relevant.
   As you can see I didn’t receive any further comment, so 
   I was just waiting… but still relevant.
 *  [Andreas Socratous](https://wordpress.org/support/users/shipettos/)
 * (@shipettos)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/how-to-translate-strings-programatically/#post-18005225)
 * such functionality it would be great if added for devs. I am looking for the 
   same solution as [@asfo](https://wordpress.org/support/users/asfo/)
 *  [Bernardo de Oliveira](https://wordpress.org/support/users/bernardo31p/)
 * (@bernardo31p)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/how-to-translate-strings-programatically/#post-18039537)
 * I’ve developed a lightweight Translation Class to integrate with TranslatePress
   and other translation plugins for use with our proprietary plugin. **Note:** 
   This solution is not recommended for production use, as any updates to TranslatePress
   or other plugins could potentially break the functionality. The class works by
   directly manipulating the database, which increases the risk of compatibility
   issues.
 * Here’s a snippet of the code:
   [https://pastebin.com/raw/5dYtVcW4](https://pastebin.com/raw/5dYtVcW4)
   I hope this helps
    -  This reply was modified 1 year, 8 months ago by [Bernardo de Oliveira](https://wordpress.org/support/users/bernardo31p/).

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

The topic ‘How to translate strings programatically’ 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/)

 * 8 replies
 * 5 participants
 * Last reply from: [Bernardo de Oliveira](https://wordpress.org/support/users/bernardo31p/)
 * Last activity: [1 year, 8 months ago](https://wordpress.org/support/topic/how-to-translate-strings-programatically/#post-18039537)
 * Status: resolved