尊龙凯时人生就是搏

Laravel¿ª·¢£ºÔõÑùʹÓÃLaravel LocalizationÖ§³Ö²î±ðÓïÑÔ £¿

Ëæ×ÅÈ«Çò»¯µÄ¼ÓËÙ£¬Ô½À´Ô½¶àµÄÍøÕ¾ºÍÓ¦ÓóÌÐòÐèÒªÖ§³Ö¶àÖÖÓïÑÔ¡£ÎªÁËÈÃÄãµÄÓ¦ÓóÌÐòÄܹ»¸üºÃµØЧÀÍÓÚÈ«ÇòÓû§£¬laravel ÌṩÁËÒ»¸ö¹¦Ð§Ç¿Ê¢µÄÍâµØ»¯¹¤¾ß°ü¡£ÔÚÕâƪÎÄÕÂÖУ¬ÎÒÃǽ«ÏÈÈÝ laravel localization µÄ»ù±¾¿´·¨£¬²¢ÑÝʾÔõÑùʹÓÃËüÀ´Ö§³Ö²î±ðµÄÓïÑÔ¡£

ʲôÊÇ Laravel Localization £¿

Laravel Localization ÊÇ Laravel ¿ò¼ÜµÄÒ»¸öÀ©Õ¹£¬ËüÌṩÁËÒ»ÖÖÀû±ãµÄÒªÁìÀ´´¦Àí¶àÓïÑÔ×Ö·û´®¡£Õâ¸öÀ©Õ¹ÔÊÐíÄãÔÚÓ¦ÓóÌÐòÖÐÇáËɵØʹÓòî±ðµÄÓïÑÔ£¬²¢Æ¾Ö¤Óû§µÄÓïÑÔÇéÐηµ»Ø²î±ðµÄ×Ö·û´®¡£

ÔõÑùʹÓà Laravel Localization £¿

ҪʹÓà Laravel Localization£¬ÄãÐèÒª¾ÙÐÐÒÔÏ°취£º

µÚÒ»²½£º×°Öà Laravel

ÈôÊÇÄãÒѾ­×°ÖÃÁË Laravel£¬Ôò¿ÉÒÔÌø¹ý´Ë°ì·¨¡£ÈôÊÇûÓУ¬ÇëÏÈ×°Öà Laravel¡£Äã¿ÉÒÔͨ¹ý¹Ù·½Îĵµ https://laravel.com/docs ×°Öà Laravel¡£

µÚ¶þ²½£ºÉèÖà Laravel Localization

ÔÚ Laravel ÖУ¬ÄãÐèÒªÉèÖÃÓ¦ÓóÌÐòÀ´Ö§³Ö¶àÓïÑÔ¡£Õâ°üÀ¨Á½¸ö°ì·¨£º

ÉèÖÃÓ¦ÓóÌÐòÓïÑÔÇéÐÎ

Laravel Localization Ö§³Ö¶à¸öÓïÑÔÇéÐΡ£Ä¬ÈÏÇéÐÎÏ£¬Laravel Ö§³ÖÓ¢ÎÄ£¨en£©ºÍÎ÷°àÑÀÓes£©Á½ÖÖÓïÑÔÇéÐΡ£

ÈôÊÇÄãÐèÒªÌí¼ÓÆäËûÓïÑÔÇéÐΣ¬ÔòÐèÒª¶Ô config/app.php Îļþ¾ÙÐиü¸Ä¡£

ÕÒµ½ locale Ñ¡Ï²¢½«ÆäÉèÖÃΪÄãÒªÌí¼ÓµÄÓïÑÔÇéÐεÄÓïÑÔ´úÂë¡£ÀýÈ磬ÈôÊÇÄãÒªÌí¼Ó·¨ÓÔò½« locale Ñ¡ÏîÉèÖÃΪ fr¡£

// config/app.php
'locale' => 'fr',

µÇ¼ºó¸´ÖÆ

Òª¼ì²éÒ»¸öÓïÑÔÇéÐÎÊÇ·ñ¿ÉÓã¬Ôò¿ÉÒÔÖ´ÐÐÒÔÏÂÏÂÁ

php artisan tinker
>>> print_r(config('app.available_locales'));

µÇ¼ºó¸´ÖÆ

Ìí¼ÓÓïÑÔÎļþ

ÏÖÔÚ£¬ÄãÐèÒªÌí¼ÓÿÖÖÓïÑÔµÄÓïÑÔÎļþ¡£ÔÚ Laravel Localization ÖУ¬Ã¿ÖÖÓïÑÔ¶¼ÓÐÒ»¸öÓïÑÔÎļþ¡£Ä¬ÈÏÇéÐÎÏ£¬ÕâЩÎļþλÓÚ resources/lang Ŀ¼ÖС£

