Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions code/Project_2-master/app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use RenanBr\BibTexParser\Parser;
use RenanBr\BibTexParser\Processor;

use Stichoza\GoogleTranslate\GoogleTranslate;

class HomeController extends Controller
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,19 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App;
use App\Models\ResearchGroup;
use App\Models\ResearchProject;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;

class LocalizationController extends Controller
{
public function index()
{
$resp = ResearchGroup:: all();
return view('welcome',compact('resp'));
// return view('welcome');
}
public function switchLang($lang)
{
if (array_key_exists($lang, Config::get('languages'))) {
Session::put('applocale', $lang);
// ตั้งค่า locale ทันทีที่เลือกภาษา
App::setLocale($lang);
}
return redirect()->back();
}
}
}
9 changes: 8 additions & 1 deletion code/Project_2-master/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\App; // เพิ่มการใช้งาน App
use Illuminate\Support\Facades\Session; // เพิ่มการใช้งาน Session

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -25,11 +27,16 @@ public function register()
public function boot()
{
Paginator::useBootstrap();

view()->composer(
'layouts.layout',
'layouts.layout',
function ($view) {
$view->with('dn', \App\Models\Program::where('degree_id', '=', 1)->get());
}
);

// ตั้งค่า locale จาก session หากมี ไม่เช่นนั้นใช้ค่า default เป็น 'th'
$locale = Session::get('applocale', 'th');
App::setLocale($locale);
}
}
58 changes: 37 additions & 21 deletions code/Project_2-master/app/helpers.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
<?php

/**
* MAKE AVATAR FUNCTION
*/
if(!function_exists('makeAvatar')){

function makeAvatar($fontPath, $dest, $char){
$path = $dest;
$image = imagecreate(200,200);
$red = rand(0,255);
$green = rand(0,255);
$blue = rand(0,255);
imagecolorallocate($image,$red,$green,$blue);
$textcolor = imagecolorallocate($image,255,255,255);
imagettftext($image,100,0,50,150,$textcolor,$fontPath,$char);
imagepng($image,$path);
imagedestroy($image);
return $path;
}
/**
* MAKE AVATAR FUNCTION
*/
if (!function_exists('makeAvatar')) {
function makeAvatar($fontPath, $dest, $char)
{
$path = $dest;
$image = imagecreate(200, 200);
$red = rand(0, 255);
$green = rand(0, 255);
$blue = rand(0, 255);
imagecolorallocate($image, $red, $green, $blue);
$textcolor = imagecolorallocate($image, 255, 255, 255);
imagettftext($image, 100, 0, 50, 150, $textcolor, $fontPath, $char);
imagepng($image, $path);
imagedestroy($image);
return $path;
}
}



?>
/**
* TRANSLATE TEXT FUNCTION
* ฟังก์ชันนี้จะใช้สำหรับแปลข้อความต้นฉบับ (ภาษาอังกฤษ)
* ให้เป็นภาษาที่เลือกโดยใช้ stichoza/google-translate-php
*/
if (!function_exists('translateText')) {
function translateText($text)
{
// ดึง locale ปัจจุบันของแอปพลิเคชัน
$locale = app()->getLocale();
// หาก locale ไม่ใช่ 'en' (ภาษาอังกฤษ) ให้แปลข้อความจากอังกฤษไปเป็น target locale
if ($locale !== 'en') {
$tr = new \Stichoza\GoogleTranslate\GoogleTranslate($locale);
return $tr->translate($text);
}
// หากเป็นภาษาอังกฤษ ให้คืนค่าข้อความต้นฉบับ
return $text;
}
}
1 change: 1 addition & 0 deletions code/Project_2-master/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"phpoffice/phpword": "^0.18.3",
"renanbr/bibtex-parser": "^2.1",
"spatie/laravel-permission": "^5.4",
"stichoza/google-translate-php": "^5.2",
"symfony/process": "^5.4",
"yajra/laravel-datatables-oracle": "^9.19"
},
Expand Down
Loading