I have used t() to translate a string value. To translate it from the user interface, I first need to view the page on which this string is displayed in a different language. Only then, the string is added to the translate interface.

I want to be able to translate the string before doing that. Can I programmatically add the string to the translation interface?


Assuming that your question is in regard to translating a (custom) module or theme. In that case, I'm using the Translation template extractor to get all strings of a module/theme that are used in the t() functions. For more information about using this module, look at this discussion. Though a pretty old discussion, it's still very useful.


For a quick solution, add something like this to a custom module:

 * Implements hook_flush_caches().
 * Using this as a way to get certain phrases into the t() workflow, that don't
 * seem to otherwise make it. To get these items to show up in the Translate
 * interface, go to a different language and in the Drupal admin clear the
 * Drupal cache. (ie, at /admin/config/development/performance
function mymodule_flush_caches() {


you can write custom code for that like this function

//$sourse :- string for en language or default language 
//$translation :- string you want to add in other language translation
//$langcode :- language code in which you translate string

function addInManually($source, $translation, $langcode){
  $report = array(
  ); // ??
  $source = $source;
  $translation = $translation;
  $textgroup = 'default'; // field , node, default, menu ...
  $langcode = $langcode; // 'en', 'de'
  $location = ''; //  'menu:menu:management:title', '/node/3', ...
  $context = '';
  _locale_import_one_string_db($report, $langcode, $context, $source, $translation, $textgroup, $location, $mode);

  // Clear locale cache.
  cache_clear_all('locale:', 'cache', TRUE);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.