<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                **Import name:**?jinja2.ext.i18n Jinja2 當前只附帶一個擴展,就是 i18n 擴展。它可以與?[gettext](http://docs.python.org/dev/library/gettext)?或?[babel](http://babel.edgewall.org/)?聯合使用。如果啟用了 i18n 擴展, Jinja2 提供了?trans?語句來標記被其包裹的 字符串為可翻譯的,并調用?gettext?。 在啟用虛擬的?_?函數后,之后的?gettext?調用會被添加到環境的全局變量。那么 一個國際化的應用應該不僅在全局,以及在每次渲染中在命名空間中提供至少一個?gettext?或可選的ngettext?函數。 ### 環境方法[](http://docs.jinkan.org/docs/jinja2/extensions.html#id3 "Permalink to this headline") 在啟用這個擴展后,環境提供下面的額外方法: jinja2.Environment.install_gettext_translations(*translations*,?*newstyle=False*)[](http://docs.jinkan.org/docs/jinja2/extensions.html#jinja2.Environment.install_gettext_translations "Permalink to this definition") 在該環境中全局安裝翻譯。提供的翻譯對象要至少實現?uggettext?和?ungettext?。gettext.NullTranslations?和?gettext.GNUTranslations?類和?[Babel](http://babel.edgewall.org/)‘s 的?Translations?類也被支持。 Changed in version 2.5:?添加了新樣式的 gettext jinja2.Environment.install_null_translations(*newstyle=False*)[](http://docs.jinkan.org/docs/jinja2/extensions.html#jinja2.Environment.install_null_translations "Permalink to this definition") 安裝虛擬的 gettext 函數。這在你想使應用為國際化做準備但還不想實現完整的 國際化系統時很有用。 Changed in version 2.5:?添加了新樣式的 gettext jinja2.Environment.install_gettext_callables(*gettext*,?*ngettext*,*newstyle=False*)[](http://docs.jinkan.org/docs/jinja2/extensions.html#jinja2.Environment.install_gettext_callables "Permalink to this definition") 在環境中把給出的?gettext?和?ngettext?可調用量安裝為全局變量。它們 應該表現得幾乎與標準庫中的?gettext.ugettext()?和?gettext.ungettext()?函數相同。 如果激活了?新樣式?,可調用量被包裝為新樣式的可調用量一樣工作。更多 信息見?[*新樣式 Gettext*](http://docs.jinkan.org/docs/jinja2/extensions.html#newstyle-gettext)?。 New in version 2.5. jinja2.Environment.uninstall_gettext_translations()[](http://docs.jinkan.org/docs/jinja2/extensions.html#jinja2.Environment.uninstall_gettext_translations "Permalink to this definition") 再次卸載翻譯。 jinja2.Environment.extract_translations(*source*)[](http://docs.jinkan.org/docs/jinja2/extensions.html#jinja2.Environment.extract_translations "Permalink to this definition") 從給定的模板或源中提取本地化字符串。 對找到的每一個字符串,這個函數生產一個?(lineno,?function,?message?)?元組,在這里: * lineno?是這個字符串所在行的行號。 * function?是?gettext?函數使用的名稱(如果字符串是從內嵌的 Python 代碼中抽取的)。 * message?是字符串本身(一個?unicode?對象,在函數有多個字符串參數 時是一個unicode?對象的元組)。 如果安裝了?[Babel](http://babel.edgewall.org/)?,?[*Babel 集成*](http://docs.jinkan.org/docs/jinja2/integration.html#babel-integration)?可以用來為 babel 抽取字符串。 對于一個對多種語言可用而對所有用戶給出同一種的語言的 web 應用(例如一個法國社 區安全了一個多種語言的論壇軟件)可能會一次性加載翻譯并且在環境生成時把翻譯方 法添加到環境上: ~~~ translations = get_gettext_translations() env = Environment(extensions=['jinja2.ext.i18n']) env.install_gettext_translations(translations) ~~~ get_get_translations?函數會返回當前配置的翻譯器。(比如使用?gettext.find?) 模板設計者的?i18n?擴展使用在?[*模板文檔*](http://docs.jinkan.org/docs/jinja2/templates.html#i18n-in-templates)?中有描述。 ### 新樣式 Gettext[](http://docs.jinkan.org/docs/jinja2/extensions.html#newstyle-gettext "Permalink to this headline") New in version 2.5. 從版本 2.5 開始你可以使用新樣式的 gettext 調用。這些的啟發源于 trac 的內部 gettext 函數并且完全被 babel 抽取工具支持。如果你不使用 Babel 的抽取工具, 它可能不會像其它抽取工具預期的那樣工作。 標準 gettext 調用和新樣式的 gettext 調用有什么區別?通常,它們要輸入的東西 更少,出錯率更低。并且如果在自動轉義環境中使用它們,它們也能更好地支持自動 轉義。這里是一些新老樣式調用的差異: 標準 gettext: ~~~ {{ gettext('Hello World!') }} {{ gettext('Hello %(name)s!')|format(name='World') }} {{ ngettext('%(num)d apple', '%(num)d apples', apples|count)|format( num=apples|count )}} ~~~ 新樣式看起來是這樣: ~~~ {{ gettext('Hello World!') }} {{ gettext('Hello %(name)s!', name='World') }} {{ ngettext('%(num)d apple', '%(num)d apples', apples|count) }} ~~~ 新樣式 gettext 的優勢是你需要輸入的更少,并且命名占位符是強制的。后者看起 來似乎是缺陷,但解決了當翻譯者不能切換兩個占位符的位置時經常勉勵的一大堆 麻煩。使用新樣式的 gettext ,所有的格式化字符串看起來都一樣。 除此之外,在新樣式 gettext 中,如果沒有使用占位符,字符串格式化也會被使用, 這使得所有的字符串表現一致。最后,不僅是新樣式的 gettext 調用可以妥善地為 解決了許多轉義相關問題的自動轉義標記字符串,許多模板也在使用自動轉義時體驗 了多次。
                  <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>

                              哎呀哎呀视频在线观看