If you want to use an event system to modify the language file, it's important to note that OpenCart's events system is designed to trigger functionality based on actions in the system. It isn't designed to modify files directly, including language files. (Perhaps i am wrong , maybe some pro can verify it)
This is a bit of a workaround
First, register the event. This will be done in your admin/controller/extension/module/yourmodule.php file (replace yourmodule with the name of your module).
Code: Select all
$this->load->model('setting/event');
$this->model_setting_event->addEvent('yourmodule', 'admin/language/*/before', 'extension/module/yourmodule/modifyLanguage');
Then, you would create the method that gets called when the event fires, in this case it's modifyLanguage. This would be in your admin/controller/extension/module/yourmodule.php file.
Code: Select all
public function modifyLanguage(&$route, &$args, &$output) {
$file = DIR_LANGUAGE . $args[0] . '/' . end(explode('/', $route)) . '.php';
$data = [];
include($file); // This will populate $data with the current language variables
if (!isset($data['new_variable'])) {
$content = file_get_contents($file);
$content .= "\n$_['new_variable'] = 'Your new variable value';";
file_put_contents($file, $content);
}
}
Ps. remember the drill of backup.