public function FeatureContext::addTranslation in Open Social 8
Same name and namespace in other branches
- 8.2 tests/behat/features/bootstrap/FeatureContext.php \FeatureContext::addTranslation()
Helper function to add translation.
Parameters
$source_string:
$translated_string:
$langcode:
1 call to FeatureContext::addTranslation()
- FeatureContext::iTranslate in tests/
behat/ features/ bootstrap/ FeatureContext.php - Translate a string.
File
- tests/
behat/ features/ bootstrap/ FeatureContext.php, line 841
Class
- FeatureContext
- Defines application features from the specific context.
Code
public function addTranslation($source_string, $translated_string, $langcode) {
// Find existing source string.
$storage = \Drupal::service('locale.storage');
$string = $storage
->findString(array(
'source' => $source_string,
));
if (is_null($string)) {
$string = new SourceString();
$string
->setString($source_string);
$string
->setStorage($storage);
$string
->save();
}
// Create translation. If one already exists, it will be replaced.
$translation = $storage
->createTranslation(array(
'lid' => $string->lid,
'language' => $langcode,
'translation' => $translated_string,
))
->save();
return $translation;
}