You are here

function tmgmt_translator_auto_create in Translation Management Tool 8

Same name and namespace in other branches
  1. 7 tmgmt.module \tmgmt_translator_auto_create()

Auto creates a translator from a translator plugin definition.

Parameters

array $definition: The definition of a translator plugin.

Related topics

4 calls to tmgmt_translator_auto_create()
ConfigSourceUnitTest::setUp in sources/tmgmt_config/tests/src/Kernel/ConfigSourceUnitTest.php
ConfigSourceWebformTest::setUp in sources/tmgmt_config/tests/src/Kernel/ConfigSourceWebformTest.php
ContentEntityTestBase::setUp in sources/content/tests/src/Kernel/ContentEntityTestBase.php
tmgmt_modules_installed in ./tmgmt.module
Implements hook_modules_installed().

File

./tmgmt.module, line 475
Main module file for the Translation Management module.

Code

function tmgmt_translator_auto_create(array $definition) {
  $plugin = $definition['id'];
  if (!Translator::load($plugin)) {
    $translator = Translator::create([
      'name' => $plugin,
      'plugin' => $plugin,
      'remote_languages_mappings' => array(),
      'label' => $definition['label'],
      'description' => (string) $definition['description'],
    ]);

    // Append default settings from the translator plugin definition.
    $translator
      ->setSettings($translator
      ->getPlugin()
      ->defaultSettings());
    $translator
      ->save();
  }
}