You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.6 KiB
82 lines
2.6 KiB
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App;
|
|
|
|
class LangController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('lang');
|
|
}
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function change(Request $request)
|
|
{
|
|
App::setLocale($request->lang);
|
|
session()->put('locale', $request->lang);
|
|
return redirect()->back();
|
|
}
|
|
public function edit(Request $request)
|
|
{
|
|
$path = public_path('lang');
|
|
$file = \File::allFiles($path);
|
|
$data_json = [];
|
|
$data_final = [];
|
|
$data_key_by_lang = [];
|
|
foreach ($file as $f) {
|
|
$content_file = \File::get($f);
|
|
if (\File::extension($f) == "json") {
|
|
$data_json[] = (array)json_decode($content_file);
|
|
}
|
|
}
|
|
if (!empty($data_json)) {
|
|
foreach ($data_json as $data) {
|
|
$data_by_lang[$data['lang']] = $data;
|
|
}
|
|
}
|
|
if (!empty($data_by_lang)) {
|
|
foreach ($data_by_lang as $key => $lang) {
|
|
foreach ($lang as $key_item => $item) {
|
|
$data_final[$key_item][$key] = $item;
|
|
}
|
|
}
|
|
}
|
|
return view('lang', compact('data_final'));
|
|
}
|
|
public function update(Request $request)
|
|
{
|
|
$path = public_path('lang');
|
|
$data_update = json_decode($request->data);
|
|
if (!empty($data_update)) {
|
|
foreach ($data_update as $data) {
|
|
// $file = ($path . DIRECTORY_SEPARATOR . $data->lang . ".json");
|
|
$file = ($path . DIRECTORY_SEPARATOR . 'test' . ".json");
|
|
if (\File::exists($file)) {
|
|
|
|
// $key_update = $data->key;
|
|
// $data_json = json_decode(\File::get($file));
|
|
// $data_json->$key_update = $data->word;
|
|
// $shell = "rm -rf " .base_path() . DIRECTORY_SEPARATOR . "public" . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . "test.json";
|
|
// if (is_dir($path)) {
|
|
// // unlink($path . DIRECTORY_SEPARATOR . "test.json");
|
|
// \File::delete($path . DIRECTORY_SEPARATOR . "test.json");
|
|
// dd(15435345);
|
|
// dd(fopen($path . DIRECTORY_SEPARATOR . "test.json","r"));
|
|
// }
|
|
}else{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|