<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ### **1、簡介** [Laravel](http://laravelacademy.org/tags/laravel "View all posts in Laravel")?的[本地化](http://laravelacademy.org/tags/%e6%9c%ac%e5%9c%b0%e5%8c%96 "View all posts in 本地化")特性允許你在應用中輕松實現多種語言支持。 語言字符串默認存放在`resources/lang`目錄中,在該目錄中應該包含應用支持的每種語言的子目錄: ~~~ /resources /lang /en messages.php /es messages.php ~~~ 所有語言文件都返回一個鍵值對數組,例如: ~~~ <?php return [ 'welcome' => 'Welcome to our application' ]; ~~~ ##### **配置Locale選項** 應用默認語言存放在配置文件`config/app.php`中,當然,你可以修改該值來匹配應用需要。你還可以在運行時使用`App`[門面](http://laravelacademy.org/post/2920.html)上的`setLocale`方法改變當前語言: ~~~ Route::get('welcome/{locale}', function ($locale) { App::setLocale($locale); // }); ~~~ 你還可以配置一個“備用語言”,當當前語言不包含給定語言行時備用語言被返回。和默認語言一樣,備用語言也在配置文件`config/app.php`中配置: ~~~ 'fallback_locale' => 'en', ~~~ ### **2、基本使用** 你可以使用幫助函數`trans`從語言文件中獲取行,該方法接收文件和語言行的鍵作為第一個參數,例如,讓我們在語言文件`resources/lang/messages.php`中獲取語言行`welcome`: ~~~ echo trans('messages.welcome'); ~~~ 當然如果你使用[Blade模板引擎](http://laravelacademy.org/post/2865.html),可以使用`{{ }}`語法打印語言行: ~~~ {{ trans('messages.welcome') }} ~~~ 如果指定的語言行不存在,`trans`函數將返回語言行的鍵,所以,使用上面的例子,如果語言行不存在的話,`trans`函數將返回`messages.welcome`。 ##### **替換語言行中的參數** 如果需要的話,你可以在語言行中定義占位符,所有的占位符都有一個:前綴,例如,你可以用占位符名稱定義一個`welcome`消息: ~~~ 'welcome' => 'Welcome, :name', ~~~ 要在獲取語言行的時候替換占位符,傳遞一個替換數組作為`trans`函數的第二個參數: ~~~ echo trans('messages.welcome', ['name' => 'Dayle']); ~~~ #### **多元化** 多元化是一個復雜的問題,因為不同語言對多元化有不同的規則,通過使用管道字符“|”,你可以區分一個字符串的單數和復數形式: ~~~ 'apples' => 'There is one apple|There are many apples', ~~~ 然后,你可以使用`trans_choice`函數獲取給定行數的語言行,在本例中,由于行數大于1,將會返回語言行的復數形式: ~~~ echo trans_choice('messages.apples', 10); ~~~ Laravel?[翻譯](http://laravelacademy.org/tags/%e7%bf%bb%e8%af%91 "View all posts in 翻譯")器由?[Symfony](http://laravelacademy.org/tags/symfony "View all posts in Symfony")?翻譯組件提供,因此你可以創建更復雜的多元化規則: ~~~ 'apples' => '{0} There are none|[1,19] There are some|[20,Inf] There are many', ~~~ ### **3、覆蓋Vendor包的語言文件** 有些包可以處理自己的語言文件。你可以通過將自己的文件放在`resources/lang/vendor/{package}/{locale}`目錄下來覆蓋它們而不是破壞這些包的核心文件來調整這些句子。 所以,舉個例子,如果你需要覆蓋名為`skyrim/hearthfire`的包中的`messages.php`文件里的英文句子,可以創建一個`resources/lang/vendor/hearthfire/en/messages.php`文件。在這個文件中只需要定義你想要覆蓋的句子,你沒有覆蓋的句子仍然從該包原來的語言文件中加載。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看