首页 > 解决方案 > 多个复数条件翻译

问题描述

我尝试使用翻译服务来翻译包含 2 个复数单词的句子,请参见下面的示例:

$countToBeDownloded = 2;
$allowedToDl = 0;

$countToBeDownloded1 = 15;
$allowedToDl1 = 4;

/*
 * Sentence : 
 *
 * `You tried to download {countToBeDownloded} image|images but your daily quota allow you to download only 
 * {allowedToDl} image|images`
 */

$this->translator->trans('mymessage', ['countToBeDownloded' => $countToBeDownloded, 'allowedToDl' => $allowedToDl]);

// mymessage output : You tried to download 2 images but your daily quota allow you to download only 0 image


$this->translator->trans('mymessage2', ['countToBeDownloded' => $countToBeDownloded1, 'allowedToDl' => $allowedToDl1]);

// mymessage output : You tried to download 15 images but your daily quota allow you to download only 4 images

如您所见,我必须使用and翻译image两次。countToBeDownlodedallowedToDl

有我的 yaml 翻译文件

mymessage: |-
  {countToBeDownloded, plural,
      =1 {You tried to download # image but your daily quota allow you to download only {allowedToDl} images}
      other {You tried to download # images but your daily quota allow you to download only {allowedToDl} images}
  }

有办法实现吗?

标签: phpyamlsymfony5

解决方案


推荐阅读