PHP code example of opgginc / laravel-essentials-entry
1. Go to this page and download the library: Download opgginc/laravel-essentials-entry library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
opgginc / laravel-essentials-entry example snippets
'language' => [
'enabled' => true,
'default' => env('APP_LOCALE'), // 기본 언어 (이 언어는 URL에 표시되지 않음)
// 지원 언어 목록 (순서가 중요: 같은 기본 언어에 대해 먼저 나열된 항목이 우선순위가 높음)
// 예: 'zh'를 감지하면 아래 순서대로 'zh_CN'이 'zh_TW'나 'zh_HK'보다 우선 적용됨
'supported' => [
'en',
'es_ES',
'zh_CN', // 중국어 간체 우선
'zh_TW', // 번체 (대만)
// 'zh_HK', // 번체 (홍콩)
'ja_JP',
'ko_KR',
],
'cookie' => [ // 사용자 언어 설정 저장용 쿠키
'name' => '_ol',
'minutes' => 60 * 24 * 365, // 1년
],
// 특별 매핑 관계 (서로 대체 가능한 언어들)
'locale_mappings' => [
// 번체 중국어 상호 참조 (zh_HK와 zh_TW는 모두 번체 중국어라 서로 대체 가능)
// 중국어 홍콩/대만 버전 차이점은 https://kargn.as/posts/differences-hong-kong-taiwan-chinese-website-ui-localisation 참고
'zh_HK' => 'zh_TW',
'zh_TW' => 'zh_HK',
],
],
// 다국어 라우트 생성
Route::localized(function () {
// 모든 언어에 대해 다음 URL들이 생성됨:
// - /{locale}/
// - /{locale}/users
// - /{locale}/users/{id}
Route::get('/', 'HomeController@index')->name('home');
Route::get('/users', 'UserController@index')->name('users.index');
Route::get('/users/{id}', 'UserController@show')->name('users.show');
});
// 라우트 URL 생성
$url = route('users.show', ['id' => 1, 'locale' => 'ko_KR']); // /ko_KR/users/1