Sometimes you may not find the neccesary language while localizing your website. Here is a short step-by-step tutorial to help you with this issue.
Magento 2 is a multilingual system. It used ResourceBundle for working with locales and had all the locales available in the ICU library.
But for some unknown reasons this list is limited. The limitations are located in Magento\Framework\Locale\Config in the _allowedLocales property. Magento 2 uses the getAllowedLocales public function for getting the list of locales.
Adding an unavailable language
First of all, create a plugin:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php namespace BelVG\Locale\Plugin; /** * Class Config * @package BelVG\Locale\Plugin */ class Config { /** * @param \Magento\Framework\Locale\Config $config * @param $items * @return mixed */ public function afterGetAllowedLocales(\Magento\Framework\Locale\Config $config, $locales) { return array_merge($locales,['hy_AM']); // This code we can find in global base of locales } } |
Then enable the plugin in the di.xml file:
1 2 3 4 5 |
<type name="\Magento\Framework\Locale\Config"> <plugin name="BelVG_Locale_Config_Plugin" sortOrder="100" type="BelVG\Locale\Plugin\Config"/> </type> |
After that, we need to run the bin/magento setup:upgrade for applied plugin command in the console.
Here is what we will see as a result:
That’s it, now you have the necessary language on the list.
Magento Custom Development
Take your online store to the next level with BelVG Magento Custom Development
Visit the page
Hi :)
Please, contact us at [email protected]. We need more information :)
Facing the same issue as Oscar mentioned, any solutions? please let me know.
Hi Oscar
could you please provide us with more details at [email protected]?
HI,
I did follow your post and it seems to work, BUT, when I wanna to deploy to production mode, it throws an exception , the message is “es_US argument has invalid value, please run info:language:list for list of available locales “, can you help me? what can I do?