1: | <?php
2: | namespace Opencart\Catalog\Controller\Startup;
3: | /**
4: | * Class Language
5: | *
6: | * @package Opencart\Catalog\Controller\Startup
7: | */
8: | class Language extends \Opencart\System\Engine\Controller {
9: | /**
10: | * @var array<string, array<string, mixed>>
11: | */
12: | private static array $languages = [];
13: |
14: | /**
15: | * Index
16: | *
17: | * @return void
18: | */
19: | public function index(): void {
20: | $this->load->model('localisation/language');
21: |
22: | self::$languages = $this->model_localisation_language->getLanguages();
23: |
24: | $language_info = [];
25: |
26: | // Set default language
27: | if (isset(self::$languages[$this->config->get('config_language_catalog')])) {
28: | $language_info = self::$languages[$this->config->get('config_language_catalog')];
29: | }
30: |
31: | // If GET has language var
32: | if (isset($this->request->get['language']) && isset(self::$languages[$this->request->get['language']])) {
33: | $language_info = self::$languages[$this->request->get['language']];
34: | }
35: |
36: | if ($language_info) {
37: | // If extension switch add language directory
38: | if ($language_info['extension']) {
39: | $this->language->addPath('extension/' . $language_info['extension'], DIR_EXTENSION . $language_info['extension'] . '/catalog/language/');
40: | }
41: |
42: | // Set the config language_id key
43: | $this->config->set('config_language_id', $language_info['language_id']);
44: | $this->config->set('config_language', $language_info['code']);
45: |
46: | $this->load->language('default');
47: | }
48: | }
49: |
50: | /**
51: | * After
52: | *
53: | * Override the language default values
54: | *
55: | * @param string $route
56: | * @param string $prefix
57: | * @param string $code
58: | * @param array<mixed> $output
59: | *
60: | * @return void
61: | */
62: | public function after(&$route, &$prefix, &$code, &$output): void {
63: | if (!$code) {
64: | $code = $this->config->get('config_language');
65: | }
66: |
67: | // Use $this->language->load so it's not triggering infinite loops
68: | $this->language->load($route, $prefix, $code);
69: |
70: | if (isset(self::$languages[$code])) {
71: | $language_info = self::$languages[$code];
72: |
73: | $path = '';
74: |
75: | if ($language_info['extension']) {
76: | $extension = 'extension/' . $language_info['extension'];
77: |
78: | if (oc_substr($route, 0, strlen($extension)) != $extension) {
79: | $path = $extension . '/';
80: | }
81: | }
82: |
83: | // Use $this->language->load so it's not triggering infinite loops
84: | $this->language->load($path . $route, $prefix, $code);
85: | }
86: | }
87: | }
88: |

OpenCart API API documentation generated by ApiGen dev-master