3

I have .po file with translation and I have it in modulename/translation/xy.po

When I installed profile in XY language the file was not loaded. I did a little digging and found that \FileTranslation::getTranslationFilesPattern looks for drupal-8.xy.po pattern so I renamed the file, reinstalled my profile but the language still was not picked up. The interface translation was downloaded just fine though. If I manually import the file it works. So it looks to me like the directory for translations has changed maybe?


I have checked the installer and it looks like Drupal only looks into the site's files/translations directory. So how are modules supposed to ship with translations?


So it looks like the translations ARE being imported just fine(entries are present in the locales_source table), but for some reason not everything is displayed translated.


Ok, so I came to a conclusion that my translation file is not imported at all. The reason for incomplete translation is because it comes from downloaded Drupal localization and not my file. I am looking at installer and there is nothing that would suggest po files discovery mechanism in any way, only the drupal core(or any po file) in the files/translations directory(which is where the drupal translation is downloaded into).

2 Answers 2

2

Be sure the directory sites/default is writable, so that during installation the translation files can be copied to the translations directory at sites/default/files/translations

2

OK, so it looks like this change https://www.drupal.org/node/1352228 is cause of all the hell with translations. I'm not sure how I'll handle this for multisite but at least I know where the issue came from.


As a follow-up in order for local .po files to be used one needs to add new records into module's info file or implement the hook_locale_translation_projects_alter. The description of this hook basically explains everything.

But still, it is not working. I had to manually run locale_system_update(array('module' => array('mymodule'))); and CC'd afterwards in order for the translation file to be successfully imported and used. I am not sure if this is a bug or not but it is a huge PITA.

I need the translation to work when the site is installed(I have custom profile) so I have to implement this as additional installation task but am not sure if it will work sin in the locale_system_update function it says not to do this while installing. If anyone has figured this thing out, please leave an answer or a comment, thanks.


Final solution: I had to create two additional installation steps in my profile. Basically I have split the locale_system_update() since it defines two batches. I am running them as last two steps so install_finished() runs before them.

One more info: I had to replace the locale_translation_batch_update_build with manually importing the file since it was not working as expected. So now in my first step I will import desired .po files(see \Drupal\locale\Form\ImportForm::submitForm()) and in the seconds step I am updating config translation since installation handler cannot handle multiple batch configurations even if it says it does(maybe it is not working only in this case).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.