Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Add I18n shortcuts to AR models

#1689

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

Reported by Yaroslav Markin · January 3rd, 2009 @ 10:50 AM

State: invalid
Milestone: 3.0.2
Assigned to: DHH DHH
Importance: High

Activity

  1. Pascal Ehlert
    Pascal Ehlert

    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.

    January 3rd, 2009 @ 08:00 PM

  2. Yaroslav Markin
    Yaroslav Markin

    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.

    January 3rd, 2009 @ 08:05 PM

  3. Yaroslav Markin
    Yaroslav Markin
    • 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.

    January 10th, 2009 @ 02:54 PM

  4. Sven Fuchs
    Sven Fuchs

    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 ;)

    January 10th, 2009 @ 03:09 PM

  5. Pratik
    Pratik
    • Assigned user changed from DHH to Pratik

    Let's add this post 2.3

    Thanks.

    March 8th, 2009 @ 01:39 PM

  6. Pratik
    Pratik
    • Assigned user changed from Pratik to josh

    I suppose this should be in AMo now.

    June 21st, 2009 @ 05:40 PM

  7. josh
    josh
    • Assigned user changed from josh to DHH
    • Milestone cleared.

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

    July 9th, 2009 @ 07:34 PM

  8. Mike Champion
    Mike Champion

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

    July 9th, 2009 @ 07:44 PM

  9. Dmitry Polushkin
    Dmitry Polushkin

    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

    February 28th, 2010 @ 06:51 PM

  10. José Valim
    José Valim
    • 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.

    March 28th, 2010 @ 06:13 AM

  11. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • 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.

    March 28th, 2010 @ 06:14 AM

  12. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to High

    October 15th, 2010 @ 11:01 PM