【问题标题】:Symfony pluralization ignoring floatsSymfony 复数忽略浮点数
【发布时间】:2015-11-24 07:30:47
【问题描述】:

我正在使用移植到我的框架中的 Symfony Translations。我在文档中找到了这个:

'{0} There are no apples|{1} There is one apple|]1,19] There are %count% apples|[20,Inf[ There are many apples'

The above string specifies four different intervals: exactly 0, exactly 1, 2-19, and 20 and higher.

来源:http://symfony.com/doc/current/components/translation/usage.html#explicit-interval-pluralization

我的问题是我需要为1.5 使用与1 不同的复数形式。我怎样才能做到这一点?当我将1.5 作为计数参数传递时,它得到1 复数分配。

我认为将间隔指定为]1,something] 会起作用,但根据文档,它与[2,something] 基本相同(在这种情况下,我无论如何都看不到使用]1 的意义)。如何覆盖1.5 复数?

【问题讨论】:

    标签: symfony pluralize


    【解决方案1】:

    根据 Symfony 参考,Interval (http://api.symfony.com/2.7/Symfony/Component/Translation/Interval.html) 和 TranslatorInterface (http://api.symfony.com/2.7/Symfony/Component/Translation/TranslatorInterface.html) 接受 int 值,所以我认为你想要实现的目标是不可能的。

    但是,您可以覆盖 Translator 服务并实现您的逻辑。详情请见here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-18
      相关资源
      最近更新 更多