Things have changed since I last localized a Drupal contrib module of mine. In D9/10, having a translations folder with .po files no longer seems to be the usual route. Yes, it can be done for local custom modules by specifying the location in the info.yml but I'm looking for a solution for regular, d.o hosted contrib modules. Right now I don't even need many languages, just one, the (Commerce) module in question applies to a single country, so the translation should obviously come directly for anybody installing the module.

I'm aware of this question but it's unanswered.

1 Answer 1


With some perseverance, I succeeded. The required steps are partly as described in the linked other question, have your .po files in a translations folder inside your module. But instead of adding the fixed path to the info.yml file, use the following hook in your .module:

function MODULE_locale_translation_projects_alter(&$projects) {
  $folder = \Drupal::service('extension.list.module')->getPath('MODULE');
  $projects['MODULE'] = [
    'info' => [
      'interface translation server pattern' => $folder . '/translations/%language.po',

You may use a different naming scheme for the files, I decided the language code was enough for me.

This way, it will be loaded from the actual folder, no matter whether it's in custom or not.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.