<legend id='sh1VM'><style id='sh1VM'><dir id='sh1VM'><q id='sh1VM'></q></dir></style></legend>

      <small id='sh1VM'></small><noframes id='sh1VM'>

        • <bdo id='sh1VM'></bdo><ul id='sh1VM'></ul>

        <tfoot id='sh1VM'></tfoot>
      1. <i id='sh1VM'><tr id='sh1VM'><dt id='sh1VM'><q id='sh1VM'><span id='sh1VM'><b id='sh1VM'><form id='sh1VM'><ins id='sh1VM'></ins><ul id='sh1VM'></ul><sub id='sh1VM'></sub></form><legend id='sh1VM'></legend><bdo id='sh1VM'><pre id='sh1VM'><center id='sh1VM'></center></pre></bdo></b><th id='sh1VM'></th></span></q></dt></tr></i><div id='sh1VM'><tfoot id='sh1VM'></tfoot><dl id='sh1VM'><fieldset id='sh1VM'></fieldset></dl></div>
      2. 编程多语言 PHP 应用程序

        时间:2023-10-03
          <tbody id='YgQXm'></tbody>

          <bdo id='YgQXm'></bdo><ul id='YgQXm'></ul>
          <tfoot id='YgQXm'></tfoot>
          <legend id='YgQXm'><style id='YgQXm'><dir id='YgQXm'><q id='YgQXm'></q></dir></style></legend>
            <i id='YgQXm'><tr id='YgQXm'><dt id='YgQXm'><q id='YgQXm'><span id='YgQXm'><b id='YgQXm'><form id='YgQXm'><ins id='YgQXm'></ins><ul id='YgQXm'></ul><sub id='YgQXm'></sub></form><legend id='YgQXm'></legend><bdo id='YgQXm'><pre id='YgQXm'><center id='YgQXm'></center></pre></bdo></b><th id='YgQXm'></th></span></q></dt></tr></i><div id='YgQXm'><tfoot id='YgQXm'></tfoot><dl id='YgQXm'><fieldset id='YgQXm'></fieldset></dl></div>

            <small id='YgQXm'></small><noframes id='YgQXm'>

                  本文介绍了编程多语言 PHP 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在开发一个 PHP 应用程序,我想知道为其他国家/地区的用户提供多语言支持的最佳方式.

                  I'm developing a PHP application and I'm wondering about the best way to include multi-language support for users in other countries.

                  我精通 PHP,但从未开发过支持其他语言的任何东西.

                  I'm proficient with PHP but have never developed anything with support for other languages.

                  我正在考虑将语言放入带有常量的 PHP 文件中,例如:

                  I was thinking of putting the language into a PHP file with constants, example:

                  en.php 可以包含:

                  en.php could contain:

                  define('HZ_DB_CONN_ERR', 'There was an error connecting to the database.');
                  

                  和 fr.php 可以包含:

                  and fr.php could contain:

                  define('HZ_DB_CONN_ERR', 'whatever the french is for the above...');
                  

                  然后我可以调用一个函数并自动传入正确的语言.

                  I could then call a function and automatically have the correct language passed in.

                  hz_die('HZ_DB_CONN_ERR', $this);
                  

                  这是解决问题的好方法吗?

                  Is this a good way of going about it?

                  -- morristhebear.

                  -- morristhebear.

                  推荐答案

                  奇怪.人们似乎忽略了显而易见的解决方案.您对特定于语言环境的文件的想法很好.有en.php:

                  Weird. People seem to be ignoring the obvious solution. Your idea of locale-specific files is fine. Have en.php:

                  define('LOGIN_INCORRECT','Your login details are incorrect.');
                  ...
                  

                  然后,假设您有一个全局配置/常量文件(出于多种原因,我建议这样做),请使用如下代码:

                  Then, assuming you have a global config/constants file (which I'd suggest for many reasons), have code like this:

                  if ($language == 'en') {
                    reqire_once 'en.php';
                  } else if ($language == 'de') {
                    require_once 'de.php';
                  }
                  

                  您可以定义数字和货币显示、比较/排序(即德语、法语和英语都有不同的整理方法)等功能.

                  You can define functions for number and currency display, comparison/sorting (ie German, French and English all have different collation methods), etc.

                  人们常常忘记 P​​HP 是一种动态语言,所以像这样:

                  People often forget PHP is a dynamic language so things like this:

                  if ($language == 'en') {
                    function cmp($a, $b) { ... }
                  } else if ($language == 'de') {
                    function cmp($a, $b) { ... }
                  }
                  

                  实际上是完全合法的.使用它们.

                  are in fact perfectly legal. Use them.

                  这篇关于编程多语言 PHP 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何停止基于 EXIF“方向"数据的 PHP iMagick 自 下一篇:为什么不将 C 用于 Web 应用程序?

                  相关文章

                  最新文章

                      <bdo id='jI5Nu'></bdo><ul id='jI5Nu'></ul>
                  1. <legend id='jI5Nu'><style id='jI5Nu'><dir id='jI5Nu'><q id='jI5Nu'></q></dir></style></legend>

                  2. <small id='jI5Nu'></small><noframes id='jI5Nu'>

                    <i id='jI5Nu'><tr id='jI5Nu'><dt id='jI5Nu'><q id='jI5Nu'><span id='jI5Nu'><b id='jI5Nu'><form id='jI5Nu'><ins id='jI5Nu'></ins><ul id='jI5Nu'></ul><sub id='jI5Nu'></sub></form><legend id='jI5Nu'></legend><bdo id='jI5Nu'><pre id='jI5Nu'><center id='jI5Nu'></center></pre></bdo></b><th id='jI5Nu'></th></span></q></dt></tr></i><div id='jI5Nu'><tfoot id='jI5Nu'></tfoot><dl id='jI5Nu'><fieldset id='jI5Nu'></fieldset></dl></div>
                      <tfoot id='jI5Nu'></tfoot>