No commit activity in last 3 years
No release in over 3 years
Use lazy translations from models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
~> 10

Runtime

< 6, >= 3.2
 Project Readme

ActivemodelTranslation

Lazy translations for models.

::tranlate method performs translation with fallback similar to resolving errors. With one difference - it uses strings scope.

  • activemodel.strings.admin.key
  • activemodel.strings.user.key
  • strings.key

User.model_name.human(plural: true) returns translated plural model name.

Installation

Add this line to your application's Gemfile:

gem 'activemodel_translation'

# or pick a module:
# gem 'activemodel_translation', require: 'activemodel_translation/helper'
# gem 'activemodel_translation', require: 'activemodel_translation/plural'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activemodel_translation

Usage

class User < ActiveRecord::Base
  # lazy translation
  def title
    super || self.class.t('.default_title')
  end
end

# translated plural model name
User.model_name.human_plural

# ru.yml
# activerecord:
#   models_plural:
#     user: Пользователи

Contributing

  1. Fork it ( http://github.com/printercu/activemodel_translation/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request