1: | <?php
2: | namespace Opencart\Catalog\Controller\Event;
3: | /**
4: | * Class Language
5: | *
6: | * @package Opencart\Catalog\Controller\Event
7: | */
8: | class Language extends \Opencart\System\Engine\Controller {
9: | // view/*/before
10: | // Dump all the language vars into the template.
11: | /**
12: | * @param string $route
13: | * @param array<string, string> $args
14: | *
15: | * @return void
16: | */
17: | public function index(string &$route, array &$args): void {
18: | foreach ($this->language->all() as $key => $value) {
19: | if (!isset($args[$key])) {
20: | $args[$key] = $value;
21: | }
22: | }
23: | }
24: |
25: | // controller/*/before
26: | // 1. Before controller load store all current loaded language data
27: | /**
28: | * Before
29: | *
30: | * @param string $route
31: | * @param array<int, mixed> $args
32: | *
33: | * @return void
34: | */
35: | public function before(string &$route, array &$args): void {
36: | $data = $this->language->all();
37: |
38: | if ($data) {
39: | $this->language->set('backup', json_encode($data));
40: | }
41: | }
42: |
43: | // controller/*/after
44: | // 2. After controller load restore old language data
45: | /**
46: | * After
47: | *
48: | * @param string $route
49: | * @param array<int, mixed> $args
50: | * @param mixed $output
51: | *
52: | * @return void
53: | */
54: | public function after(string &$route, array &$args, &$output): void {
55: | $data = json_decode($this->language->get('backup'), true);
56: |
57: | if (is_array($data)) {
58: | $this->language->clear();
59: |
60: | foreach ($data as $key => $value) {
61: | $this->language->set($key, $value);
62: | }
63: | }
64: | }
65: | }
66: |

OpenCart API API documentation generated by ApiGen dev-master