cancel
Showing results for 
Search instead for 
Did you mean: 

Language files - duplicate phrases best practices

Language files - duplicate phrases best practices

I am setting up a Magento 2.3 store with different extensions. What I have noticed is that some modules contain language files, containing the same phrases that have already been defined in the theme language file. 10 3rd party modules all containing for example the “Add to Cart” phrase and translation doesn’t make sense to me and causes a lot of extra work. Furthermore it can be difficult to find out which language file is being used for a specific frontend phrase. So question is. Can I safely remove these duplicate phrases from the module specific language files, if they are already present in the theme language file? What is best practice?

1 REPLY 1

Re: Language files - duplicate phrases best practices

Module uses four ways to translate their string:

1. Module translation csv

2. Translation Packages

3. Theme translation csv

4. Database translation

There priority is from top to bottom. So if your theme and your module both contain the translation of “Add to Cart”, your theme translation is applied. You can check the order of translation applied in file : https://github.com/magento/magento2/blob/2.3.2/lib/internal/Magento/Framework/Translate.php#L198 here the order of translation is : 

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

So you can easily add those string in your theme and it will override your module translation.

If you remove those csv file from third party extension, you need to check every time when you upgrade those extension. So the better option is to add those translation to your theme.

I hope it will help you!