Search code examples
drupal-modulesdrupal-8translation-scheme

How to make proper module translations in Drupal 8?


I have to prepare modules translations, but the documentation is not helping me.

I know i can use *.pot files, but i can't fully understand how dupal is managing translations.

If i add translations/example.pot drupal will take care of everything else?


Solution

  • First modify module_name.info.yml add:

    'interface translation project': block_example
    'interface translation server pattern': modules/examples/%project/translations/%language.po*
    

    Then create in your module directory folder translations.

    Add translations/language.po files, where you will store translations.

    language.po:

    msgid "your id to translate"
    msgstr "translations test"
    

    template.html.twig:

    <p>{% trans %}your id to translate{% endtrans %}</p>
    

    Then go to your Drupal admin page Configuration/User interface translation, there you can filtr your msgid and see already translated files.

    You may have to use IMPORT {just upload .po file} Translations are imported automatically when you install your module.