diff --git a/code/Project_2-master/app/Http/Controllers/HomeController.php b/code/Project_2-master/app/Http/Controllers/HomeController.php index 3481e53..833888b 100644 --- a/code/Project_2-master/app/Http/Controllers/HomeController.php +++ b/code/Project_2-master/app/Http/Controllers/HomeController.php @@ -11,6 +11,8 @@ use RenanBr\BibTexParser\Parser; use RenanBr\BibTexParser\Processor; +use Stichoza\GoogleTranslate\GoogleTranslate; + class HomeController extends Controller { diff --git a/code/Project_2-master/app/Http/Controllers/LocalizationController.php b/code/Project_2-master/app/Http/Controllers/LocalizationController.php index b922387..9bad7d6 100644 --- a/code/Project_2-master/app/Http/Controllers/LocalizationController.php +++ b/code/Project_2-master/app/Http/Controllers/LocalizationController.php @@ -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(); } -} \ No newline at end of file +} diff --git a/code/Project_2-master/app/Providers/AppServiceProvider.php b/code/Project_2-master/app/Providers/AppServiceProvider.php index be8ae3a..9a34f63 100644 --- a/code/Project_2-master/app/Providers/AppServiceProvider.php +++ b/code/Project_2-master/app/Providers/AppServiceProvider.php @@ -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 { @@ -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); } } diff --git a/code/Project_2-master/app/helpers.php b/code/Project_2-master/app/helpers.php index 62378f3..b7eecf4 100644 --- a/code/Project_2-master/app/helpers.php +++ b/code/Project_2-master/app/helpers.php @@ -1,25 +1,41 @@ \ No newline at end of file +/** + * 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; + } +} diff --git a/code/Project_2-master/composer.json b/code/Project_2-master/composer.json index b146f15..9110ae3 100644 --- a/code/Project_2-master/composer.json +++ b/code/Project_2-master/composer.json @@ -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" }, diff --git a/code/Project_2-master/composer.lock b/code/Project_2-master/composer.lock index 11c194b..4695bed 100644 --- a/code/Project_2-master/composer.lock +++ b/code/Project_2-master/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "df12afa23ac71fe1005569e1ca54098b", + "content-hash": "4e9514389e696c02b20de3fa884e4c9d", "packages": [ { "name": "asm89/stack-cors", @@ -1459,16 +1459,16 @@ }, { "name": "laminas/laminas-escaper", - "version": "2.15.0", + "version": "2.16.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-escaper.git", - "reference": "c612b0488ae486284c39885efca494c180f16351" + "reference": "9cf1f5317ca65b4fd5c6a3c2855e24a187b288c8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-escaper/zipball/c612b0488ae486284c39885efca494c180f16351", - "reference": "c612b0488ae486284c39885efca494c180f16351", + "url": "https://api.github.com/repos/laminas/laminas-escaper/zipball/9cf1f5317ca65b4fd5c6a3c2855e24a187b288c8", + "reference": "9cf1f5317ca65b4fd5c6a3c2855e24a187b288c8", "shasum": "" }, "require": { @@ -1480,12 +1480,11 @@ "zendframework/zend-escaper": "*" }, "require-dev": { - "infection/infection": "^0.27.11", + "infection/infection": "^0.29.8", "laminas/laminas-coding-standard": "~3.0.1", - "maglnet/composer-require-checker": "^3.8.0", - "phpunit/phpunit": "^9.6.22", - "psalm/plugin-phpunit": "^0.19.0", - "vimeo/psalm": "^5.26.1" + "phpunit/phpunit": "^10.5.45", + "psalm/plugin-phpunit": "^0.19.2", + "vimeo/psalm": "^6.6.2" }, "type": "library", "autoload": { @@ -1517,7 +1516,7 @@ "type": "community_bridge" } ], - "time": "2024-12-17T19:39:54+00:00" + "time": "2025-02-17T12:40:19+00:00" }, { "name": "laravel/framework", @@ -2294,29 +2293,29 @@ }, { "name": "maatwebsite/excel", - "version": "3.1.62", + "version": "3.1.63", "source": { "type": "git", "url": "https://github.com/SpartnerNL/Laravel-Excel.git", - "reference": "decfb9140161fcc117571e47e35ddf27983189ce" + "reference": "fccd234da23b39ab03e1a1f6fe9178fb96ec1be1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/decfb9140161fcc117571e47e35ddf27983189ce", - "reference": "decfb9140161fcc117571e47e35ddf27983189ce", + "url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/fccd234da23b39ab03e1a1f6fe9178fb96ec1be1", + "reference": "fccd234da23b39ab03e1a1f6fe9178fb96ec1be1", "shasum": "" }, "require": { "composer/semver": "^3.3", "ext-json": "*", - "illuminate/support": "5.8.*||^6.0||^7.0||^8.0||^9.0||^10.0||^11.0", + "illuminate/support": "5.8.*||^6.0||^7.0||^8.0||^9.0||^10.0||^11.0||^12.0", "php": "^7.0||^8.0", - "phpoffice/phpspreadsheet": "^1.29.7", + "phpoffice/phpspreadsheet": "^1.29.9", "psr/simple-cache": "^1.0||^2.0||^3.0" }, "require-dev": { "laravel/scout": "^7.0||^8.0||^9.0||^10.0", - "orchestra/testbench": "^6.0||^7.0||^8.0||^9.0", + "orchestra/testbench": "^6.0||^7.0||^8.0||^9.0||^10.0", "predis/predis": "^1.1" }, "type": "library", @@ -2359,7 +2358,7 @@ ], "support": { "issues": "https://github.com/SpartnerNL/Laravel-Excel/issues", - "source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.62" + "source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.63" }, "funding": [ { @@ -2371,35 +2370,35 @@ "type": "github" } ], - "time": "2025-01-04T12:14:36+00:00" + "time": "2025-02-19T14:24:57+00:00" }, { - "version": "3.1.2", + "name": "maennchen/zipstream-php", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/maennchen/ZipStream-PHP.git", - "reference": "aeadcf5c412332eb426c0f9b4485f6accba2a99f" + "reference": "6187e9cc4493da94b9b63eb2315821552015fca9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/aeadcf5c412332eb426c0f9b4485f6accba2a99f", - "reference": "aeadcf5c412332eb426c0f9b4485f6accba2a99f", + "url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/6187e9cc4493da94b9b63eb2315821552015fca9", + "reference": "6187e9cc4493da94b9b63eb2315821552015fca9", "shasum": "" }, "require": { "ext-mbstring": "*", "ext-zlib": "*", - "php-64bit": "^8.2" + "php-64bit": "^8.1" }, "require-dev": { - "brianium/paratest": "^7.7", "ext-zip": "*", "friendsofphp/php-cs-fixer": "^3.16", "guzzlehttp/guzzle": "^7.5", "mikey179/vfsstream": "^1.6", "php-coveralls/php-coveralls": "^2.5", - "phpunit/phpunit": "^11.0", - "vimeo/psalm": "^6.0" + "phpunit/phpunit": "^10.0", + "vimeo/psalm": "^5.0" }, "suggest": { "guzzlehttp/psr7": "^2.4", @@ -2440,7 +2439,7 @@ ], "support": { "issues": "https://github.com/maennchen/ZipStream-PHP/issues", - "source": "https://github.com/maennchen/ZipStream-PHP/tree/3.1.2" + "source": "https://github.com/maennchen/ZipStream-PHP/tree/3.1.1" }, "funding": [ { @@ -2448,7 +2447,7 @@ "type": "github" } ], - "time": "2025-01-27T12:07:53+00:00" + "time": "2024-10-10T12:33:01+00:00" }, { "name": "markbaker/complex", @@ -2661,16 +2660,16 @@ }, { "name": "nesbot/carbon", - "version": "2.72.6", + "version": "2.73.0", "source": { "type": "git", "url": "https://github.com/CarbonPHP/carbon.git", - "reference": "1e9d50601e7035a4c61441a208cb5bed73e108c5" + "reference": "9228ce90e1035ff2f0db84b40ec2e023ed802075" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/CarbonPHP/carbon/zipball/1e9d50601e7035a4c61441a208cb5bed73e108c5", - "reference": "1e9d50601e7035a4c61441a208cb5bed73e108c5", + "url": "https://api.github.com/repos/CarbonPHP/carbon/zipball/9228ce90e1035ff2f0db84b40ec2e023ed802075", + "reference": "9228ce90e1035ff2f0db84b40ec2e023ed802075", "shasum": "" }, "require": { @@ -2764,7 +2763,7 @@ "type": "tidelift" } ], - "time": "2024-12-27T09:28:11+00:00" + "time": "2025-01-08T20:10:23+00:00" }, { "name": "nette/schema", @@ -4395,6 +4394,87 @@ ], "time": "2023-10-25T05:12:01+00:00" }, + { + "name": "stichoza/google-translate-php", + "version": "v5.2.0", + "source": { + "type": "git", + "url": "https://github.com/Stichoza/google-translate-php.git", + "reference": "9429773d991c98f68a25bec40d20f590ea3312a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Stichoza/google-translate-php/zipball/9429773d991c98f68a25bec40d20f590ea3312a0", + "reference": "9429773d991c98f68a25bec40d20f590ea3312a0", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-mbstring": "*", + "guzzlehttp/guzzle": "^7.0", + "php": "^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5.10" + }, + "type": "library", + "autoload": { + "psr-4": { + "Stichoza\\GoogleTranslate\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Levan Velijanashvili", + "email": "me@stichoza.com" + } + ], + "description": "Free Google Translate API PHP Package", + "homepage": "https://github.com/Stichoza/google-translate-php", + "keywords": [ + "google", + "php", + "translate", + "translating", + "translator" + ], + "support": { + "issues": "https://github.com/Stichoza/google-translate-php/issues", + "source": "https://github.com/Stichoza/google-translate-php/tree/v5.2.0" + }, + "funding": [ + { + "url": "https://btc.com/bc1qc25j4x7yahghm8nnn6lypnw59nptylsw32nkfl", + "type": "custom" + }, + { + "url": "https://www.paypal.me/stichoza", + "type": "custom" + }, + { + "url": "https://ko-fi.com/stichoza", + "type": "ko_fi" + }, + { + "url": "https://liberapay.com/stichoza", + "type": "liberapay" + }, + { + "url": "https://opencollective.com/stichoza", + "type": "open_collective" + }, + { + "url": "https://www.patreon.com/stichoza", + "type": "patreon" + } + ], + "time": "2024-08-05T19:11:36+00:00" + }, { "name": "swiftmailer/swiftmailer", "version": "v6.3.0", @@ -4572,20 +4652,20 @@ }, { "name": "symfony/css-selector", - "version": "v7.2.0", + "version": "v6.4.13", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "601a5ce9aaad7bf10797e3663faefce9e26c24e2" + "reference": "cb23e97813c5837a041b73a6d63a9ddff0778f5e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/601a5ce9aaad7bf10797e3663faefce9e26c24e2", - "reference": "601a5ce9aaad7bf10797e3663faefce9e26c24e2", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/cb23e97813c5837a041b73a6d63a9ddff0778f5e", + "reference": "cb23e97813c5837a041b73a6d63a9ddff0778f5e", "shasum": "" }, "require": { - "php": ">=8.2" + "php": ">=8.1" }, "type": "library", "autoload": { @@ -4617,7 +4697,7 @@ "description": "Converts CSS selectors to XPath expressions", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/css-selector/tree/v7.2.0" + "source": "https://github.com/symfony/css-selector/tree/v6.4.13" }, "funding": [ { @@ -4633,7 +4713,7 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:21:43+00:00" + "time": "2024-09-25T14:18:03+00:00" }, { "name": "symfony/deprecation-contracts", @@ -7445,16 +7525,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.12.1", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845" + "reference": "024473a478be9df5fdaca2c793f2232fe788e414" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/123267b2c49fbf30d78a7b2d333f6be754b94845", - "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/024473a478be9df5fdaca2c793f2232fe788e414", + "reference": "024473a478be9df5fdaca2c793f2232fe788e414", "shasum": "" }, "require": { @@ -7493,7 +7573,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.12.1" + "source": "https://github.com/myclabs/DeepCopy/tree/1.13.0" }, "funding": [ { @@ -7501,7 +7581,7 @@ "type": "tidelift" } ], - "time": "2024-11-08T17:47:46+00:00" + "time": "2025-02-12T12:17:51+00:00" }, { "name": "nunomaduro/collision", diff --git a/code/Project_2-master/config/languages.php b/code/Project_2-master/config/languages.php index f8db35a..466b9a5 100644 --- a/code/Project_2-master/config/languages.php +++ b/code/Project_2-master/config/languages.php @@ -10,5 +10,9 @@ 'display' => 'ไทย', 'flag-icon' => 'th' ], + 'zh-CN' => [ + 'display' => '中文', + 'flag-icon' => 'zh-CN' + ], ]; diff --git a/code/Project_2-master/resources/views/layouts/layout.blade.php b/code/Project_2-master/resources/views/layouts/layout.blade.php index c2d4fbf..fd1f3c1 100644 --- a/code/Project_2-master/resources/views/layouts/layout.blade.php +++ b/code/Project_2-master/resources/views/layouts/layout.blade.php @@ -49,7 +49,7 @@ - + @@ -65,7 +65,7 @@
+ */ + function trigger_deprecation(string $package, string $version, string $message, mixed ...$args): void + { + @trigger_error(($package || $version ? "Since $package $version: " : '').($args ? vsprintf($message, $args) : $message), \E_USER_DEPRECATED); + } +}