This project is archived and is in readonly mode.

#1689 ✓invalid
Yaroslav Markin

Add I18n shortcuts to AR models

Reported by Yaroslav Markin | January 3rd, 2009 @ 10:50 AM | in 3.0.2

Patch adds I18n shortcuts to ActiveRecord models, much like is already done for ActionController.

It occurs I18n in models is not as simple as it should be, and t/l aliases can help with that.

Linkproof: http://groups.google.com/group/r...

Comments and changes to this ticket

  • Pascal Ehlert

    Pascal Ehlert January 3rd, 2009 @ 08:00 PM

    Imho we should keep AR:Base clean from helper methods (actually this feels like a helper method, although the definition is different ;-))..

    Actually, translation shouldn't be going on in models at all (where possible) and if someone needs it, it's easy enough to do I18n.t or alias the method on his own.

    -1 for this.

  • Yaroslav Markin

    Yaroslav Markin January 3rd, 2009 @ 08:05 PM

    Actually, translation shouldn't be going on in models at all (where possible)

    Why so? Check the link, I see it as a very common scenario. Validation messages translation is sure built in, but this does not mean you don't need other strings translated.

    I think of I18n as some kind of string refactoring -- keep all your string constants in a separate place (YML file or any source supported by I18n backend used).

    Judging by link provided, seems it is not really clear that Rails devs should use I18n module -- l/t aliases are built-in for ActionController for a reason.

    This style is a bit simular to logger accessor for AC and AR -- sure you can use @RAILS_DEFAULT_LOGGER@, but this stuff is shorter and built-in.

  • Yaroslav Markin

    Yaroslav Markin January 10th, 2009 @ 02:54 PM

    • Assigned user changed from “Sven Fuchs” to “DHH”

    Since Sven is N/A at the moment and it looks like an API design issue anyway (patch is too simple), I pass ticket to DHH.

  • Sven Fuchs

    Sven Fuchs January 10th, 2009 @ 03:09 PM

    Maybe not n/a for that matter ... but i'm not quite sure about this one tbh. On the one hand I tend to agree with Pascal here that this might be a bit too much in AR::Base. Otoh we ship a helper for controllers and views, too.

    The ticket is in best hands with DHH anyway ;)

  • Pratik

    Pratik March 8th, 2009 @ 01:39 PM

    • Assigned user changed from “DHH” to “Pratik”

    Let's add this post 2.3

    Thanks.

  • Pratik

    Pratik June 21st, 2009 @ 05:40 PM

    • Assigned user changed from “Pratik” to “josh”

    I suppose this should be in AMo now.

  • josh

    josh July 9th, 2009 @ 07:34 PM

    • Assigned user changed from “josh” to “DHH”
    • Milestone cleared.

    Pass back to DHH. I'm kind of a -1 here too.

  • Mike Champion

    Mike Champion July 9th, 2009 @ 07:44 PM

    I wrote a plugin/gem that adds a more DRY "translate" to models, mailers, controllers, views. Might be interesting for those running into this issue:

    http://github.com/graysky/translator/

    The stock AR models already support i18n for the validation messages, but don't make it simple if you have your own messages you want to have be i18n. If it is valuable for all the validates methods, why not ones developers add?

    (A purist could make the case the the models shouldn't be injecting user-visible strings at all and that should be done in a view layer, but I don't think anyone is proposing that.)

  • Dmitry Polushkin

    Dmitry Polushkin February 28th, 2010 @ 06:51 PM

    I think this should be in the core (I've used "translator" gem in all the multi-language projects). Models will be more clear (and you will never use additional scopes).
    +1

  • José Valim

    José Valim March 28th, 2010 @ 06:13 AM

    • State changed from “new” to “wontfix”

    I'm closing this one guys since I'm kinda of -1 also. Re-raise the discussion in the i18n mailing list or Rails mailing list and see how people react to it.

  • Yehuda Katz (wycats)

    Yehuda Katz (wycats) March 28th, 2010 @ 06:14 AM

    • State changed from “wontfix” to “invalid”

    This has been around the block a few times and has received a lot of -1's from members of the core team. People in general seem ambivalent. I'm closing pending a suggestion that is more widely accepted.

  • Jeremy Kemper

    Jeremy Kemper October 15th, 2010 @ 11:01 PM

    • Milestone set to 3.0.2
    • Importance changed from “” to “High”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages