class FileTranslator in Translation Management Tool 8
File translator.
Plugin annotation
@TranslatorPlugin(
id = "file",
label = @Translation("File exchange"),
description = @Translation("Provider to export and import files."),
ui = "Drupal\tmgmt_file\FileTranslatorUi"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\tmgmt\TranslatorPluginBase implements TranslatorPluginInterface
- class \Drupal\tmgmt_file\Plugin\tmgmt\Translator\FileTranslator
- class \Drupal\tmgmt\TranslatorPluginBase implements TranslatorPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of FileTranslator
File
- translators/
tmgmt_file/ src/ Plugin/ tmgmt/ Translator/ FileTranslator.php, line 21
Namespace
Drupal\tmgmt_file\Plugin\tmgmt\TranslatorView source
class FileTranslator extends TranslatorPluginBase {
/**
* {@inheritdoc}
*/
public function checkTranslatable(TranslatorInterface $translator, JobInterface $job) {
// Anything can be exported.
return TranslatableResult::yes();
}
/**
* {@inheritdoc}
*/
public function requestTranslation(JobInterface $job) {
$name = "JobID" . $job
->id() . '_' . $job
->getSourceLangcode() . '_' . $job
->getTargetLangcode();
$export = \Drupal::service('plugin.manager.tmgmt_file.format')
->createInstance($job
->getSetting('export_format'), $job
->getSetting('format_configuration'));
$path = $job
->getSetting('scheme') . '://tmgmt_file/' . $name . '.' . $job
->getSetting('export_format');
$dirname = dirname($path);
if (\Drupal::service('file_system')
->prepareDirectory($dirname, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
$file = file_save_data($export
->export($job), $path, FileSystemInterface::EXISTS_REPLACE);
\Drupal::service('file.usage')
->add($file, 'tmgmt_file', 'tmgmt_job', $job
->id());
$job
->submitted('Exported file can be downloaded <a href="@link" download>here</a>.', array(
'@link' => file_create_url($path),
));
}
else {
$job
->rejected('Failed to create writable directory @dirname, check file system permissions.', [
'@dirname' => $dirname,
]);
}
}
/**
* {@inheritdoc}
*/
public function hasCheckoutSettings(JobInterface $job) {
return $job
->getTranslator()
->getSetting('allow_override');
}
/**
* {@inheritdoc}
*/
public function defaultSettings() {
return array(
'export_format' => 'xlf',
'allow_override' => TRUE,
'scheme' => 'public',
// Making this setting TRUE by default is more appropriate, however we
// need to make it FALSE due to backwards compatibility.
'xliff_processing' => FALSE,
'xliff_cdata' => FALSE,
'format_configuration' => [],
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FileTranslator:: |
public | function |
Check whether this service can handle a particular translation job. Overrides TranslatorPluginBase:: |
|
FileTranslator:: |
public | function |
Defines default settings. Overrides TranslatorPluginBase:: |
|
FileTranslator:: |
public | function |
Returns if the translator has any settings for the passed job. Overrides TranslatorPluginBase:: |
|
FileTranslator:: |
public | function |
@abstract Overrides TranslatorPluginInterface:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TranslatorPluginBase:: |
protected | property | Characters that indicate the end of an escaped string. | 1 |
TranslatorPluginBase:: |
protected | property | Characters that indicate the beginning of an escaped string. | 1 |
TranslatorPluginBase:: |
public | function |
Aborts a translation job. Overrides TranslatorPluginInterface:: |
|
TranslatorPluginBase:: |
public | function |
Accept a single data item. Overrides TranslatorPluginInterface:: |
|
TranslatorPluginBase:: |
public | function |
Checks whether a translator is available. Overrides TranslatorPluginInterface:: |
1 |
TranslatorPluginBase:: |
public | function |
Returns the escaped #text of a data item. Overrides TranslatorPluginInterface:: |
|
TranslatorPluginBase:: |
public | function |
Specifies default mappings for local to remote language codes. Overrides TranslatorPluginInterface:: |
1 |
TranslatorPluginBase:: |
protected | function | Returns the escaped string. | |
TranslatorPluginBase:: |
public | function |
Default implementation that gets target languages for each remote language.
This approach is ineffective and therefore it is advised that a plugin
should provide own implementation. Overrides TranslatorPluginInterface:: |
1 |
TranslatorPluginBase:: |
public | function |
Gets all supported languages of the translator. Overrides TranslatorPluginInterface:: |
|
TranslatorPluginBase:: |
public | function |
Returns all available target languages that are supported by this service
when given a source language. Overrides TranslatorPluginInterface:: |
2 |
TranslatorPluginBase:: |
public | function |
Removes escape patterns from an escaped text. Overrides TranslatorPluginInterface:: |