如何向Perl脚本添加国际化?

时间:2021-07-15 07:16:06

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

我正在考虑为用Perl编写的成熟CGI应用程序引入多语言支持。我最初考虑使用Perl哈希(存储在磁盘上)来翻译我自己的解决方案,但后来我遇到了一个CPAN模块,它看起来像我想做的那样(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?

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

Thanks

谢谢

4 个解决方案

#1


16  

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.

有一篇关于软件本地化的Perl期刊文章。它将为您提供添加多语言支持时可以期待的内容。它写得很漂亮,很有幽默感。

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.

具体来说,这篇文章是由编写和维护Locale :: Maketext的人编写的,因此我建议该模块只是基于作者必须忍受的痛苦程度才能使其正常工作。

#2


8  

See http://rassie.org/archives/247 for comparison of modern GNU gettext, Locale::Maketext and Locale::TextDomain.

有关现代GNU gettext,Locale :: Maketext和Locale :: TextDomain的比较,请参见http://rassie.org/archives/247。

#3


3  

In a response to my question about this one of the comments suggested reading this article about localizing perl code.

在回答我的问题时,其中一条评论建议阅读本文关于本地化perl代码。

#4


3  

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.

如果你有时间,那么看看I18N在Jifty框架中完成的方式 - 虽然最初很混乱,但它非常优雅和可用。

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

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

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.

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

#1


16  

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.

有一篇关于软件本地化的Perl期刊文章。它将为您提供添加多语言支持时可以期待的内容。它写得很漂亮,很有幽默感。

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.

具体来说,这篇文章是由编写和维护Locale :: Maketext的人编写的,因此我建议该模块只是基于作者必须忍受的痛苦程度才能使其正常工作。

#2


8  

See http://rassie.org/archives/247 for comparison of modern GNU gettext, Locale::Maketext and Locale::TextDomain.

有关现代GNU gettext,Locale :: Maketext和Locale :: TextDomain的比较,请参见http://rassie.org/archives/247。

#3


3  

In a response to my question about this one of the comments suggested reading this article about localizing perl code.

在回答我的问题时,其中一条评论建议阅读本文关于本地化perl代码。

#4


3  

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.

如果你有时间,那么看看I18N在Jifty框架中完成的方式 - 虽然最初很混乱,但它非常优雅和可用。

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

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

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.

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