String Translation hinzufügen oder ändern
Mit dem folgenden Helper Script, kann eine bestehende String Translation – z.B. t('Mein String')
– bearbeitet oder eine neue hinzugefügt werden.
/** * Helper to manually add or update a single translation string. * * @param $langcode * The langcode of the target language (e.g. 'de'). * @param $source * Source string. * @param $translation * Translation string to language specified in $langcode. * @param $context * The context of the string. Default ''. * @param $textgroup * Name of the textgroup to store translation in. Default 'default'. */ function _locale_add_translation($langcode, $source, $translation, $context = '', $textgroup = 'default') { require_once DRUPAL_ROOT . '/includes/locale.inc'; $report = &drupal_static(__FUNCTION__, array('additions' => 0, 'updates' => 0, 'deletes' => 0, 'skips' => 0)); _locale_import_one_string_db($report, $langcode, $context, $source, $translation, $textgroup, 'Manual import via helper ' . __FUNCTION__ .'().', LOCALE_IMPORT_OVERWRITE); // Clear locale cache. _locale_invalidate_js(); cache_clear_all('locale:', 'cache', TRUE); }
Am Besten macht sich die Funktion bzw. dessen Verwendung in einer Update Funktion via hook_update_N()
.
/** * Change the "Mein String" string. */ function my_module_update_7101() { _locale_add_translation('de', 'Mein String', 'Meine Übersetung des Strings'); }
Quelle: dropbucket
🔗 Links zu dieser Seite