1: | <?php
2: | namespace Opencart\Admin\Controller\Startup;
3: | /**
4: | * Class Language
5: | *
6: | * @package Opencart\Admin\Controller\Startup
7: | */
8: | class Language extends \Opencart\System\Engine\Controller {
9: | /**
10: | * @var array<string, array<string, string>>
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_admin')])) {
28: | $language_info = self::$languages[$this->config->get('config_language_admin')];
29: | }
30: |
31: | // If cookie has language stored
32: | if (isset($this->request->cookie['language']) && isset(self::$languages[$this->request->cookie['language']])) {
33: | $language_info = self::$languages[$this->request->cookie['language']];
34: | }
35: |
36: | if ($language_info) {
37: | if ($language_info['extension']) {
38: | $this->language->addPath('extension/' . $language_info['extension'], DIR_EXTENSION . $language_info['extension'] . '/admin/language/');
39: | }
40: |
41: | // Set the config language_id key
42: | $this->config->set('config_language_id', $language_info['language_id']);
43: | $this->config->set('config_language', $language_info['code']);
44: |
45: | $this->load->language('default');
46: | }
47: | }
48: |
49: | /**
50: | * After
51: | *
52: | * Fill the language up with default values
53: | *
54: | * @param string $route
55: | * @param string $prefix
56: | * @param string $code
57: | * @param array<mixed> $output
58: | *
59: | * @return void
60: | */
61: | public function after(string &$route, string &$prefix, string &$code, array &$output): void {
62: | if (!$code) {
63: | $code = $this->config->get('config_language_admin');
64: | }
65: |
66: | // Use $this->language->load so it's not triggering infinite loops
67: | $this->language->load($route, $prefix, $code);
68: |
69: | if (isset(self::$languages[$code])) {
70: | $language_info = self::$languages[$code];
71: |
72: | $path = '';
73: |
74: | if ($language_info['extension']) {
75: | $extension = 'extension/' . $language_info['extension'];
76: |
77: | if (oc_substr($route, 0, strlen($extension)) != $extension) {
78: | $path = $extension . '/';
79: | }
80: | }
81: |
82: | // Use $this->language->load so it's not triggering infinite loops
83: | $this->language->load($path . $route, $prefix, $code);
84: | }
85: | }
86: | }
87: |

OpenCart API API documentation generated by ApiGen dev-master