{"id":806,"date":"2025-06-12T00:09:13","date_gmt":"2025-06-11T16:09:13","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/laravel\/806.html"},"modified":"2025-06-12T00:09:13","modified_gmt":"2025-06-11T16:09:13","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-laravel-%e4%b8%ad%e5%88%9b%e5%bb%ba%e5%8f%af%e6%9c%ac%e5%9c%b0%e5%8c%96%ef%bc%88i18n%ef%bc%89%e7%9a%84%e8%b7%af%e7%94%b1","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/806.html","title":{"rendered":"\u5982\u4f55\u5728 Laravel \u4e2d\u521b\u5efa\u53ef\u672c\u5730\u5316\uff08i18n\uff09\u7684\u8def\u7531"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">Bug&#32534;&#35793;&#29422;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312; Laravel &#20013;&#21019;&#24314;&#21487;&#26412;&#22320;&#21270;&#30340;&#36335;&#30001;&#65292;&#21487;&#20197;&#25353;&#29031;&#20197;&#19979;&#27493;&#39588;&#36827;&#34892;&#65306;<\/p>\n<h3>1. &#23433;&#35013;&#21644;&#37197;&#32622; Laravel<\/h3>\n<p>&#39318;&#20808;&#65292;&#30830;&#20445;&#20320;&#24050;&#32463;&#23433;&#35013;&#20102; Laravel&#12290;&#22914;&#26524;&#27809;&#26377;&#23433;&#35013;&#65292;&#21487;&#20197;&#36890;&#36807; Composer &#36827;&#34892;&#23433;&#35013;&#65306;<\/p>\n<pre><code class=\"language-bash\">composer create-project --prefer-dist laravel\/laravel my-laravel-app\ncd my-laravel-app<\/code><\/pre>\n<h3>2. &#21019;&#24314;&#35821;&#35328;&#21253;&#30446;&#24405;<\/h3>\n<p>Laravel &#20351;&#29992;&#35821;&#35328;&#21253;&#26469;&#31649;&#29702;&#19981;&#21516;&#22269;&#23478;&#30340;&#35821;&#35328;&#23383;&#31526;&#20018;&#12290;&#40664;&#35748;&#24773;&#20917;&#19979;&#65292;Laravel &#30340;&#35821;&#35328;&#21253;&#20301;&#20110; <code>resources\/lang<\/code> &#30446;&#24405;&#19979;&#12290;<\/p>\n<h3>3. &#28155;&#21152;&#35821;&#35328;&#25991;&#20214;<\/h3>\n<p>&#22312; <code>resources\/lang<\/code> &#30446;&#24405;&#19979;&#21019;&#24314;&#19968;&#20010;&#26032;&#30340;&#35821;&#35328;&#25991;&#20214;&#65292;&#20363;&#22914; <code>en.json<\/code> &#21644; <code>zh-CN.json<\/code>&#12290;&#36825;&#20123;&#25991;&#20214;&#23558;&#21253;&#21547;&#20320;&#30340;&#26412;&#22320;&#21270;&#23383;&#31526;&#20018;&#12290;<\/p>\n<h4>&#31034;&#20363;&#65306;en.json<\/h4>\n<pre><code class=\"language-json\">{\n    \"hello\": \"Hello, World!\"\n}<\/code><\/pre>\n<h4>&#31034;&#20363;&#65306;zh-CN.json<\/h4>\n<pre><code class=\"language-json\">{\n    \"hello\": \"&#20320;&#22909;&#65292;&#19990;&#30028;&#65281;\"\n}<\/code><\/pre>\n<h3>4. &#37197;&#32622;&#35821;&#35328;&#21253;<\/h3>\n<p>&#32534;&#36753; <code>config\/app.php<\/code> &#25991;&#20214;&#20013;&#30340; <code>locale<\/code> &#35774;&#32622;&#65292;&#25351;&#23450;&#40664;&#35748;&#30340;&#35821;&#35328;&#21253;&#65306;<\/p>\n<pre><code class=\"language-php\">'locale' =&gt; 'en',<\/code><\/pre>\n<h3>5. &#25351;&#23450;&#35821;&#35328;&#21253;<\/h3>\n<p>&#20320;&#21487;&#20197;&#36890;&#36807; URL &#21442;&#25968;&#25351;&#23450;&#19981;&#21516;&#30340;&#35821;&#35328;&#21253;&#12290;&#20363;&#22914;&#65292;&#22914;&#26524;&#20320;&#24819;&#20351;&#29992;&#20013;&#25991;&#35821;&#35328;&#21253;&#65292;&#21487;&#20197;&#22312; URL &#20013;&#28155;&#21152; <code>?locale=zh-CN<\/code>&#12290;<\/p>\n<pre><code class=\"language-http\">https:\/\/example.com\/hello?locale=zh-CN<\/code><\/pre>\n<h3>6. &#21019;&#24314;&#36335;&#30001;<\/h3>\n<p>&#22312;&#25511;&#21046;&#22120;&#20013;&#20351;&#29992; <code>translate<\/code> &#26041;&#27861;&#26469;&#33719;&#21462;&#26412;&#22320;&#21270;&#23383;&#31526;&#20018;&#12290;&#20363;&#22914;&#65306;<\/p>\n<pre><code class=\"language-php\">namespace AppHttpControllers;\n\nuse IlluminateHttpRequest;\nuse AppServicesTranslationService;\n\nclass HelloController extends Controller\n{\n    public function index(Request $request)\n    {\n        \/\/ &#33719;&#21462;&#24403;&#21069;&#35821;&#35328;&#21253;\n        $locale = $request-&gt;input('locale', app()-&gt;getLocale());\n\n        \/\/ &#20351;&#29992;&#32763;&#35793;&#26381;&#21153;&#33719;&#21462;&#26412;&#22320;&#21270;&#23383;&#31526;&#20018;\n        $message = TranslationService::getMessage($locale, 'hello');\n\n        return view('welcome', compact('message'));\n    }\n}<\/code><\/pre>\n<h3>7. &#32534;&#20889;&#35270;&#22270;<\/h3>\n<p>&#22312; <code>resources\/views\/welcome.blade.php<\/code> &#25991;&#20214;&#20013;&#20351;&#29992;&#21464;&#37327;&#26174;&#31034;&#26412;&#22320;&#21270;&#23383;&#31526;&#20018;&#65306;<\/p>\n<pre><code class=\"language-html\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"{{ app()-&gt;getLocale() }}\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n    &lt;title&gt;{{ __('messages.hello') }}&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    {{ $message }}\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<h3>8. &#27979;&#35797;&#36335;&#30001;<\/h3>\n<p>&#29616;&#22312;&#65292;&#20320;&#21487;&#20197;&#35775;&#38382; <code>\/hello?locale=en<\/code> &#26469;&#26597;&#30475;&#33521;&#25991;&#29256;&#26412;&#30340;&#39029;&#38754;&#65292;&#35775;&#38382; <code>\/hello?locale=zh-CN<\/code> &#26469;&#26597;&#30475;&#20013;&#25991;&#29256;&#26412;&#30340;&#39029;&#38754;&#12290;<\/p>\n<h3>&#31034;&#20363;&#20195;&#30721;<\/h3>\n<p>&#20197;&#19979;&#26159;&#19968;&#20010;&#23436;&#25972;&#30340;&#31034;&#20363;&#20195;&#30721;&#65292;&#23637;&#31034;&#20102;&#22914;&#20309;&#22312; Laravel &#20013;&#23454;&#29616;&#21487;&#26412;&#22320;&#21270;&#30340;&#36335;&#30001;&#65306;<\/p>\n<pre><code class=\"language-php\">\/\/ routes\/web.php\nRoute::get('\/hello', [HelloController::class, 'index']);\n\n\/\/ app\/Http\/Controllers\/HelloController.php\nnamespace AppHttpControllers;\n\nuse IlluminateHttpRequest;\nuse AppServicesTranslationService;\n\nclass HelloController extends Controller\n{\n    public function index(Request $request)\n    {\n        \/\/ &#33719;&#21462;&#24403;&#21069;&#35821;&#35328;&#21253;\n        $locale = $request-&gt;input('locale', app()-&gt;getLocale());\n\n        \/\/ &#20351;&#29992;&#32763;&#35793;&#26381;&#21153;&#33719;&#21462;&#26412;&#22320;&#21270;&#23383;&#31526;&#20018;\n        $message = TranslationService::getMessage($locale, 'hello');\n\n        return view('welcome', compact('message'));\n    }\n}\n\n\/\/ app\/Services\/TranslationService.php\nnamespace AppServices;\n\nclass TranslationService\n{\n    public static function getMessage($locale, $key)\n    {\n        if (file_exists(resource_path(\"lang\/$locale\/{$key}.json\"))) {\n            return json_decode(file_get_contents(resource_path(\"lang\/$locale\/{$key}.json\")), true);\n        } else {\n            return null;\n        }\n    }\n}\n\n\/\/ resources\/lang\/en.json\n{\n    \"hello\": \"Hello, World!\"\n}\n\n\/\/ resources\/lang\/zh-CN.json\n{\n    \"hello\": \"&#20320;&#22909;&#65292;&#19990;&#30028;&#65281;\"\n}<\/code><\/pre>\n<p>&#36890;&#36807;&#20197;&#19978;&#27493;&#39588;&#65292;&#20320;&#21487;&#20197;&#22312; Laravel &#20013;&#25104;&#21151;&#21019;&#24314;&#24182;&#37197;&#32622;&#21487;&#26412;&#22320;&#21270;&#30340;&#36335;&#30001;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;Bug&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#40657;&#26495;Bug&#35762;&#24072;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<body><h3>&#20171;&#32461;<\/h3><p>&#22312;&#22810;&#35821;&#35328;&#30340;&#32593;&#32476;&#24212;&#29992;&#20013;&#65292;&#20351;&#29992;&#21453;&#26144;&#36873;&#25321;&#35821;&#35328;&#30340;URL&#21487;&#20197;&#25552;&#21319;&#29992;&#25143;&#20307;&#39564;&#24182;&#21487;&#33021;&#25913;&#21892;SEO&#12290;Laravel &#26159;&#19968;&#20010;&#27969;&#34892;&#30340;PHP&#32593;&#32476;&#24212;&#29992;&#31243;&#24207;&#26694;&#26550;&#65292;&#23427;&#25552;&#20379;&#20102;&#20840;&#38754;&#30340;&#22269;&#38469;&#21270;&#65288;i18n&#65289;&#24037;&#20855;&#21253;&#12290;&#22312;&#36825;&#31687;&#25945;&#31243;&#20013;&#65292;&#25105;&#20204;&#23558;&#23398;&#20064;&#22914;&#20309;&#20351;&#29992;Laravel&#21019;&#24314;&#20855;&#26377;&#26412;&#22320;&#21270;&#21151;&#33021;&#30340;&#22269;&#38469;&#36335;&#30001;&#12290;<\/p><h3>&#22312;Laravel&#20013;&#29702;&#35299;&#26412;&#22320;&#21270;&#65288;Localization&#65289;<\/h3><p>Laravel&#30340;&#26412;&#22320;&#21270;&#21151;&#33021;&#35753;&#20320;&#33021;&#22815;&#21019;&#24314;&#22810;&#35821;&#35328;&#32593;&#31449;&#65292;&#36890;&#36807;&#25552;&#20379;&#19968;&#31181;&#26041;&#20415;&#30340;&#26041;&#24335;&#26469;&#26816;&#32034;&#21508;&#31181;&#35821;&#35328;&#20013;&#30340;&#23383;&#31526;&#20018;&#12290;&#20026;&#20102;&#22312;&#36335;&#30001;&#20043;&#38388;&#31649;&#29702;&#35821;&#35328;&#36873;&#25321;&#65292;&#20320;&#20063;&#38656;&#35201;&#35843;&#25972;&#20320;&#30340;&#36335;&#30001;&#35774;&#35745;&#12290;&#36825;&#20351;&#24471;&#29992;&#25143;&#21487;&#20197;&#22312;&#21516;&#19968;&#39029;&#38754;&#19978;&#20999;&#25442;&#19981;&#21516;&#30340;&#35821;&#35328;&#12290;<\/p><h3>&#35774;&#32622;&#29615;&#22659;<\/h3><p>&#22312;&#21019;&#24314;&#26412;&#22320;&#21270;&#36335;&#30001;&#20043;&#21069;&#65292;&#35831;&#30830;&#20445;&#24744;&#27491;&#22312;&#36816;&#34892;&#26368;&#26032;&#29256;&#26412;&#30340;Laravel&#65292;&#24182;&#19988;&#24050;&#32463;&#21019;&#24314;&#20102;&#19968;&#20010;&#26032;&#39033;&#30446;&#25110;&#27491;&#22312;&#22788;&#29702;&#19968;&#20010;&#29616;&#26377;&#39033;&#30446;&#12290;&#22914;&#26524;&#24744;&#23578;&#26410;&#35774;&#32622;&#29615;&#22659;&#65292;&#35831;&#21442;&#38405;Laravel&#23433;&#35013;&#25991;&#26723;&#12290;<\/p><pre><code>composer create-project laravel\/laravel your_project_name\n<\/code><\/pre><h3>&#22522;&#26412;&#30340;&#26412;&#22320;&#36335;&#30001;<\/h3><p>&#39318;&#20808;&#65292;&#36890;&#36807;&#37197;&#32622;&#25991;&#20214;&#25110;&#29615;&#22659;&#21464;&#37327;&#20869;&#37096;&#23450;&#20041;&#19968;&#20010;&#25903;&#25345;&#30340;&#26102;&#21306;&#38598;&#21512;&#12290;&#22312;&#26412;&#25945;&#31243;&#20013;&#65292;&#20551;&#35774;&#25105;&#20204;&#30340;&#25903;&#25345;&#35821;&#35328;&#20026;&#33521;&#35821;&#65288;en&#65289;&#21644;&#35199;&#29677;&#29273;&#35821;&#65288;es&#65289;&#12290;&#35831;&#25171;&#24320;&lsquo;config\/app.php&rsquo;&#24182;&#28155;&#21152;&#20197;&#19979;&#20195;&#30721;&#65306;<\/p><pre><code>'supported_locales' =&gt; ['en', 'es'],\n<\/code><\/pre><p>&#22312;&#20320;&#30340; routes\/web.php &#25991;&#20214;&#20013;&#65292;&#35774;&#32622;&#19968;&#20010;&#36335;&#30001;&#32452;&#24182;&#20026;&#35821;&#35328;&#21069;&#32512;&#65306;<\/p><pre><code>Route::group(['prefix' =&gt; '{locale}'], function () {\n    Route::get('\/', function () {\n        return view('welcome');\n    });\n});\n<\/code><\/pre><p>&#29616;&#22312;&#65292;&#24744;&#30340;&#27426;&#36814;&#39029;&#38754;&#30340;&#35775;&#38382;&#36335;&#24452;&#21487;&#20197;&#36890;&#36807;&lsquo;\/en&rsquo;&#21644;&lsquo;\/es&rsquo;&#26469;&#23454;&#29616;&#65292;&#20998;&#21035;&#24102;&#26377;&#30456;&#24212;&#30340;&#35821;&#35328;&#20869;&#23481;&#12290;&#35831;&#30830;&#20445;&#24744;&#30340;&#24212;&#29992;&#33021;&#22815;&#26816;&#27979;&#24182;&#24212;&#29992;&#27491;&#30830;&#30340;&#35821;&#35328;&#12290;<\/p><h3>&#23450;&#20301;&#26816;&#27979;&#30340;&#20013;&#38388;&#20214;<\/h3><p>&#20026;&#20102;&#22788;&#29702;&#22320;&#21306;&#26816;&#27979;&#21644;&#24212;&#29992;&#31243;&#24207;&#65292;&#21487;&#20197;&#22312;Laravel&#20013;&#21019;&#24314;&#20013;&#38388;&#20214;&#12290;&#21487;&#20197;&#20351;&#29992;Artisan&#21629;&#20196;&#34892;&#24037;&#20855;&#65306;<\/p><pre><code>php artisan make:middleware LocaleMiddleware\n<\/code><\/pre><p>&#22312; handle &#26041;&#27861;&#20013;&#28155;&#21152;&#26412;&#22320;&#21270;&#26816;&#27979;&#36923;&#36753;&#65306;<\/p><pre><code>public function handle($request, Closure $next)\n{\n    $locale = $request-&gt;route('locale');\n    if (in_array($locale, config('app.supported_locales'))) {\n        app()-&gt;setLocale($locale);\n    }\n    return $next($request);\n}\n<\/code><\/pre><p>&#22312; app\/Http\/Kernel.php &#25991;&#20214;&#30340; $routeMiddleware &#25968;&#32452;&#20013;&#27880;&#20876;&#20013;&#38388;&#20214;&#65306;<\/p><pre><code>'setlocale' =&gt; AppHttpMiddlewareLocaleMiddleware::class,\n<\/code><\/pre><p>&#24212;&#29992;&#25105;&#20204;&#30340;&#26032;&lsquo;setlocale&rsquo;&#20013;&#38388;&#20214;&#21040;&#26412;&#22320;&#21270;&#36335;&#30001;&#32452;&#65306;<\/p><pre><code>Route::group(['prefix' =&gt; '{locale}', 'middleware' =&gt; 'setlocale'], function() {\n    \/\/ Your localized routes go here\n});\n<\/code><\/pre><h3>&#29983;&#25104;&#26412;&#22320;&#21270;URL<\/h3><p>&#20351;&#29992;&#36335;&#30001;&#26412;&#22320;&#21270;&#26102;&#65292;&#24744;&#36890;&#24120;&#38656;&#35201;&#29983;&#25104;&#20855;&#26377;&#36866;&#24403;&#26412;&#22320;&#21270;&#30340;URL&#12290;Laravel&#20801;&#35768;&#24744;&#20351;&#29992;&ldquo;route&rdquo;&#20989;&#25968;&#29983;&#25104;URL&#65306;<\/p><pre><code>$localizedUrl = route('your_route_name', ['locale' =&gt; app()-&gt;getLocale()]);\n<\/code><\/pre><p>&#20026;&#20102;&#20445;&#25345;&#27169;&#26495;&#30340;&#25972;&#27905;&#65292;&#35831;&#32771;&#34385;&#21019;&#24314;&#19968;&#20010;&#36741;&#21161;&#20989;&#25968;&#26469;&#22788;&#29702;&#36825;&#19968;&#21151;&#33021;&#12290;<\/p><h3>&#39640;&#32423;&#36335;&#32447;&#23450;&#20301;<\/h3><p>&#20026;&#20102;&#23454;&#29616;&#26356;&#31934;&#32454;&#30340;&#25511;&#21046;&#65292;&#32771;&#34385;&#23545;&#20010;&#21035;&#36335;&#32447;&#21517;&#31216;&#36827;&#34892;&#26412;&#22320;&#21270;&#22788;&#29702;&#65292;&#24182;&#30830;&#20445;&#20174;&#21629;&#21517;&#36335;&#32447;&#36820;&#22238;&#26102;&#23562;&#37325;&#25152;&#36873;&#30340;&#26041;&#35328;&#25110;&#22320;&#21306;&#35774;&#32622;&#12290;<\/p><p>&#20320;&#21487;&#20197;&#36825;&#26679;&#23450;&#20041;&#21629;&#21517;&#36335;&#30001;&#65306;<\/p><pre><code>Route::group(['prefix' =&gt; '{locale}', 'as' =&gt; '{locale}.'], function() {\n    Route::get('\/contact', function () {\n        \/\/ Contact page logic\n    })-&gt;name('contact');\n\n    \/\/ More localized routes\n});\n<\/code><\/pre><p>&#25353;&#29031;&#36825;&#31181;&#26041;&#24335;&#65292;&#20320;&#21487;&#20197;&#36890;&#36807;&#20351;&#29992;&#35821;&#35328;&#21069;&#32512;&#26469;&#24341;&#29992;&#36335;&#30001;&#65292;&#20363;&#22914;&#65306;<\/p><pre><code>$localizedContactUrl = route(app()-&gt;getLocale().'.contact');\n<\/code><\/pre><h3>&#26412;&#22320;&#21270;&#24320;&#20851;<\/h3><p>&#20026;&#20102;&#24110;&#21161;&#29992;&#25143;&#22312;&#24212;&#29992;&#24067;&#23616;&#20013;&#20999;&#25442;&#35821;&#35328;&#65292;&#20320;&#21487;&#20197;&#21019;&#24314;&#19968;&#20010;&#35821;&#35328;&#20999;&#25442;&#22120;&#12290;&#36941;&#21382;&#25903;&#25345;&#30340;&#35821;&#35328;&#21644;&#22320;&#21306;&#65292;&#29983;&#25104;&#20999;&#25442;&#38142;&#25509;&#65306;<\/p><pre><code>&lt;nav&gt;\n@foreach(config('app.supported_locales') as $locale)\n    &lt;a href=\"{{ route(Route::currentRouteName(), $locale) }}\"&gt;{{ strtoupper($locale) }}&lt;\/a&gt;\n@endforeach\n&lt;\/nav&gt;\n<\/code><\/pre><p>&#30830;&#20445;&#22312;&#24403;&#21069;&#36335;&#30001;&#26410;&#21629;&#21517;&#25110;locale&#21442;&#25968;&#19981;&#24517;&#35201;&#26102;&#65292;&#21253;&#21547;&#36923;&#36753;&#22788;&#29702;&#26426;&#21046;&#12290;<\/p><h3>&#22522;&#20110;&#25968;&#25454;&#24211;&#30340;&#36335;&#30001;&#32763;&#35793;<\/h3><p>&#22914;&#26524;&#24744;&#30340;&#24212;&#29992;&#31243;&#24207;&#38656;&#35201;&#26681;&#25454;&#23384;&#20648;&#30340;&#20869;&#23481;&#36827;&#34892;&#21160;&#24577;&#36335;&#30001;&#32763;&#35793;&#65292;&#21487;&#20197;&#32771;&#34385;&#38598;&#25104;&#19968;&#20010;&#21253;&#25110;&#23454;&#29616;&#19968;&#20010;&#25511;&#21046;&#22120;&#26469;&#35299;&#26512;&#26412;&#22320;&#21270;slug&#20197;&#26144;&#23556;&#21040;&#27169;&#22411;&#23454;&#20363;&#12290;&#20363;&#22914;&#65306;<\/p><pre><code>Route::get('{locale}\/{slug}', 'ContentController@show');\n<\/code><\/pre><p>ContentController@show &#26041;&#27861;&#20250;&#26681;&#25454;&#35821;&#35328;&#26597;&#25214; slug &#24182;&#36820;&#22238;&#36866;&#24403;&#30340;&#35270;&#22270;&#21644;&#20869;&#23481;&#12290;<\/p><h3>&#32467;&#35770;&#12290;<\/h3><p>&#22312;Laravel&#24212;&#29992;&#31243;&#24207;&#20013;&#26412;&#22320;&#21270;&#36335;&#30001;&#19981;&#20165;&#23545;&#29992;&#25143;&#20307;&#39564;&#26377;&#30410;&#65292;&#32780;&#19988;&#19982;&#26694;&#26550;&#25552;&#20379;&#30340;&#24378;&#22823;&#26412;&#22320;&#21270;&#21151;&#33021;&#30456;&#36741;&#30456;&#25104;&#12290;&#27491;&#22914;&#25105;&#20204;&#25152;&#35265;&#65292;&#36890;&#36807;&#20351;&#29992;&#23569;&#37327;&#20013;&#38388;&#20214;&#21644;&#31934;&#24515;&#35774;&#35745;&#30340;&#36335;&#30001;&#32422;&#23450;&#65292;Laravel&#20351;&#24471;&#21487;&#20197;&#26080;&#32541;&#22320;&#23558;&#22269;&#38469;&#21270;&#36335;&#30001;&#38598;&#25104;&#21040;&#24744;&#30340;&#24212;&#29992;&#20013;&#12290;<\/p><\/body>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--3\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/xygcfznnzczhsdmwydzhsmzzzmddnq-400x300.jpg\" alt=\"&#38271;&#24037;&#30721;&#22900;1523\" class=\"wp-image-2906\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#38271;&#24037;&#30721;&#22900;1523<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312; Laravel &#20013;&#21019;&#24314;&#21487;&#26412;&#22320;&#21270;&#30340;&#36335;&#30001;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992; Laravel &#30340;&#22269;&#38469;&#21270; (i18n) &#21151;&#33021;&#12290;&#36825;&#23558;&#24110;&#21161;&#20320;&#22312;&#19981;&#21516;&#30340;&#35821;&#35328;&#29615;&#22659;&#20013;&#25552;&#20379;&#19968;&#33268;&#30340;&#29992;&#25143;&#20307;&#39564;&#12290;<\/p>\n<h3>1. &#23433;&#35013; Laravel &#30340; i18n &#25903;&#25345;<\/h3>\n<p>&#39318;&#20808;&#65292;&#30830;&#20445;&#20320;&#24050;&#23433;&#35013;&#20102; Laravel&#65292;&#24182;&#19988;&#24050;&#32463;&#27491;&#30830;&#37197;&#32622;&#20102;&#29615;&#22659;&#21464;&#37327;&#12290;&#28982;&#21518;&#65292;&#36816;&#34892;&#20197;&#19979;&#21629;&#20196;&#26469;&#23433;&#35013; i18n&#65306;<\/p>\n<pre><code class=\"language-bash\">composer require laravel\/laravel-i18n<\/code><\/pre>\n<h3>2. &#21019;&#24314;&#22269;&#38469;&#21270;&#25991;&#20214; (.po &#25991;&#20214;)<\/h3>\n<p>&#20320;&#38656;&#35201;&#20026;&#27599;&#20010;&#35821;&#35328;&#28155;&#21152; .po &#25991;&#20214;&#12290;&#36825;&#20123;&#25991;&#20214;&#26159; Laravel i18n &#30340;&#26680;&#24515;&#12290;&#23427;&#20204;&#29992;&#20110;&#23384;&#20648;&#21644;&#31649;&#29702;&#21508;&#31181;&#23383;&#31526;&#20018;&#25968;&#25454;&#12290;<\/p>\n<ul>\n<li>&#22312;&#39033;&#30446;&#30340; <code>resources\/lang<\/code> &#30446;&#24405;&#19979;&#65292;&#21019;&#24314;&#19968;&#20010;&#21517;&#20026; <code>en<\/code> &#30340;&#25991;&#20214;&#22841;&#12290;<\/li>\n<li>&#22312; <code>en<\/code> &#25991;&#20214;&#22841;&#20869;&#65292;&#21019;&#24314; <code>.po<\/code> &#25991;&#20214;&#65292;&#20363;&#22914; <code>en\/strings.po<\/code>&#12290;<\/li>\n<li>&#28155;&#21152;&#20320;&#30340;&#23383;&#31526;&#20018;&#21040;&#36825;&#20010;&#25991;&#20214;&#12290;&#20363;&#22914;&#65306;\n<pre><code class=\"language-plaintext\">\"name\": \"John Doe\",\n\"age\": 30,<\/code><\/pre><\/li>\n<\/ul>\n<h3>3. &#32534;&#36753; .env &#25991;&#20214;<\/h3>\n<p>&#22312;&#39033;&#30446;&#26681;&#30446;&#24405;&#19979;&#30340; <code>.\/config\/app.php<\/code> &#25991;&#20214;&#20013;&#65292;&#25214;&#21040;&#25110;&#32534;&#36753; <code>app.i18n.translations<\/code> &#35774;&#32622;&#65292;&#23558;&#20854;&#26367;&#25442;&#20026;&#20320;&#21018;&#21019;&#24314;&#30340; <code>.po<\/code> &#25991;&#20214;&#36335;&#24452;&#12290;&#20363;&#22914;&#65306;<\/p>\n<pre><code class=\"language-php\">'app.i18n.translations' =&gt; __DIR__ . '\/lang',<\/code><\/pre>\n<p>&#36825;&#24847;&#21619;&#30528;&#29616;&#22312;&#20320;&#30340;&#24212;&#29992;&#31243;&#24207;&#21487;&#20197;&#35775;&#38382;&#20219;&#20309; <code>.po<\/code> &#25991;&#20214;&#65292;&#21482;&#35201;&#23427;&#20301;&#20110;&#24403;&#21069;&#30446;&#24405;&#21450;&#20854;&#23376;&#30446;&#24405;&#20043;&#19979;&#21363;&#21487;&#12290;<\/p>\n<h3>4. &#37197;&#32622; Laravel<\/h3>\n<p>&#25171;&#24320;&#39033;&#30446;&#30340; <code>config\/app.php<\/code> &#25991;&#20214;&#24182;&#28155;&#21152;&#20197;&#19979;&#20195;&#30721;&#20197;&#21551;&#29992; Laravel &#30340;&#22269;&#38469;&#21270;&#25903;&#25345;&#65306;<\/p>\n<pre><code class=\"language-php\">'middleware' =&gt; [\n    'web' =&gt; ['throttle:60,1'],\n],\n\n'aliases' =&gt; [\n    \/\/...\n    'translator' =&gt; Translator::class,\n],<\/code><\/pre>\n<p>&#25509;&#19979;&#26469;&#65292;&#21551;&#21160;&#24212;&#29992;&#24182;&#26816;&#26597;&#26159;&#21542;&#33021;&#26174;&#31034;&#27491;&#30830;&#30340;&#35821;&#35328;&#36873;&#25321;&#22120;&#12290;<\/p>\n<h3>5. &#27979;&#35797;<\/h3>\n<p>&#27979;&#35797;&#19968;&#19979; Laravel &#26159;&#21542;&#33021;&#27491;&#30830;&#22788;&#29702;&#29992;&#25143;&#20174;&#27983;&#35272;&#22120;&#36873;&#25321;&#30340;&#35821;&#35328;&#12290;&#22312;&#27983;&#35272;&#22120;&#22320;&#22336;&#26639;&#36755;&#20837; <code>http:\/\/yourdomain.com\/yourlanguage\/<\/code>&#65292;&#20320;&#24212;&#35813;&#33021;&#30475;&#21040;&#30456;&#24212;&#30340;&#35821;&#35328;&#36873;&#25321;&#33756;&#21333;&#12290;<\/p>\n<p>&#36890;&#36807;&#20197;&#19978;&#27493;&#39588;&#65292;&#20320;&#29616;&#22312;&#21487;&#20197;&#22312; Laravel &#24212;&#29992;&#31243;&#24207;&#20013;&#36731;&#26494;&#22320;&#23454;&#29616;&#26412;&#22320;&#21270;&#21151;&#33021;&#65292;&#20351;&#20320;&#30340;&#24212;&#29992;&#31243;&#24207;&#33021;&#22815;&#26681;&#25454;&#29992;&#25143;&#30340;&#22320;&#29702;&#20301;&#32622;&#33258;&#21160;&#35843;&#25972;&#20854;&#30028;&#38754;&#21644;&#20869;&#23481;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312; Laravel &#20013;&#21019;&#24314;&#21487;&#26412;&#22320;&#21270;&#30340;&#36335;&#30001;&#65292;&#21487;&#20197;&#25353;&#038;#2..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[44],"tuisongtax":[],"class_list":["post-806","my1js","type-my1js","status-publish","hentry","my1js2nav-laravel"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/806","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=806"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=806"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=806"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}