{"id":14955634,"url":"https://github.com/thadeu/acts_enum_translable","last_synced_at":"2025-10-08T18:03:56.275Z","repository":{"id":56842244,"uuid":"88387246","full_name":"thadeu/acts_enum_translable","owner":"thadeu","description":"💎  ActiveRecord::Enum Translate with i18n","archived":false,"fork":false,"pushed_at":"2017-04-18T12:32:09.000Z","size":125,"stargazers_count":3,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-01T06:09:17.738Z","etag":null,"topics":["activerecorde-enum","enum","enum-native-rails","enumerable","enums","rails","rails4","rails5","translable"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thadeu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-16T02:55:59.000Z","updated_at":"2019-06-12T14:30:54.000Z","dependencies_parsed_at":"2022-08-29T07:42:18.269Z","dependency_job_id":null,"html_url":"https://github.com/thadeu/acts_enum_translable","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/thadeu/acts_enum_translable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Facts_enum_translable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Facts_enum_translable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Facts_enum_translable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Facts_enum_translable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thadeu","download_url":"https://codeload.github.com/thadeu/acts_enum_translable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Facts_enum_translable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264585372,"owners_count":23632647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecorde-enum","enum","enum-native-rails","enumerable","enums","rails","rails4","rails5","translable"],"created_at":"2024-09-24T13:11:28.620Z","updated_at":"2025-10-08T18:03:56.223Z","avatar_url":"https://github.com/thadeu.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActsEnumTranslable\nActsEnumTranslable convention translate enums with .yml file.\n\n## Pull Request Ruby on Rails\nI hope this functionality is accepted in the pull request I made in the rails project. If it is accepted, we will soon have a merge for rails 5.x. [Pull Request in to Rails 5.x](https://github.com/rails/rails/pull/28787)\n\n## Usage\n* Install Gem\n* Configure enum native Rails\n* Add acts_enum_translable in Model class\n* Configure active_record attributes in file .yml\n* Use methods\n\n## Install Gem for Ruby on Rails\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'acts_enum_translable'\n```\n\nAfter:\n```bash\n$ bundle install\n```\n\n## Configure enum native Rails\nMore details, please visit [ActiveRecord::Enum](http://api.rubyonrails.org/classes/ActiveRecord/Enum.html)\n\n```ruby\n# example model\n# user.rb\n\nclass User \u003c ApplicationRecord\n  enum status: { inactive: 0, active: 1, blocked: 2 }\n  enum visible: [:hide, :show]\nend\n```\n## Add acts_enum_translable in Model class\n\nAdd in Model for inherit methods\n\n```ruby\n# exemple model\n# user.rb\n\nclass User \u003c ApplicationRecord\n  enum status: { inactive: 0, active: 1, blocked: 2 }\n  enum visible: [:hide, :show]\n\n  # Add in Model for inherit methods\n  acts_enum_translable\nend\n```\n\n## Configure active_record attributes in file .yml\n\nMore details, please visit section [4.5 Translations for Active Record Models](http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models)\n\nConfigure *Locale English* for exemple\n\n```ruby\n# config/locales/en.activerecord.yml\nen:\n  activerecord:\n    attributes:\n      users:\n        status:\n          inactive: \"Inactive\"\n          active: \"Active\"\n          blocked: \"Blocked\"\n        visible:\n          hide: 'Hide'\n          show: 'Show'\n```\n\nConfigure *Locale Portuguese* for exemple\n\n```ruby\n# config/locales/pt.activerecord.yml\npt:\n  activerecord:\n    attributes:\n      users:\n        status:\n          inactive: \"Inativo\"\n          active: \"Ativo\"\n          blocked: \"Bloqueado\"\n        visible:\n          hide: 'Oculto'\n          show: 'Visível'\n```\n\n## Use methods sufix with _translable for enums key\n```ruby\n# print status\nuser = User.new(status: :blocked, visible: :show)\nuser.status_translable\n# english: Blocked\n# portuguese: Bloqueado\n\n# print visible\nuser.visible_translable\n# english: Show\n# portuguese: Visível\n```\n\n## Use methods in Model class get enums for key\n\n_Required key param._\n\n```ruby\n# return Array with Values\n# in english\n# I18n.locale = :en\nUser.enum_list(:status)\n# =\u003e [\"Inactive\", \"Active\", \"Blocked\"]\n\n# in portuguese\n# I18n.locale = :pt\nUser.enum_list(:status)\n# =\u003e [\"Inativo\", \"Ativo\", \"Bloqueado\"]\n```\n\nNow return array with values and keys or reverse\n\n```ruby\n# return Arrary with par [value, key]\n# in english\n# I18n.locale = :en\nUser.enum_with_keys(:status)\n# =\u003e [[\"Inactive\", 0], [\"Active\", 1], [\"Blocked\", 2]]\n\n# in portuguese\n# I18n.locale = :pt\nUser.enum_with_keys(:status)\n# =\u003e [[\"Inativo\", 0], [\"Ativo\", 1], [\"Bloqueado\", 2]]\n\n# return par array [key, value]\nUser.enum_form(:status)\n# =\u003e [[0, \"Inativo\"], [1, \"Ativo\"], [2, \"Bloqueado\"]]\n```\n\n### Use SimpleForm too\n\nEasy return enums translated.\n\n```ruby\n# with I18n.locale = :pt or :en\n\u003c%= f.select :status, User.enum_form(:status), include_blank: true %\u003e\n```\n\n## Contributing\n\nWe have a long list of valued contributors. Check them all at: https://github.com/Thadeu/acts_enum_translable.\n\n## License\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthadeu%2Facts_enum_translable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthadeu%2Facts_enum_translable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthadeu%2Facts_enum_translable/lists"}