public function PotxExtractTranslationForm::buildForm in Translation template extractor 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ PotxExtractTranslationForm.php, line 77
Class
- PotxExtractTranslationForm
- Class PotxExtractTranslationForm.
Namespace
Drupal\potx\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$components = $this
->generateComponentList();
$this
->buildComponentSelector($form, $components);
// Generate translation file for a specific language if possible.
$languages = $this->languageManager
->getLanguages();
if (count($languages) > 1 || !isset($languages['en'])) {
// We have more languages, or the single language we have is not English.
$options = [
'n/a' => $this
->t('Language independent template'),
];
foreach ($languages as $langcode => $language) {
// Skip English, as we should not have translations for this language.
if ($langcode == 'en') {
continue;
}
$options[$langcode] = $this
->t('Template file for @langname translations', [
'@langname' => $language
->getName(),
]);
}
$form['langcode'] = [
'#type' => 'radios',
'#title' => $this
->t('Template language'),
'#default_value' => 'n/a',
'#options' => $options,
'#description' => $this
->t('Export a language independent or language dependent (plural forms, language team name, etc.) template.'),
];
$form['translations'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Include translations'),
'#description' => $this
->t('Include translations of strings in the file generated. Not applicable for language independent templates.'),
];
}
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this
->t('Extract'),
];
return $form;
}