Manually add string translations

Public

</> CopyGet raw version
php
  1. /**
  2.  * Helper to manually add a single translation string.
  3.  *
  4.  * After adding strings use locale_clear_cache() for clearing caches.
  5.  */
  6. function locale_add_translation($source, $langcode, $translation, $context = '', $textgroup = 'default') {
  7. require_once DRUPAL_ROOT . '/includes/locale.inc';
  8.  
  9. $report = &drupal_static(__FUNCTION__, array('additions' => 0, 'updates' => 0, 'deletes' => 0, 'skips' => 0));
  10. _locale_import_one_string_db($report, $langcode, $context, $source, $translation, $textgroup, 'Manual import via helper ' . __FUNCTION__ .'().', LOCALE_IMPORT_OVERWRITE);
  11. }
  12.  
  13. /**
  14.  * Helper to clear the locale cache.
  15.  */
  16. function locale_clear_cache() {
  17. require_once DRUPAL_ROOT . '/includes/locale.inc';
  18. // Clear locale cache.
  19. _locale_invalidate_js();
  20. cache_clear_all('locale:', 'cache', TRUE);
  21. }

Comments

mattew's picture

Note that _locale_import_one_string_db() will skip if the translation contains accentuated characters (it considers this string as non-safe).