<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國際加速解決方案。 廣告
                # 本土化 - [簡介](#introduction) - [提取語句](#retrieving-language-lines) - [語句中的參數替換](#replacing-parameters-in-language-lines) - [復數](#pluralization) - [重寫擴展包的語言包](#overriding-package-language-files) <a name="introduction"></a> ## 簡介 Laravel 的本地化功能提供方便的方法來獲取多語言的字符串,讓你的網站可以簡單的支持多語言。 語言包存放在 `resources/lang` 目錄下的文件里。在此目錄中應該有應用對應支持的語言并將其對應到每一個子目錄: /resources /lang /en messages.php /es messages.php 語言包簡單地返回鍵值和字符串數組,例如: <?php return [ 'welcome' => 'Welcome to our application' ]; ### 切換語言 應用的默認語言保存在 `config/app.php` 配置文件中。當然,你可以根據需求自由的修改當前設置,可以使用 `App` facade 的 `setLocale` 方法動態地更改現有語言: Route::get('welcome/{locale}', function ($locale) { App::setLocale($locale); // }); 你也可以設置 「備用語言」 ,它將會在當現有語言沒有指定語句時被使用。就像默認語言那樣,備用語言也可以在 `config/app.php` 配置文件設置: 'fallback_locale' => 'en', #### 指定當前語言 你可以使用 `App` facade 的 `getLocale` 及 `isLocale` 方法指定當前的語言環境或者檢驗當前語言是否是給定的值: $locale = App::getLocale(); if (App::isLocale('en')) { // } <a name="retrieving-language-lines"></a> ## 提取語句 你可以使用 `trans` 輔助函數來獲取語言字符串,`trans` 方法接受文件名和鍵值作為其第一個參數。例如,讓我們提取 `resources/lang/messages.php` 中的 `welcome` : echo trans('messages.welcome'); 當然,如果你使用 [Blade 模板引擎](/docs/{{version}}/blade), 那么你可以在視圖文件中使用 `{{ }}` 語法或者使用 `@lang` 命令來輸出語句: {{ trans('messages.welcome') }} @lang('messages.welcome') 如果指定的語句不存在,`trans` 方法則會簡單的返回這個鍵名。所以,如果上述示例中的鍵不存在,那么 `trans` 方法則會返回 `messages.welcome` 。 <a name="replacing-parameters-in-language-lines"></a> ### 語句中的參數替換 如果需要,你也可以在語句中定義占位符。所有的占位符都使用的 `:` 開頭。例如,你可以自定義一則歡迎消息的占位符: 'welcome' => 'Welcome, :name', 你可以在 `trans` 方法中傳遞一個數組作為第二個參數,它會將數組的值替換到語言內容的占位符中: echo trans('messages.welcome', ['name' => 'dayle']); 如果你的占位符中包含了首字母大寫或者全體大寫,翻譯過來的內容也會相應的做相應的處理: 'welcome' => 'Welcome, :NAME', // Welcome, DAYLE 'goodbye' => 'Goodbye, :Name', // Goodbye, Dayle <a name="pluralization"></a> ### 復數 復數是個復雜的問題,不同語言對于復數有不同的規則。使用管道符 `|` ,可以區分單復數字符串格式: 'apples' => 'There is one apple|There are many apples', 接著,你可以使用 `trans_choice` 方法來設置總數。例如,當總數大于一時將會獲取復數語句: echo trans_choice('messages.apples', 10); 因為 laravel 的翻譯器是基于 Symfony 翻譯擴展包的,因此你甚至可以使用更復雜的復數規則: 'apples' => '{0} There are none|[1,19] There are some|[20,Inf] There are many', <a name="overriding-package-language-files"></a> ## 重寫擴展包的語言包 部分擴展包帶有自己的語言包,你可以通過在 `resources/lang/vendor/{package}/{locale}` 放置文件來重寫它們,而不是直接修改擴展包的核心文件。 例如,你需要重寫 `skyrim/hearthfire` 擴展包的英文語言包 `messages.php` ,則需要把文件放置在 `resources/lang/vendor/hearthfire/en/messages.php` 。所有沒有重寫的語句仍將會從擴展包的語言包中被加載。 ## 譯者署名 | 用戶名 | 頭像 | 職能 | 簽名 | |---|---|---|---| | [@江邊望海](http://blog.jiangbianwanghai.com) | <img class="avatar-66 rm-style" src="https://dn-phphub.qbox.me/uploads/avatars/5306_1470714129.jpeg?imageView2/1/w/100/h/100"> | 翻譯 | 鄭州悉知資深技術經理、講師,10多年軟件產品研發、測試、咨詢及管理工作經驗。Follow me [@jiangbianwanghai](https://github.com/jiangbianwanghai/) at Github | | [@summerblue](https://github.com/summerblue) | <img class="avatar-66 rm-style" src="https://avatars2.githubusercontent.com/u/324764?v=3&s=100"> | Review | A man seeking for Wisdom. |
                  <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>

                              哎呀哎呀视频在线观看