// Load the translation service $translation = \Drupal::service('string_translation'); // Translate a string $translated_string = $translation->translate('Hello world!');
// Load the node object $node = \Drupal::entityTypeManager()->getStorage('node')->load(123); // Translate the node title $translated_title = $node->getTranslation('fr')->getTitle();
// Load the translation management service $translation_management = \Drupal::service('translation.management'); // Create a job for translating content from English to French $job = $translation_management->createJob('en', 'fr'); // Assign content to the job $job->addContent(\Drupal::entityTypeManager()->getStorage('node')->loadMultiple([1, 2, 3])); // Save the job $job->save();Package library: Drupal\content_translation\TranslationManagement\TranslationManagementService Overall, PHP Drupal Translation is a powerful tool for creating multilingual Drupal websites. It offers a wide range of features for managing translations, and its APIs are well-documented and easy to use.