多元化/非多元化

发布于 2024-08-11 04:04:17 字数 154 浏览 12 评论 0 原文

php 有没有函数来处理复数或非复数单词?

显然,像“apple”这样的单词末尾的“s”很容易去掉或替换,但其他单词就没那么简单了。

如果php没有原生的处理方式,那么其他语言如何处理这个问题呢?是否有一个函数可以处理复数/非复数,或者英语在语法上是否太不一致?

Does php have any function to deal with pluralising or depluralising words?

Obviously it's pretty easy to take off or replace the 's' at the end of words like 'apple' but other words are not so simple.

If php doesn't have a native way of dealing with it, how do other languages deal with the problem? Is there a function that can handle pluralisation/depluralisation or is the english language just too gramatically inconsistent?

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

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

发布评论

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

评论(3

悟红尘 2024-08-18 04:04:17

我通常仅在实现自己的方式来处理此问题的框架内使用 PHP,但我认为您问题的答案可能是 gettext

Gettext 是 GNU 国际化和本地化 (i18n) 库。它已被开发为 i18n 和 l10n(国际化和本地化)的工具,但 - 正因为如此,它具有 大量的函数来处理复数形式,因为其他语言可能有比英语更复杂的形成复数的方式。

PHP 实现 gettext 因此这可能是您研究的一个很好的起点。最后,您可能希望查看这个其他答案,建议另一种方法这样做的。

编辑:我认为 ngettext() 可能是您正在寻找的功能。

I am normally using PHP only from within frameworks that implements their own way to deal with this problem, yet I think the answer to your question might be gettext.

Gettext is the GNU internationalization and localization (i18n) library. It has been developed as a tool for i18n and l10n (internationalisation and localisation) but - exactly because of this, it has plenty of functions to deal with plural forms, given that other languages might have much more complex ways of forming plurals than English does.

PHP implments gettext so that might be a good starting point for you to look into. Finally, you might wish to have a look to this other answer, suggesting an alternative way of doing this.

EDIT: I think ngettext() might be the function you are looking for.

海之角 2024-08-18 04:04:17

查看 Damien Conway 关于此的论文。它很好地说明了仅用英语来说这是一个多么棘手的话题。

其他语言如何处理这个问题(正如您所问的)? Perl 有一个用于此目的的模块(由 Damien 编写),它对上述论文进行了编码。请参阅 Lingua-EN-Inflect。我不知道其他语言中有任何模块可以做到这一点。

Check out Damien Conway's paper on this. It illustrates nicely what a thorny topic this is in English alone.

How do other languages deal with this (as you've asked) ? Perl has a module for this (written by Damien) which encodes the above paper. See Lingua-EN-Inflect. I don't know of any modules in other languages which do quite this.

鲜肉鲜肉永远不皱 2024-08-18 04:04:17

我认为您应该查看此示例:

http://kuwamoto.org/2007/12/14/how-to-pluralize-in-php-and-please-help-me-check-the-code/

可能存在一些错误,我还没有测试过,但它应该足以让您开始。

I think you should check this sample out:

http://kuwamoto.org/2007/12/14/how-to-pluralize-in-php-and-please-help-me-check-the-code/

There might be some bugs and I haven't tested it, but it should be enough to get you started.

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