public function StringoverridesAdminForm::getCurrentTranslations in String Overrides 8
Get current translations in format for admin form.
Parameters
string $language: Language code for configuration.
Return value
array Translations.
1 call to StringoverridesAdminForm::getCurrentTranslations()
- StringoverridesAdminForm::buildForm in src/
Form/ StringoverridesAdminForm.php - Form constructor.
File
- src/
Form/ StringoverridesAdminForm.php, line 82
Class
- StringoverridesAdminForm
- Class StringoverridesAdminForm.
Namespace
Drupal\stringoverrides\FormCode
public function getCurrentTranslations($language) {
$config_factory = \Drupal::service('config.factory');
$words_enabled = $config_factory
->getEditable('stringoverrides.string_override.' . $language)
->get('contexts');
$words_disabled = $config_factory
->getEditable('stringoverrides.string_override.' . $language . '_disabled')
->get('contexts');
$words = [
FALSE => $words_disabled ? $words_disabled : [],
TRUE => $words_enabled ? $words_enabled : [],
];
$strings = [];
foreach ($words as $enabled => $custom_strings) {
foreach ($custom_strings as $context) {
foreach ($context['translations'] as $source => $translation) {
$strings[] = [
'enabled' => $enabled,
'context' => $context['context'],
'source' => $translation['source'],
'translation' => $translation['translation'],
];
}
}
}
// Sort alphabetically.
usort($strings, function ($word1, $word2) {
return strcasecmp($word1['source'], $word2['source']);
});
return $strings;
}