I've looked everywhere for some tips for dealing with this, but I can only find tutorials regarding translation of the Drupal core itself.

I've created a custom module and want to make translations for it. As far as I can see from looking at other modules, I need to place the translated .po files it a directory called "translations" under my module's directory.

Using the potx module I've extracted a .pot file and a .po file for my Danish translation. I translated a lot of the texts using the Poedit editor and tried to upload the result:
- my_module.da.po
- my_module.pot

But nothing happens. I've cleared the cache, but my site still just displays the standard texts from my module. My site is already set to Danish (da) as the default language.

What do I need to do to make Drupal use this translation?!

Comments

rsm08’s picture

Please, anyone?

Doesn't anyone know how to translate modules!?

Jaypan’s picture

You have to import the translations after creating them. Go to 'translation interface', and click the 'import' tab.

rsm08’s picture

But do I really have to import translation files for every module on Drupal? I have some 50 custom modules added. This is an immense task, and what if I upgrade a module and need a new translation?! This sounds very strange.

Are you completely sure that modules aren't meant to import their translation files automatically, when they're enabled?

Jaypan’s picture

Yes you do. And I agree, it's a pain in the ass. But as far as I know, it's just the way it is.

Edit: Actually on second thought, the files should automatically be imported when you enable the module. So if you added the translation files after the fact, you need to import them. But if they are in the translations folder when you enable the module, they should import themselves.

rsm08’s picture

But that Is what I did. I added the files to the directory, disabled the module and enabled it again. But nothing had happened.

I assume disabling and enabling the module does the same as installing it the first time, since my_module.install doesn't contain any code related to importing these files.

????

Jaypan’s picture

I think you will have to uninstall it then re-install it. The translations import probably isn't called during enabling, only during installation, though I'm speculating.

rsm08’s picture

To test this, I tried disabling the module, refresh, deleting its files, refresh, uploading the module again with translation, refresh, enabling the module. - Same result!

The module I tested it on don't have an install file and does not need to be installed or uninstalled. Far from all modules have install files, and partly due to this I don't think the installation procedure has anything to do with this.

The only thing I can think of is that maybe Drupal has still kept a record of the module in the db, and there's no way to remove this from the interface. Maybe Drupal will only import translations for modules, that has never before set foot on the system?!

But it would really seem stupid, if the only change you'd get to have Drupal import translations automatically was when the module was first installed virgin fresh on the site - then no more after could you upload a new translation or do anything update to it..

I still feel there something missing here .. There must be someone who knows exactly how Drupal handles this?!...

Jaypan’s picture

That is definitely a pain in the ass.

I just discovered though that there are hook_enable() and hook_disable() that are called when enabling and disabling modules. There must be some functions that force an import of translations, so you can probably put this together yourself.

rsm08’s picture

Yeah I guess. I think the record in the db is what's keeping Drupal from importing translations more than once. It seems like a really stupid practice though. I assume that a hook_update in the install file of module upgrades will trigger the import function though, so this is better than nothing at all.

It seems that I'll just have to import the .po files directly in the UI to get on from here. I found an amazingly cool module (l10n_client) that makes it possible to translate all texts on a page while browsing the page on the site. This is amazing, because now I don't have to translate like 50 modules or something completely to get translations for the 5-10 % of the strings from each module that will actually be displayed to users and not only in the backend.

Thanks for helping me out!

svdoord’s picture

I just removed my added language, and then added it again. This forced Drupal to import all translations again. So using the import tab should not be necessary.

josepvalls’s picture

I've developed a very simple and small module for Spanish identity document validations. I'd like to publish it as a project and so, but I'd like to include the translations. I've used http://drupal.org/project/potx to create the template and translate it, but how do I set it up so when I enable the module in a new installation my po are imported?
Where can I get some documentation on this?
Thanks.

Jaypan’s picture

Since the time I've posted in this thread previously, I have come to understand the translation system better. You need the following:

1) a folder in the module folder called 'translations'.
2) a language independent file called my_module.pot (of coures you need to change 'my_module' to the name of your module).
3) a file for each language, using the 2-letter language code, followed by .po. So for Japanese translations, I use ja.po

So if I have a module named power_module, I would have the following

power_module/translations
power_module/translations/power_module.pot
power_module/translations/ja.po

You can use the translation template extractor module to extract blank templates for steps 2 and 3 above, though be aware, you will need to rename the extracted language dependent file, as it will be named with your module name initially (ex: power_module.ja.po -> ja.po).

FreddieK’s picture

But did this solve your problem of .po files not being imported when the module was enabled?

I'm developing a module right now and have run into the same problem. I have a translations folder with the module.pot + translations.po files, but still the site won't use the files no matter if I disable/enable the module and flush cache. Is there some hook command available to completely uninstall the module so that when I reenable it the .po files will be imported?

Jaypan’s picture

Yes, it did solve my problem, but only on module install, not module enable. Do you have an .install file with hook_install() and hook_uninstall() in it? If you do, then you need to disable then uninstall the module, then reinstall it. If you don't have an .install file, then I don't know how you can force the install of the translation file after initial installation, but you should be able to go to admin->build (or maybe content) -> translation interface, and click the 'upload' or 'import' tab (I can't remember the exact name of the tab off the top of my head.

vatavale’s picture

You need to delete language, and to add it again. Then all .po files will be readed to database again.

Jaypan’s picture

Gotta be careful with that though - if any custom changes to translations have been made through the admin interface, they will be lost when the language is deleted.