×ðÁú¿­Ê±¹ÙÍøµÇ¼

ÔõÑùʹÓÃThinkPHP6¾ÙÐжàÓïÑÔ·­Òë²Ù×÷£¿

Ëæ×ÅÈ«Çò»¯µÄÉú³¤ £¬Ô½À´Ô½¶àµÄÍøÕ¾ºÍÓ¦ÓóÌÐòÐèÒªÌṩ¶àÓïÑÔÖ§³Ö¡£¶ø¹ØÓÚʹÓÃthinkphp6¿ò¼ÜµÄ¿ª·¢ÕßÀ´Ëµ £¬ÔõÑùʵÏÖ¶àÓïÑÔ·­Òë²Ù×÷ÊÇÒ»¸öÖ÷ÒªµÄÐèÇó¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃthinkphp6¾ÙÐжàÓïÑÔ·­Òë²Ù×÷¡£

ÉèÖÃÓïÑÔ°ü

ÔÚThinkPHP6ÖÐ £¬ÓïÑÔ°üÊÇÒ»¸ö°üÀ¨¼üÖµ¶ÔµÄÊý×é¡£¿ÉÒÔ½«Æä´æ´¢ÔÚapp/lang/Ŀ¼ÏµÄÖÖÖÖ×ÓĿ¼ÖС£ÀýÈ磺

/app/lang/zh-cn/
/app/lang/en-us/

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬zh-cnºÍen-usÊÇÓïÑÔ°üµÄÃû³Æ £¬ËüÃǶÔÓ¦µÄĿ¼Ï¾ÍÓ¦¸Ã´æ·Å¸ÃÓïÑÔ°æ±¾µÄ·­Òë¡£ÔÚÓïÑÔ°üĿ¼Ï £¬Í¨³ £»áÓÐÒ»¸öapp.php»òÕßvalidation.phpÎļþ £¬ËüÃÇ»®·Ö¶ÔÓ¦Ó¦ÓóÌÐòºÍ±íµ¥ÑéÖ¤µÄ·­Òë¡£

ÀýÈ磺

/app/lang/zh-cn/app.php
/app/lang/en-us/app.php

µÇ¼ºó¸´ÖÆ

ÔÚÕâÁ½¸öÎļþÖÐ £¬»á½ç˵һЩ¼üÖµ¶Ô £¬ÓÃÀ´·­ÒëÓ¦ÓóÌÐòÖеÄÎÄ×Ö¡£ÀýÈç £¬Ò»¸ö¼òÆÓµÄapp.phpÎļþ¿ÉÄܳ¤ÕâÑù£º

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

<?php
return [
    'welcome' => '½Ó´ý',
    'login' => '怬',
    'logout' => 'Í˳öµÇ¼',
];

µÇ¼ºó¸´ÖÆ

ÕâÀï½ç˵ÁËÈý¸ö¼üÖµ¶Ô £¬ËüÃÇÓÃÀ´·­ÒëÓ¦ÓóÌÐòÖеġ°½Ó´ý¡±¡¢¡°µÇ¼¡±ºÍ¡°Í˳öµÇ¼¡±µÄÎÄ×Ö¡£¹ØÓÚÓ¢ÎÄ°æ±¾ £¬¿ÉÒÔ½¨ÉèÒ»¸öen-us/app.phpÎļþ £¬½«ÉÏÃæµÄÖÐÎÄ·­ÒëÌæ»»³ÉÓ¢ÎÄ·­Ò룺

<?php
return [
    'welcome' => 'Welcome',
    'login' => 'Log in',
    'logout' => 'Log out',
];

µÇ¼ºó¸´ÖÆ

¶ÁÈ¡ÓïÑÔ°ü

ÔÚÓ¦ÓóÌÐòÖÐ £¬Í¨³£ÐèҪƾ֤Óû§µÄÓïÑÔÉèÖÃÀ´¶ÁÈ¡ÏìÓ¦µÄÓïÑÔ°ü¡£¿ÉÒÔʹÓÃÒÔÏ´úÂëÀ´»ñÈ¡Ä¿½ñÓïÑÔÉèÖãº

$lang = $request->lang();

µÇ¼ºó¸´ÖÆ

ÕâÀïʹÓÃÁË$request¹¤¾ßµÄlang()ÒªÁì £¬¸ÃÒªÁì¿ÉÒÔ»ñÈ¡ÇëÇ󹤾ßÖеÄlang²ÎÊý¡£Í¨³£Õâ¸ö²ÎÊý»á´æ´¢Óû§µÄÓïÑÔÉèÖà £¬ÀýÈ磺

http://example.com/?lang=zh-cn
http://example.com/?lang=en-us

µÇ¼ºó¸´ÖÆ

ÕâÀïÈôÊÇlang²ÎÊýûÓÐÖ¸¶¨ £¬¿ÉÒÔͨ¹ý¶ÁÈ¡ä¯ÀÀÆ÷µÄAccept-LanguageÍ·À´ÍƲâÓû§µÄÓïÑÔÉèÖá£

½ÓÏÂÀ´ £¬¿ÉÒÔʹÓÃlang()º¯ÊýÀ´¶ÁÈ¡Ä¿½ñÓïÑÔ°ü £¬ÀýÈ磺

$lang = $request->lang();

app()->setLocale($lang);

$translations = lang('app');

