Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mimran created an issue. See original summary.

mimran’s picture

Assigned: Unassigned » mimran
loopduplicate’s picture

Assigned: mimran » Unassigned

Translating 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.

loopduplicate’s picture

This patch doesn't work but I'm uploading it to show my failed attempt.

Gábor Hojtsy’s picture

I think when we install the modules the languages are not there yet or something along those lines, so the translations are not getting imported.

loopduplicate’s picture

Thanks for the clue, Gábor :)

loopduplicate’s picture

Hi 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

Gábor Hojtsy’s picture

You 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.

loopduplicate’s picture

Sweet! Thanks for the help again, Gábor :) I'll give this another shot soon.

loopduplicate’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
6.56 KB

Alright. 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

loopduplicate’s picture

Kristen Pol’s picture

Nice! 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:

diff --git a/config/install/language/hu/system.maintenance.yml b/config/install/language/hu/system.maintenance.yml
new file mode 100644
index 0000000..d978f3c
--- /dev/null
+++ b/config/install/language/hu/system.maintenance.yml
@@ -0,0 +1 @@
+message: '@site karbantartás alatt van . Mi kell vissza rövidesen. Köszönöm a türelmed.'
diff --git a/config/install/language/hu/system.site.yml b/config/install/language/hu/system.site.yml
index 7309dd0..ffda0b1 100644
--- a/config/install/language/hu/system.site.yml
+++ b/config/install/language/hu/system.site.yml
@@ -1 +1,2 @@
+name: 'Beutazni a világot'
 slogan: 'Mikor ez kész!'

Thanks!

loopduplicate’s picture

re #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.

loopduplicate’s picture

Please note that the new patch in #13 includes the site maintenance and site name config.

Gábor Hojtsy’s picture

It 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.

+++ b/multilingual_demo.profile
@@ -16,3 +17,57 @@ function multilingual_demo_form_install_configure_form_alter(&$form, FormStateIn
+  // Sub-directory names (language codes).
+  $langcodes = array_diff(scandir($language_config_directory), array('..', '.'));

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.

loopduplicate’s picture

Here's an updated patch which only imports translations for languages that are not the installation language :)

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me :)

  • loopduplicate committed 1f772c5 on 8.x-1.x
    Issue #2652750 by loopduplicate, Gábor Hojtsy, Kristen Pol: "Trips" Menu...
loopduplicate’s picture

Status: Reviewed & tested by the community » Fixed

Committed :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.