Files
safekat/ci4/app/Controllers/Language.php

30 lines
766 B
PHP
Executable File

<?php
namespace App\Controllers;
use App\Controllers\BaseController;
class Language extends BaseController
{
public function index()
{
$session = session();
$locale = $this->request->getLocale();
$session->remove('lang');
$session->set('lang', $locale);
$url = previous_url();
return redirect()->to($url);
}
// Function to get the translation of the language file from a AJAX request
public function getTranslation()
{
$translationFile = $this->request->getPost('translationFile');
$locale = $this->request->getPost('locale');
$path = "Language/{$locale}/$translationFile.php";
$lang = require APPPATH.$path;
return json_encode($lang);
}
}