Hello,
I want to aggregate some similar sentences, which will work with i18n in
the en.yml file
Now I have redundancies like:
challenge_created_success: Challenge has been successfully created.
change_created: Change has been successfully created.
and I need something like that:
<<Item>> has been successfully created.
I'm new in ruby so sorry if it is an easy question :)
The Item should also be from the en.yml file. So how can I access a
variable in en.yml?
Thank you in advance!

On Mon, Jan 25, 2010 at 19:39, Kot Matroskin <lists@ruby-forum.com>
wrote:
> Hello,>> I want to aggregate some similar sentences, which will work with i18n in> the en.yml file>> Now I have redundancies like:>> challenge_created_success: Challenge has been successfully created.> change_created: Change has been successfully created.
en.yml:
successfully_created: "{{kind}} has been successfully created."
view:
t(:successfully_created, :kind => Challenge.human_name)
This assumes Challenge is an ActiveRecord model translated per the
conventions (activerecord.models.challenge).
More generally, you could do something like
t(:successfully_created, :kind => t("some.other.key"))

Thank you very much!
can I also use words from a .yml file I defined? not from activerecord?
Kot Matroskin wrote:
> Hello,>> I want to aggregate some similar sentences, which will work with i18n in> the en.yml file>> Now I have redundancies like:>> challenge_created_success: Challenge has been successfully created.> change_created: Change has been successfully created.>> and I need something like that:>> <<Item>> has been successfully created.>> I'm new in ruby so sorry if it is an easy question :)> The Item should also be from the en.yml file. So how can I access a> variable in en.yml?>> Thank you in advance!

On Mon, Jan 25, 2010 at 20:34, Kot Matroskin <lists@ruby-forum.com>
wrote:
> How do I use that in the controller after creating a Challenge?>> flash[:success] = t(:flash.added, :item => Challenge.human_name) ?
The key should be a single symbol or a string. So
t(:'flash.added', ...)
or
t('flash.added', ...)
Have a look at http://guides.rubyonrails.org/i18n.html for more
details on the basics.

Hi Kot,
sorry for the late response here, but ...
On Jan 25, 2010, at 7:39 PM, Kot Matroskin wrote:
> <<Item>> has been successfully created.
Why do you think you need that? To remove the redundancies and keep
translations dry?
In general redundancies aren't a bad thing in translations as they are
in your code. Keep in mind that in your translations you as a developer
want to give as much control as possible to translators. You as a
developer might not know many of the languages that your code eventually
needs to be localized to, so should keep the door open for translators
to do their thing.
In your example the words "challange" and "change" might need to be
inflected differently in a particular language so that you'd need to add
more logic here (in order to evaluate <Item> correctly). In English this
is trivial but in many other languages it's not.
So if you're just using the I18n API to abstract strings out of your
code while your app eventually never will be localized to any other
language than English then your fine. If not then you're probably better
off not to dry up messages like those.
:)