Òª½¨ÉèÒ»¸öеÄÓïÑÔÎļþ£¬ÇëʹÓÃÏÂÁ

php artisan make:lang {language_code}

µÇ¼ºó¸´ÖÆ

ÀýÈ磬Ҫ½¨ÉèÒ»¸öеķ¨ÓïÓïÑÔÎļþ£¬ÇëʹÓÃÒÔÏÂÏÂÁ

php artisan make:lang fr

µÇ¼ºó¸´ÖÆ

Õ⽫ÔÚ resources/lang Ŀ¼Ï½¨ÉèÒ»¸öÃûΪ fr µÄÐÂĿ¼£¬ÆäÖаüÀ¨Ò»¸öÃûΪ messages.php µÄÓïÑÔÎļþ¡£

½ÓÏÂÀ´£¬ÄãÐèÒª·­¿ªÕâ¸öÎļþ£¬²¢Ìí¼ÓÄãÒª·­ÒëµÄËùÓÐ×Ö·û´®¡£ÀýÈ磺

<?php
return [
    'welcome' => "Bienvenue sur mon application",
    'title'   => "La page d'accueil",
];

µÇ¼ºó¸´ÖÆ

ÏÖÔÚ£¬ÔÚÿ¸öÓïÑÔĿ¼ÖÐÌí¼ÓÒ»¸öÓïÑÔÎļþÒÔ½¨Éè²î±ðµÄÓïÑÔÇéÐΡ£

µÚÈý²½£ºÔÚ³ÌÐòÖÐʹÓà Laravel Localization

ÏÖÔÚ£¬ÄãÒѾ­ÉèÖÃÁËÓ¦ÓóÌÐòÀ´Ö§³Ö¶àÖÖÓïÑÔ¡£½ÓÏÂÀ´£¬ÄãÐèÒªÔÚ PHP ³ÌÐòÖÐʹÓà Laravel Localization¡£

ʹÓà trans º¯Êý¿ÉÒÔÔÚ Laravel ÖÐÇáËɵص¼º½¶àÓïÑÔ×Ö·û´®¡£´Ëº¯Êý½ÓÊܶà¸ö²ÎÊý£ºÐèÒª·­ÒëµÄ×Ö·û´®ÒÔ¼°Èκζ¯Ì¬²ÎÊý¡£

ÀýÈ磬ҪÔÚÊÓͼÖÐÊä³ö½Ó´ýÐÂÎÅ£¬Äã¿ÉÒÔÕâÑùд£º

<h1>{{ trans('messages.welcome') }}</h1>

µÇ¼ºó¸´ÖÆ

Õ⽫ƾ֤ѡ¶¨µÄÓïÑÔÇéÐηµ»ØÊʵ±µÄ×Ö·û´®¡£ÈôÊÇÑ¡ÔñµÄÓïÑÔÇéÐÎÊÇ·¨ÓÔòµ¼º½µ½ resources/lang/fr/messages.php ÖУ¬ÈôÊÇÑ¡ÔñµÄÊÇÓ¢ÓÔòµ¼º½µ½ resources/lang/en/messages.php¡£

ÁíÒ»ÖÖ³£ÓÃµÄ Laravel Localization ¹¦Ð§ÊÇÑ¡ÔñÓû§µÄÊ×Ñ¡ÓïÑÔ¡£Õâ¿ÉÒÔͨ¹ý»á¼ûÓû§µÄ HTTP Í·À´ÊµÏÖ£º

use IlluminateHttpRequest;

public function index(Request $request)
{
    $locale = $request->header('Accept-Language');
    app()->setLocale($locale);

    return view('welcome');
}

µÇ¼ºó¸´ÖÆ

Õ⽫ƾ֤Óû§µÄÊ×Ñ¡ÓïÑÔÑ¡ÔñÊʵ±µÄÓïÑÔÇéÐΡ£

×ܽá

Laravel Localization ÌṩÁËÒ»ÖÖÀû±ãµÄÒªÁìÀ´Ö§³Ö¶àÖÖÓïÑÔ¡£Í¨¹ýÉèÖÃÓ¦ÓóÌÐòÓïÑÔÇéÐβ¢Ê¹Óà trans º¯ÊýÀ´»á¼û¶àÓïÑÔ×Ö·û´®£¬Äã¿ÉÒÔÔÚ Laravel Ó¦ÓóÌÐòÖÐÇáËɵØÖ§³Ö²î±ðµÄÓïÑÔ¡£ÕâʹµÃ Laravel Localization ³ÉΪΪȫÇòÓû§Ìṩ¸ßÖÊÁ¿Ð§À͵ıر¸¹¤¾ß¡£

ÒÔÉϾÍÊÇLaravel¿ª·¢£ºÔõÑùʹÓÃLaravel LocalizationÖ§³Ö²î±ðÓïÑÔ £¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