Magento – Magento2: how override translates in language pack

language-packagemagento2

I installed language pack in app/i18n/magento2translations/language_nl_nl/ with file nl_NL.csv It's works perfect.
Also, I added in custom theme file app/design/frontend/COMPANY/PROJECT/i18n/nl_NL.csv with my custom translates, but it not working (mode: developer, static content and caches were cleaned).
When I move custom translates to language pack's nl_NL.csv custom translates works fine.
I think the language pack has more priority as a custom theme i18n translates.

How override translates in language pack in the correct way?

Best Answer


[UPDATE] Since Magento 2.2 translation load order is the following:

  1. Loading the module translations.
  2. Load translation package info.
  3. Load theme translation file.
  4. Load database translation. (Inline translation)

That basically means that translation package will overrule theme translation. So quick and easy solution would be overcome it using Inline translation, which was also possible in M1. But we have M2 now which has even more flexibility on board and there is a way to extend existing translation packages with custom ones. All you need to do is create another translation package. So, create a module

Project\Locale

create a registration.php for it with the following content:

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::LANGUAGE,
'project_nl_nl',
__DIR__
);

That's how we define that module is a translation package. Last step, create a meta-file language.xml with the following content:

<language ...>
  <code>nl_NL</code>
  <vendor>project</vendor>
  <package>nl_nl</package>
  <sort_order>10</sort_order>
  <use vendor="language" package="nl_nl" />
</language>

This way you specify the parent translation package you want to extend. And also specify the order, in case you already have translation package inheritance in the project. Here is a link on example from magento itself.

One more thing. Make sure that your <vendor> . '_' . <code> (from language.xml) will match module name from registration.php. project_nl_nl in my example.

Related Topic