public function FeatureContext::addTranslation in Open Social 8.4
Same name and namespace in other branches
- 8.9 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::addTranslation()
- 8.3 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::addTranslation()
- 8.5 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::addTranslation()
- 8.6 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::addTranslation()
- 8.7 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::addTranslation()
- 8.8 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::addTranslation()
- 10.3.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::addTranslation()
- 10.0.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::addTranslation()
- 10.1.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::addTranslation()
- 10.2.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\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 896
Class
- FeatureContext
- Defines application features from the specific context.
Namespace
Drupal\social\BehatCode
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;
}