Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8030697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:51:09+00:00 2026-06-05T00:51:09+00:00

I need to programmatically add string translation (for example to translate taxonomy terms). Is

  • 0

I need to programmatically add string translation (for example to translate taxonomy terms). Is there some function like add_translation($my_term_name, $language, $translation)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:51:10+00:00Added an answer on June 5, 2026 at 12:51 am

    Unfortunately, there is no nice function in core. You can check how the locale menu does it by directly writing to the database:

    function locale_translate_edit_form_submit($form, &$form_state) {
      $lid = $form_state['values']['lid'];
      foreach ($form_state['values']['translations'] as $key => $value) {
        $translation = db_result(db_query("SELECT translation FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $key));
        if (!empty($value)) {
          // Only update or insert if we have a value to use.
          if (!empty($translation)) {
            db_query("UPDATE {locales_target} SET translation = '%s' WHERE lid = %d AND language = '%s'", $value, $lid, $key);
          }
          else {
            db_query("INSERT INTO {locales_target} (lid, translation, language) VALUES (%d, '%s', '%s')", $lid, $value, $key);
          }
        }
        elseif (!empty($translation)) {
          // Empty translation entered: remove existing entry from database.
          db_query("DELETE FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $key);
        }
    
        // Force JavaScript translation file recreation for this language.
        _locale_invalidate_js($key);
      }
    
      drupal_set_message(t('The string has been saved.'));
    
      // Clear locale cache.
      _locale_invalidate_js();
      cache_clear_all('locale:', 'cache', TRUE);
    
      $form_state['redirect'] = 'admin/build/translate/search';
      return;
    }
    

    Don’t forget validation if your text comes from an untrusted source (such as user input).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to programmatically add a set of controls with some amount of pixels
I temporarly added some values to the UITableViewCell programmatically. But I need to add
I have a RichTextBox and I add some texts programatically. I need to display
I have a User Control that I need to programmatically add to a Silverlight
I'd like to set a connection string programmatically, with absolutely no change to any
I'd like to be able to add a character to a TextInput programmatically (say
I have some code to create a Virtual Directory programmatically. I need to edit
Is possible in Android to findView by String Id? I add some rows in
I am adding a UIView programmatically to superview, and i would like to add
I need to programmatically force a (WP7 toolkit) ListPicker to show its list in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.