使用可选参数在.yml中翻译 [英] Translation in .yml with optional parameter

查看:139
本文介绍了使用可选参数在.yml中翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用可选参数进行翻译my_translation.例如:

I want to make a translation my_translation with an optional parameter. For example:

> I18n.t('my_translation')
=> "This is my translation"
> I18n.t('my_translation', parameter: 1)
=> "This is my translation with an optional parameter which value is 1"

这可能吗?

推荐答案

是的,当然可以.您只需这样编写翻译即可:

Yes, definitely. You just write the translations like this:

my_translation: This is my translation with an optional parameter which value is %{parameter}

该参数真的是可选的吗?在上面的翻译中,您必须提供所有参数.

Is the parameter really optional? In above translation, you have to provide all parameters.

更新:对不起,我回答太早了.我认为这并不容易.也许最简单的方法是这样的:

UPDATE: Sorry, I answered too soon. I don't think it's easy to do. Maybe the easiest way is like this:

> I18n.t('my_translation1')
=> "This is my translation"
> I18n.t('my_translation2', parameter: 1)
=> "This is my translation with an optional parameter which value is 1"

这篇关于使用可选参数在.yml中翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