代码之家  ›  专栏  ›  技术社区  ›  David

Yii::t()复杂翻译,并添加差异结果iva参数

  •  1
  • David  · 技术社区  · 12 年前

    从我的第一个问题中,我得到了以下代码

    Yii::t('transFile', 'AAA {BBB} CCC', array('{BBB}'=>Yii::t('transFile','BBB')))
    

    现在在我的transFile中

    return array(
    'BBB'=>'translation of BBB'
    'AAA {VAR} CCC'=>'translation_of_AAA CCC {VAR}',
    );
    

    这段代码运行良好。

    但我希望BBB的翻译有两种类型: BBBx BBBy 因此,翻译文件将包含以下内容

    'BBB'=>'translation of BBBx,translation of BBBy,'
    

    那么如何编写代码,以便翻译文件采用BBB翻译的一种或另一种变体并将其放入文本中呢?

    1 回复  |  直到 12 年前
        1
  •  2
  •   Mihai P.    12 年前

    答案仍然在我发送给你的链接中:)。就是这个 http://www.yiiframework.com/doc/guide/1.1/en/topics.i18n 您可以发送一个转换或另一个转换的参数。例如

    Yii::t('app', 'n==1#one book|n>1#many books', 1);
    

    您始终可以创建如下条件

    Yii::t('app', 'n==1#translation of BBBx|n>1#translation of BBBy', 1);
    

    获得“BBBx的翻译”和

    Yii::t('app', 'n==1#translation of BBBx|n>1#translation of BBBy', 2);
    

    要获得“BBBy的翻译”

    推荐文章