µÇ¼ºó¸´ÖÆ

ÕâÀïʹÓÃÁËapp()º¯ÊýÀ´»ñÈ¡Ó¦ÓóÌÐò¹¤¾ß £¬È»ºóͨ¹ýËüµÄsetLocale()ÒªÁìÀ´ÉèÖÃÄ¿½ñµÄÓïÑÔÇéÐΡ£×îºó £¬Ê¹ÓÃlang()º¯ÊýÀ´¶ÁÈ¡ÓïÑÔ°ü £¬Ëü·µ»ØÒ»¸öÊý×é £¬ÆäÖаüÀ¨ÁËÄ¿½ñÓïÑÔÇéÐÎϵÄËùÓз­Òë¡£

ʹÓ÷­Òë

ÓÐÁËÓïÑÔ°üºÍ·­ÒëÊý×é £¬¾Í¿ÉÒÔÔÚÓ¦ÓóÌÐòÖÐʹÓ÷­ÒëÁË¡£ÀýÈç £¬ÔÚÄ£°åÖпÉÒÔʹÓñêÇ©À´»ñÈ¡·­Ò룺

<p>{{ __('app.welcome') }}</p>

µÇ¼ºó¸´ÖÆ

ÕâÀïʹÓÃÁË__º¯ÊýÀ´»ñÈ¡·­Òë¡£__º¯Êý»á½«´«ÈëµÄ×Ö·û´®Æ¾Ö¤µã·Ö·¨ÆÊÎö³ÉÒ»¸öÊý×é £¬È»ºó´Ó·­ÒëÊý×éÖвéÕÒÏìÓ¦µÄ·­Òë¡£

ÈôÊÇûÓÐÕÒµ½¶ÔÓ¦µÄ·­Òë £¬__º¯Êý»á·µ»Øԭʼ×Ö·û´®¡£Òò´Ë £¬¿ÉÒÔ½«Ó¢ÎÄ×Ö·û´®×÷ΪĬÈÏÖµ´«Èë__º¯Êý £¬ÀýÈ磺

<p>{{ __('app.welcome', ['default' => 'Welcome']) }}</p>

µÇ¼ºó¸´ÖÆ

ÕâÀïÖ¸¶¨ÁËÒ»¸ödefault²ÎÊý £¬ËüµÄÖµÊÇ’Welcome’¡£ÈôÊÇÔÚ·­ÒëÊý×éÖÐûÓÐÕÒµ½’welcome’¼ü¶ÔÓ¦µÄ·­Òë £¬__º¯Êý¾Í»á·µ»ØÕâ¸öĬÈÏÖµ¡£

Ìí¼Ó×Ô½ç˵·­Òë

ÓÐʱ¼äÐèÒªÌí¼ÓһЩ×Ô½ç˵µÄ·­Òë £¬ÀýÈç±íµ¥ÑéÖ¤µÄ¹ýʧÐÅÏ¢¡£¿ÉÒÔʹÓÃÒÔÏ´úÂëÀ´Ìí¼Ó×Ô½ç˵·­Ò룺

use thinkacadeLang;

Lang::load([
    'validation.custom' => [
        'email' => [
            'required' => 'ÇëÌîдÓÊÏäµØµã',
            'email' => 'ÇëÊäÈëÓÐÓõÄÓÊÏäµØµã',
        ],
    ],
]);

µÇ¼ºó¸´ÖÆ

ÕâÀïʹÓÃÁËLangÀàµÄload()ÒªÁìÀ´Ìí¼Ó×Ô½ç˵·­Òë¡£load()ÒªÁì½ÓÊÜÒ»¸öÊý×é×÷Ϊ²ÎÊý £¬¸ÃÊý×éƾ֤ÓïÑÔ°üµÄ½á¹¹×éÖ¯ £¬ÓÃÀ´Ìí¼Ó×Ô½ç˵µÄ·­Òë¡£

ÔÚÉÏÃæµÄÀý×ÓÖÐ £¬Ìí¼ÓÁËÒ»¸övalidation.customÓïÑÔ°ü £¬Ëü°üÀ¨ÁË’email’¼üµÄ×Ô½ç˵·­Òë¡£ÕâЩ·­Òë»áÁýÕÖϵͳĬÈϵķ­Òë¡£

×ܽá

ʹÓÃThinkPHP6¾ÙÐжàÓïÑÔ·­Òë²Ù×÷ºÜÊÇÀû±ã¡£Ö»ÐèҪ׼±¸ºÃÓïÑÔ°ü £¬È»ºó¶ÁÈ¡ÓïÑÔ°ü²¢Ê¹Ó÷­Òë¼´¿É¡£ÈôÊÇÐèÒªÌí¼Ó×Ô½ç˵·­Òë £¬Ò²ºÜÊǼòÆÓ¡£¶àÓïÑÔÖ§³Ö²»µ«ÄÜÌá¸ßÓ¦ÓóÌÐòµÄ¿ÉÓÃÐÔ £¬»¹ÄܸüºÃµØÖª×ãÓû§µÄÐèÇó £¬ÔöÌíÓû§ÌåÑé¡£

ÒÔÉϾÍÊÇÔõÑùʹÓÃThinkPHP6¾ÙÐжàÓïÑÔ·­Òë²Ù×÷£¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

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

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

QR code
ÍøÕ¾µØͼ