如何将国际化添加到我的 Perl 脚本中?

发布于 2024-07-06 18:48:07 字数 318 浏览 8 评论 0原文

我正在考虑向用 Perl 编写的成熟 CGI 应用程序引入多语言支持。 我最初考虑使用 Perl 哈希(存储在磁盘上)作为翻译文件来滚动我自己的解决方案,但后来我遇到了一个 CPAN 模块,它似乎可以满足我的需求(i18n)。

有人有 Perl 国际化(特别是 i18n CPAN 模块)的经验吗? i18n 模块是多语言支持的首选方法还是我应该重新考虑自定义解决方案?

谢谢

I'm looking at introducing multi-lingual support to a mature CGI application written in Perl. I had originally considered rolling my own solution using a Perl hash (stored on disk) for translation files but then I came across a CPAN module which appears to do just what I want (i18n).

Does anyone have any experience with internationalization (specifically the i18n CPAN module) in Perl? Is the i18n module the preferred method for multi-lingual support or should I reconsider a custom solution?

Thanks

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

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

发布评论

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

评论(2

轻拂→两袖风尘 2024-07-13 18:48:07

有一篇关于软件本地化的 Perl Journal 文章。 它将使您清楚地了解添加多语言支持时可以期待什么。 它写得很漂亮而且很幽默。

具体来说,本文是由编写和维护 Locale::Maketext,所以我建议该模块只是基于作者所付出的痛苦,很明显,作者必须忍受才能使其正常工作。

There is a Perl Journal article on software localisation. It will provide you with a good idea of what you can expect when adding multi-lingual support. It's beautifully written and humourous.

Specifically, the article is written by the folks who wrote and maintain Locale::Maketext, so I would recommend that module simply based upon the amount of pain it is clear the authors have had to endure to make it work correctly.

哭泣的笑容 2024-07-13 18:48:07

如果您有时间,请查看一下 Jifty 框架 - 虽然最初很混乱,但它非常优雅且可用。

它们重载 _,以便您可以在代码中的任何位置使用 _("text to translate")。 然后正常使用 Locale::Maketext 翻译这些字符串。

它的真正强大之处在于,他们使用 Scalar::Defer 推迟翻译,直到需要字符串为止 这样您就可以随时开始添加字符串,甚至在您知道它们将被翻译成哪种语言之前。 例如在配置文件等中。这确实使 I18N 易于使用。

If you have the time then do take a look at the way the I18N is done in the Jifty framework - although initially quite confusing it is very elegant and usable.

They overload _ so that you can use _("text to translate") anywhere in the code. These strings are then translated using Locale::Maketext as normal.

What makes it really powerful is that they defer the translation until the string is needed using Scalar::Defer so that you can start adding the strings at any time, even before you know which language they will be translated into. For example in config files etc. This really make I18N easy to work with.

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