{"id":16737633,"url":"https://github.com/shioyama/i18n_accessors","last_synced_at":"2025-10-06T10:34:43.221Z","repository":{"id":56877116,"uuid":"87694242","full_name":"shioyama/i18n_accessors","owner":"shioyama","description":"Define locale-specific accessors for translated attributes.","archived":false,"fork":false,"pushed_at":"2021-10-09T07:05:58.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T02:39:28.279Z","etag":null,"topics":["i18n","ruby","translation"],"latest_commit_sha":null,"homepage":"","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/shioyama.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-09T08:34:34.000Z","updated_at":"2021-10-09T07:05:11.000Z","dependencies_parsed_at":"2022-08-20T11:30:50.973Z","dependency_job_id":null,"html_url":"https://github.com/shioyama/i18n_accessors","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shioyama%2Fi18n_accessors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shioyama%2Fi18n_accessors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shioyama%2Fi18n_accessors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shioyama%2Fi18n_accessors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shioyama","download_url":"https://codeload.github.com/shioyama/i18n_accessors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243676697,"owners_count":20329431,"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":["i18n","ruby","translation"],"created_at":"2024-10-13T00:27:14.286Z","updated_at":"2025-10-06T10:34:38.142Z","avatar_url":"https://github.com/shioyama.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# I18nAccessors\n\n[![Gem Version](https://badge.fury.io/rb/i18n_accessors.svg)][gem]\n[![Build Status](https://travis-ci.org/shioyama/i18n_accessors.svg?branch=master)][travis]\n\n[gem]: https://rubygems.org/gems/i18n_accessors\n[travis]: https://travis-ci.org/shioyama/i18n_accessors\n\nDefine locale accessors for your translated attributes. Extracted from\n[Mobility](https://github.com/shioyama/mobility); works with\n[Globalize](https://github.com/globalize/globalize) and other translation gems.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'i18n_accessors', '~\u003e 1.0.0'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install i18n_accessors\n\n## Usage\n\n### Accessor Methods\n\nTo define a set of accessors for a translated attribute of the form\n`\u003cattribute\u003e_\u003clocale\u003e`, include an instance of the `I18nAccessors::Methods`\nclass in your model with translated attribute names as arguments:\n\n```ruby\nclass Post\n\n  def title\n    # ...\n  end\n\n  def title?\n    # ...\n  end\n\n  def title=(title)\n    # ...\n  end\n\n  include I18nAccessors::Methods.new(:title)\nend\n```\nBy default, `I18n.available_locales` will be used to determine which locales to\ndefine accessors for. So if `I18n.available_locales` is `[:en, :fr]`, then this\nwill define methods: `title_en`, `title_en?`, `title_en=`, `title_fr`,\n`title_fr?` and `title_fr=`. Each of these methods is an alias to `title` (or\n`title?`, or `title=`) with `I18n.locale` changed to the locale in the suffix.\n\nIf you want to specify explicitly which locales to define accessors for, pass\nthe locales as an option with the `locales` key to `new` when creating the\nmodule:\n\n```ruby\ndef Post\n\n  # ...\n\n  include I18nAccessors::Methods.new(:title, :content, locales: [:en, :fr])\nend\n```\n\nThis will define accessor methods for both `title` and `content`, in both\nEnglish (`en`) and French (`fr`).\n\n### Method Missing\n\n`I18nAccessors::Missing` does a similar thing, but using `method_missing` to\nrespond to messages of the form `\u003cattribute\u003e_\u003clocale\u003e`. This is generally\nslower (due to how `method_missing` works), but can be used to handle *any* locale:\n\n```ruby\nclass Post\n\n  # ...\n\n  include I18nAccessors::Missing.new(:title, :content)\nend\n```\n\nYou can include both a `I18nAccessors::Methods` module and a\n`I18nAccessors::Missing` module in the same class without conflict (the\naccessor methods will take precedence).\n\n### Configuration\n\nIf you are using I18nAccessors with Globalize, you can change the default i18n\nclass to `Globalize`:\n\n```ruby\nI18nAccessors.configure do |config|\n  config.i18n_class = Globalize\nend\n```\n\nWith this configuration, `Globalize.with_locale` will be used to set the locale\naround the accessor methods, rather than `I18n.with_locale`.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/shioyama/i18n_accessors. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\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%2Fshioyama%2Fi18n_accessors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshioyama%2Fi18n_accessors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshioyama%2Fi18n_accessors/lists"}