Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3443205
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3443205
Commits
b9819faa
Commit
b9819faa
authored
10 years ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2397281
by fran seva, Gábor Hojtsy: Languages not translated when you add them
parent
621d9bf9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/locale/src/LocaleConfigManager.php
+80
-3
80 additions, 3 deletions
core/modules/locale/src/LocaleConfigManager.php
core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
+15
-0
15 additions, 0 deletions
core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
with
95 additions
and
3 deletions
core/modules/locale/src/LocaleConfigManager.php
+
80
−
3
View file @
b9819faa
...
...
@@ -109,7 +109,7 @@ public function __construct(StorageInterface $config_storage, StorageInterface $
*/
public
function
get
(
$name
)
{
// Read default and current configuration data.
$default
=
$this
->
installStorage
->
r
ead
(
$name
);
$default
=
$this
->
installStorage
R
ead
(
$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
->
get
Component
Name
s
(
$type
,
$list
))
)
;
$names
=
array_merge
(
$names
,
$this
->
installStorageComponents
(
$type
,
$list
));
}
return
$names
;
}
else
{
return
$this
->
installStorage
->
list
All
();
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
);
}
}
This diff is collapsed.
Click to expand it.
core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
+
15
−
0
View file @
b9819faa
...
...
@@ -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;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment