创建全球应用程序的痛苦

发布于 2024-08-11 08:36:56 字数 190 浏览 5 评论 0原文

我需要创建一个全局应用程序。这意味着它应该可以在世界任何地方、任何国家(或大多数国家)正常工作。这是一个 PHP 网站,在某些时候会处理金钱和时间。

我希望我能了解有关国家、相关时区、货币格式、符号和代码等内容的良好资源...

如果有人有关于此类数据的提示以及我如何以正确的方式使用它们,我会真的很感激:)

提前致谢!

I need to create a global application. This means it should work ok anywhere in the world, at any country (or most of them). It's a PHP website that will deal with money and time at certain points.

I wish I could know a good resource for countries, related timezones, currency formatting, symbols and codes, this kind of stuff...

If anyone has tips about these kind of data and how could I use them in the propper way, I would be really grateful :)

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

冬天旳寂寞 2024-08-18 08:36:57

Take a look at intl (http://www.php.net/manual/en/book.intl.php).

It is a wrapper around ICU (International Components for Unicode, http://site.icu-project.org/) and contains most of the stuff you need.

似最初 2024-08-18 08:36:57

了解 Mantis BugTracking 软件 如何处理国际化。他们使用的方法相当不错。

其他信息:
我已经使用它很多年了,但是快速浏览一下源代码就会发现这部分代码并没有发生重大变化。他们使用许多产品使用的通用消息目录和获取消息方法。他们的语言 API 非常简单 - phpxref 输出可用这并不奇怪。消息目录作为 PHP 脚本实现,只需 include 即可。例如,英语目录包含以下条目:

$s_new_bug = 'New Issue';
$s_bugnote_added = 'Note Added';

它包含大约 1,600 条左右的声明。有趣的魔法发生在 lang_load 内部。加载语言时,会包含目录文件,因此它定义的所有变量都在本地范围内定义。 Lang_load 迭代本地定义的变量并根据变量名称构建消息映射,以便可以按名称查找消息。例如,加载前面的代码片段后,就好像执行了以下语句:

$g_lang_strings['en']['new_bug'] = 'New Issue';
$g_lang_strings['en']['bugnote_added'] = 'Note Added';

当 UI 需要访问“硬编码”字符串时,它使用类似 lang_get('new_bug') 它将:

  1. 在当前用户的设置中查找首选语言
  2. 确保通过调用 lang_load() 加载语言映射
  3. 从适当的语言映射返回值

有趣的是,所有机器是延迟加载的。在您需要访问其中一种语言之前,您无需为它们定义的 50 种左右语言付费。总的来说,这可能是我多年来研究过的最令人印象深刻的 PHP 应用程序之一。

Take a look at how the Mantis BugTracking software handles internationalization. The method that they use is rather nice.

Additional Information:
It has been years since I have used it, but a quick look through the source code shows that this portion of the code has not changed significantly. They use the common message catalog and get message approach that many products use. Their language API is pretty simple - the phpxref output is available and it isn't that surprising. The message catalog is implemented as a PHP script that simply gets include'd. For example, the catalog for English contains entries like:

$s_new_bug = 'New Issue';
$s_bugnote_added = 'Note Added';

It contains about 1,600 or so declarations. The interesting magic happens inside of lang_load. When a language is loaded, the catalog file is included so all of the variables that it defines are defined in the local scope. Lang_load iterates over the locally defined variables and builds a message map based on the variable names so that it can look up the message by name. For example, after loading the previous snippet, it will be as if the following statements were executed:

$g_lang_strings['en']['new_bug'] = 'New Issue';
$g_lang_strings['en']['bugnote_added'] = 'Note Added';

When the UI needs to access a "hard coded" string, it uses a call like lang_get('new_bug') which will:

  1. Lookup the preferred language in the settings for the current user
  2. Ensure that the language map is loaded by calling lang_load()
  3. Return the value from the appropriate language map

The interesting thing is that all of the machinery is lazily loaded. You don't pay for the fact that they have 50 or so languages defined until you need to access one of them. Overall, this is probably one of the most inpressive PHP applications that I have dug into over the years.

南烟 2024-08-18 08:36:57

我曾开发过一个全球化应用程序,我发现最棘手的元素之一是时区以及如何存储日期时间。有时日期需要存储在本地时间(例如世界上某个地方发生事件的时间),有时需要存储在公共时区(例如,将所有创建的日期存储为 UTC)并转换为用户需要时当地时间。我建议您的数据库列/变量的命名约定,以明确它是什么。

永远不要尝试手动处理时区转换(它比你想象的要复杂得多),使用某种库/框架 - 我不知道在 PHP 中使用什么,在 .Net 中我们可以依赖 .Net BCL这种事。

I've worked on an globalised app and I find one of the trickiest elements is time zones and how you store your datetimes. Sometimes dates need to be stored in local time (like the time of an event at the place in the world) and somethimes they need to be stored in a common time zone (e.g. storing created dates as UTC for everything) and converted to the users local time when needed. I would advise a naming convention of your db columns/variables to make it clear which it is.

Never try to do deal with timezone conversions manually (it's much more complicated than you think), use some kind of library/framework - I wouldn't know what to use in PHP, in .Net we can rely on the .Net BCL for this sort of thing.

还在原地等你 2024-08-18 08:36:56

Zend Locale,Zend Framework 的一部分,可帮助您解决问题与货币、时区、翻译等相关......

很容易逐个采用 Zend Framework,因此您可以只使用您需要的那些部分(不会膨胀或变慢)。

Zend Locale, part of Zend Framework, helps you solve problems related to currencies, time zones, translation, ...

It's easy to adopt Zend Framework piece-by-piece, so you can just use those parts you need (no bloat or slowdown).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文