How to manually add a string to Drupal's Translate Interface?

by kmdhrm   Last Updated January 11, 2018 13:07 PM

I have used t() function to output a string value so it can be viewed in multiple languages.

However to translate them using Drupal's translate interface, first I 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 Drupal's translate interface?

Tags : i18n-l10n

Answers 3

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.

July 01, 2014 23:20 PM

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() {

Brock Fanning
Brock Fanning
January 01, 2015 18:21 PM

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);
January 11, 2018 13:02 PM

Related Questions

Keep node/user tabs in one language

Updated May 16, 2016 08:03 AM

How do I include a custom module translation?

Updated June 28, 2016 08:03 AM

Adding an existing node as a translation

Updated August 09, 2016 08:03 AM

Drupal 8: make Taxonomy terms translatable

Updated August 16, 2016 08:04 AM

How to show 404 page for nodes without translation?

Updated September 01, 2016 08:04 AM