Skip to content
Snippets Groups Projects
Commit b9819faa authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2397281 by fran seva, Gábor Hojtsy: Languages not translated when you add them

parent 621d9bf9
No related branches found
No related tags found
No related merge requests found
......@@ -109,7 +109,7 @@ public function __construct(StorageInterface $config_storage, StorageInterface $
*/
public function get($name) {
// Read default and current configuration data.
$default = $this->installStorage->read($name);
$default = $this->installStorageRead($name);
$updated = $this->configStorage->read($name);
// We get only the data that didn't change from default.
$data = $this->compareConfigData($default, $updated);
......@@ -199,12 +199,12 @@ public function getComponentNames(array $components) {
foreach ($components as $type => $list) {
// InstallStorage::getComponentNames returns a list of folders keyed by
// config name.
$names = array_merge($names, array_keys($this->installStorage->getComponentNames($type, $list)));
$names = array_merge($names, $this->installStorageComponents($type, $list));
}
return $names;
}
else {
return $this->installStorage->listAll();
return $this->installStorageAll();
}
}
......@@ -355,4 +355,81 @@ public function isUpdatingConfigTranslations() {
return $this->isUpdating;
}
/**
* Read a configuration from install storage or default languages.
*
* @param string $name
* Configuration object name.
*
* @return array
* Configuration data from install storage or default language.
*/
protected function installStorageRead($name) {
if ($this->installStorage->exists($name)) {
return $this->installStorage->read($name);
}
elseif (strpos($name, 'language.entity.') === 0) {
// Simulate default languages as if they were shipped as default
// configuration.
$langcode = str_replace('language.entity.', '', $name);
$predefined_languages = $this->languageManager->getStandardLanguageList();
if (isset($predefined_languages[$langcode])) {
$data = $this->configStorage->read($name);
$data['label'] = $predefined_languages[$langcode][0];
return $data;
}
}
}
/**
* Return the list of configuration in install storage and current languages.
*
* @return array
* List of configuration in install storage and current languages.
*/
protected function installStorageAll() {
$languages = $this->predefinedConfiguredLanguages();
return array_unique(array_merge($this->installStorage->listAll(), $languages));
}
/**
* Get all configuration names and folders for a list of modules or themes.
*
* @param string $type
* Type of components: 'module' | 'theme' | 'profile'
* @param array $list
* Array of theme or module names.
*
* @return array
* Configuration names provided by that component. In case of language
* module this list is extended with configured languages that have
* predefined names as well.
*/
protected function installStorageComponents($type, array $list) {
$names = array_keys($this->installStorage->getComponentNames($type, $list));
if ($type == 'module' && in_array('language', $list)) {
$languages = $this->predefinedConfiguredLanguages();
$names = array_unique(array_merge($names, $languages));
}
return $names;
}
/**
* Compute the list of configuration names that match predefined languages.
*
* @return array
* The list of configuration names that match predefined languages.
*/
protected function predefinedConfiguredLanguages() {
$names = $this->configStorage->listAll('language.entity.');
$predefined_languages = $this->languageManager->getStandardLanguageList();
foreach ($names as $id => $name) {
$langcode = str_replace('language.entity.', '', $name);
if (!isset($predefined_languages[$langcode])) {
unset($names[$id]);
}
}
return array_values($names);
}
}
......@@ -351,6 +351,18 @@ public function testConfigtranslationImportingPoFile() {
$this->assertEqual($config->get('anonymous'), 'Anonymous German');
}
/**
* Test the translation are imported when a new language is created.
*/
public function testCreatedLanguageTranslation() {
// Import a .po file to add de language.
$this->importPoFile($this->getPoFileWithConfigDe(), array('langcode' => 'de'));
// Get the language.entity.de label and check it's been translated.
$override = \Drupal::languageManager()->getLanguageConfigOverride('de', 'language.entity.de');
$this->assertEqual($override->get('label'), 'Deutsch');
}
/**
* Helper function: import a standalone .po file in a given language.
*
......@@ -624,6 +636,9 @@ public function getPoFileWithConfigDe() {
msgid "Anonymous"
msgstr "Anonymous German"
msgid "German"
msgstr "Deutsch"
EOF;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment