Stand with Ukraine! How can you help?

Unable to change language in OpenCart 4.0.1.1 - 4.0.2.1

OpenCartBot - 16/05/2023
Unable to change language in OpenCart 4.0.1.1 - 4.0.2.1

We develop extensions for OpenCart 4.0 and noticed that the releases of OpenCart 4.0.1.1, 4.0.2.0, 4.0.2.1 have many bugs, one of which is the problem with language switching. This problem does not appear if the site has only one language, but if there are several languages, you may notice that it is impossible to change the language of the admin panel or that default extension phrases are not translated on the site when the language is changed, they are always displayed in English. Of course, this is a serious OpenCart bug, which, however, its author is in no hurry to solve despite numerous complaints from users and contributors to the system. We hope that the problem will be finally resolved in the next releases of OpenCart, but for now, we suggest solving the problem by editing the system files.


The language of the OpenCart 4.0.1.1 - 4.0.2.1 admin panel does not change

In the header of the admin panel there is a language switcher that displays all available localizations. But when you try to change the language in the admin panel, nothing happens. More precisely, the page reloads, but the language remains in English. The problem is known and can be solved by replacing a code block in one file.

Open the file admin/controller/startup/language.php and find the following code block there (if you changed the name of the admin folder - look for the file in the folder with your new name):

// Language
if ($language_info['extension']) {
 self::$extension = $language_info['extension'];

 $this->language->addPath('extension/' . $language_info['extension'], DIR_EXTENSION . $language_info['extension'] . '/admin/language/');
}

Аnd replace to

$this->language = new \Opencart\System\Library\Language($code);
// Language
if ($language_info['extension']) {
 self::$extension = $language_info['extension'];

 $this->language->addPath(DIR_EXTENSION . $language_info['extension'] . '/admin/language/');
} else {
 $this->language->addPath(DIR_LANGUAGE);
}

Extension titles and phrases on the OpenCart 4.0.1.1 - 4.0.2.1 are not translated

When changing the language on the site, some phrases may not translate due to the lack of translation of specific phrases, but there is also a problem with the translation of standard modules, such as Account or Featured Products. You can see that the titles and phrases of these extensions are not translated and are always displayed in English. This is a problem with specific versions of OpenCart, not with the installed localizations. This problem can also be solved by replacing a code block in one of the system files. However, the localization folders and files must be present in the corresponding module directories inside the /extension/ directory. Therefore, carefully read the instructions for installing the localization you are going to add to your site. Some localization modules automatically copy translation files to the folders of other modules, while others ask you to copy the files manually to specific folders.

Open the file catalog/controller/startup/language.php and find the following code block there:

// Language
if ($language_info['extension']) {
 self::$extension = $language_info['extension'];

 $this->language->addPath('extension/' . $language_info['extension'], DIR_EXTENSION . $language_info['extension'] . '/catalog/language/');
}

Аnd replace to

$this->language = new \Opencart\System\Library\Language($code);
// Language
if ($language_info['extension']) {
 self::$extension = $language_info['extension'];

 $this->language->addPath(DIR_EXTENSION . $language_info['extension'] . '/catalog/language/');
} else {
 $this->language->addPath(DIR_LANGUAGE);
}


Of course, there are still a lot of bugs in the initial releases of OpenCart 4.0.x.x, but there is nothing perfect, we have to create the perfect for ourselves. Nevertheless, we are looking forward to new stable releases of Opencart 4 and moving forward.


Products related to this post


Related Posts