Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Views and other language config is not getting imported.
Original summary
"Trips" Menu Tab not getting translated when try to translate the site using translate menu
Comment | File | Size | Author |
---|---|---|---|
#16 | interdiff-2652750-13-16.txt | 1.22 KB | loopduplicate |
#16 | multilingual-demo--language-config-import--2652750-16.patch | 7.38 KB | loopduplicate |
Comments
Comment #2
mimran CreditAttribution: mimran as a volunteer commentedComment #3
loopduplicateTranslating the view and exporting the configuration doesn't work; not sure why. The configuration is not imported when the profile is installed. Ran out of time today to troubleshoot.
Comment #4
loopduplicateThis patch doesn't work but I'm uploading it to show my failed attempt.
Comment #5
Gábor HojtsyI think when we install the modules the languages are not there yet or something along those lines, so the translations are not getting imported.
Comment #6
loopduplicateThanks for the clue, Gábor :)
Comment #7
loopduplicateHi Gábor,
I've been trying to figure out how to save the translated config manually in our .install file since the language specific .yml files don't get imported and I don't know why.
For sites with just one language, it's easy to set config values using
\Drupal::configFactory()->getEditable()
. Thanks to your article, Drupal 8 multilingual tidbits 16: configuration translation development, it's also easy to get config values for a particular language using\Drupal::languageManager()
.So, for example, how would I write some PHP to set views.view.views_products display.trips_page.display_options.menu.title to "Excursiones" for Spanish?
I've been working on this bug for too many hours and figured it was time to ask for a little advice :)
Regards,
Jeff
Comment #8
Gábor HojtsyYou can indeed use
\Drupal::configFactory()->getEditable($config_name);
to get an original config. You can get a config object for the translation as\Drupal::languageManager()->getLanguageConfigOverride($langcode, $config_name)
and then use this to->set()
,->save()
, etc. Whether a config is in override or original config in a particular language will depend on which language was used to install of course.Comment #9
loopduplicateSweet! Thanks for the help again, Gábor :) I'll give this another shot soon.
Comment #10
loopduplicateAlright. I have a working patch. What I've done is implement hook_install_tasks() to add a custom task. I also implemented hook_install_tasks_alter() to move our task to the end of the list so that it runs after the the final import of languages. The custom task imports language config from .yml files in config/install/languages.
When I tried to run the custom code in hook_install(), it didn't work. Step debugging revealed that the config was being imported correctly from the .yml files already. Somehow, later in the installation process, during one of core's final install tasks, the config is overridden.
It would be nice if core was able to import the language config without this workaround, but for now, at least our profile is translated correctly :)
Regards,
Jeff
Comment #11
loopduplicateAdding a couple of related issues.
Comment #12
Kristen PolNice! I tested the patch on simplytest.me and it is working. I also tested without the patch and see the original problem. I reviewed the code and the only things that catch my eye:
1) Might be nice to have some comments within
multilingual_demo_install_import_language_config
.2) Should the system maintenance config be part of this patch? I'm assuming that was from a different issue:
Thanks!
Comment #13
loopduplicatere #12:
1) OK, comments added.
2) The system maintenance and site name config could be added in a different issue. I used Google to get the translations. I figured that if they weren't quite right, we could open another ticket to make them right but at least for now there is something so that the profile doesn't appear to be broken.
Comment #14
loopduplicatePlease note that the new patch in #13 includes the site maintenance and site name config.
Comment #15
Gábor HojtsyIt is not a problem to use google translate, we did so for the rest of the text as well ;)
Generally I am surprised that our source config strings do not appear on https://localize.drupal.org/translate/languages/az/translate?project=mul.... If the source strings from shipped config would appear there, then there would be no need to import translations "manually" either for all the config we ship with. Looking forward to having a new point release of the distro so we can see if that gets some more strings, eg. the default views.
In short I think this code would only be needed for dynamically created config within the installation. But for now it is a good stop-gap for the problem we experience. One comment on the code.
We should only import translations for languages that are not already the installation language, right? If we install in Hungarian, the default config would be translated in the original config.
Comment #16
loopduplicateHere's an updated patch which only imports translations for languages that are not the installation language :)
Comment #17
Gábor HojtsyLooks good to me :)
Comment #19
loopduplicateCommitted :)