7

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?

  • Please try to switch mode to default or production and check again. – Self Diagnostics Aug 18 '16 at 8:00
  • try rm -rf pub/static/*, rm -rf var/cache/* from m2 root folder. – belfort1 Aug 18 '16 at 8:04
  • I wrote in question (mode: developer, static content and caches were cleaned) + local storage has translates in json. It was cleaned too. No affect. – goral Aug 18 '16 at 11:37
10


[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.

  • Sounds great - but where exactly do I then override the translation? Yet another nl_NL.csv within that module? – fritzmg Aug 15 '18 at 10:45
  • 1
    @fritzmg yes, tranlsation file format / name is exactly the same – Sergey Aug 15 '18 at 14:42
  • 1
    thx, thought so. However I still cannot get it to work, though I have opened a separate question for that: magento.stackexchange.com/questions/238459/… – fritzmg Aug 15 '18 at 15:31
  • 1
    Just for further readers, this answer is no longer valid. Since a long time ago, Magento changed this behavior: github.com/magento/magento2/blob/2.3-develop/lib/internal/… The current order is: 1) Module translation (app/code/[Vendor_Name]/i18n) 2) Language pack translation (app/i18n) 3) Theme translation (app/design/[theme]/i18n) 4) Database translation (inline) – Manuel García Solipa Oct 29 at 12:44
  • @ManuelGarcíaSolipa yes, you are right, they changed it in 2.2. Updated the post – Sergey Oct 31 at 10:52
4

I had the same problem and found the solution. \Magento\Framework\Translate will first load theme translations and then load pack translations. You should create a plugin for this class on the method loadData, and fix the loading order.

  • Nice idea. How did you create a plugin? I only managed to create a preference because all other methods I needed were protected. I would be interested in a plugin-like solution. – simonthesorcerer Nov 8 '18 at 15:36
2

I don't know if it's because now is 2019 or if Sergey's answer has had an error from the beginning, but the actual loading order in file vendor/magento/framework/Translate.php is this:

$this->_loadModuleTranslation();
$this->_loadPackTranslation();
$this->_loadThemeTranslation();
$this->_loadDbTranslation();

What gets loaded later, gets to override the previous translations.

So, even though Daniel Sloof's answer works, you can just add your translation to the theme and it will have higher priority than a language pack.

1

If clean static content, caches and translates in local storage theme CSV works, but not for some words. So, lang pack overrided by custom theme translates, but not for all phrases.

0

Magento is loading translation info in the following order

Loading the module translations. Load theme translation file Load translation package info. Load db tranlation. (Inline translation)

I have different translation in de_de package in module, theme and another package (vendor/{name}/language-de_de). I saw that translation got from theme always. Clear pub/static and cache (with cache in Chrome). What is the real load translation priorities?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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