Aggregate similar sentences

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:

<> has been successfully created.

I’m new in ruby so sorry if it is an easy question :slight_smile:
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 M. [email protected]
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 M. 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:

<> has been successfully created.

I’m new in ruby so sorry if it is an easy question :slight_smile:
The Item should also be from the en.yml file. So how can I access a
variable in en.yml?

Thank you in advance!

Ah, ok. I got it. It was the general thing you mentioned.

Thank you!

On Mon, Jan 25, 2010 at 19:46, Henrik N. [email protected] wrote:

How do I use that in the controller after creating a Challenge?

flash[:success] = t(:flash.added, :item => Challenge.human_name) ?

On Mon, Jan 25, 2010 at 20:34, Kot M. [email protected]
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 Rails Internationalization (I18n) API — Ruby on Rails Guides for more
details on the basics.

thanks, but I think the model translation doesn’t work.

Is it in the i18n or do I need an another plugin for that?

Hi Kot,

sorry for the late response here, but …

On Jan 25, 2010, at 7:39 PM, Kot M. wrote:

<> 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 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.

:slight_smile:

sorry, but the last question is why this doesn’t work

challenge controller:

flash[:success] = t(‘flash.added’, :item => t(‘dictionary.challenge’))

en.yml

dictionary:
challenge: Challenge

flash:
added: {{item}} has been successfully created.