{"id":16820293,"url":"https://github.com/dvandersluis/has_localization_table","last_synced_at":"2025-07-06T12:37:17.154Z","repository":{"id":4285102,"uuid":"5414688","full_name":"dvandersluis/has_localization_table","owner":"dvandersluis","description":"Automatically sets up usage of a relational table to contain user-created multi-locale string attributes","archived":false,"fork":false,"pushed_at":"2016-04-01T18:16:00.000Z","size":63,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-12T04:18:49.744Z","etag":null,"topics":[],"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/dvandersluis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-08-14T15:25:05.000Z","updated_at":"2020-01-07T15:56:35.000Z","dependencies_parsed_at":"2022-08-06T16:00:45.396Z","dependency_job_id":null,"html_url":"https://github.com/dvandersluis/has_localization_table","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dvandersluis/has_localization_table","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fhas_localization_table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fhas_localization_table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fhas_localization_table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fhas_localization_table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dvandersluis","download_url":"https://codeload.github.com/dvandersluis/has_localization_table/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fhas_localization_table/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263901592,"owners_count":23527438,"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":[],"created_at":"2024-10-13T10:56:11.389Z","updated_at":"2025-07-06T12:37:17.134Z","avatar_url":"https://github.com/dvandersluis.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HasLocalizationTable\n\n[![Gem Version](https://badge.fury.io/rb/has_localization_table.svg)](https://badge.fury.io/rb/has_localization_table)\n[![Build Status](https://travis-ci.org/dvandersluis/has_localization_table.svg?branch=master)](https://travis-ci.org/dvandersluis/has_localization_table)\n\nActiveRecord plugin which adds setup and convenience methods for working with a relational localization table for user-driven data.\n\nAdds accessors to retrieve localized attributes using the current locale, in order to avoid having to collect the correct object each time a value is needed. Localized attribute values are also cached for the current locale.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'has_localization_table'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install has_localization_table\n\n## Usage\n\nThe gem assumes that the localization table has already been migrated, and the model for it contains `belongs_to` associations for the locale table and the base table. You only need to call the `has_localization_table` method on the base model.\n\n\tclass Article \u003c ActiveRecord::Base\n\t  # assuming ArticleLocalizations has name and body columns\n\t  has_localization_table :localizations, required: true, class_name: \"ArticleLocalizations\"\n\tend\n\t\n\t# Localized attributes can be retrieved by accessor...\n\ta = Article.new(name: \"Once Upon a Time...\", body: \"There once lived a princess locked away in a tower!\")\n\ta.name # \"Once Upon a Time...\"\n\ta.body # \"There once lived a princess locked away in a tower!\"\n\t\n\t# ... or set directly\n\ta.name = \"Sleeping Beauty\"\n\t\n\t# After changing to a different locale\n\ta.name = \"Belle au Bois Dormant\"\n\ta.body = \"Il était une fois une princesse enfermée dans une tour!\"\n\t\n\ta.localizations\n\t=\u003e [\u003cArticleLocalization id: 1, article_id: 1, locale_id: 1, name: \"Sleeping Beauty\", body: \"There once lived a princess locked away in a tower!\"\u003e,\n\t    \u003cArticleLocalization id: 2, article_id: 1, locale_id: 2, name: \"Belle au Bois Dormant\", body: \"Il était une fois une princesse enfermée dans une tour!\"\u003e]\n\t    \n\t# Finder and order convenience methods are also provided:\n\tArticle.find_by_name(\"Snow White\")\n\tArticle.find_by_body(\"...\")\n\tArticle.find_by_name_and_body(\"...\", \"...\")\n\tArticle.ordered_by_name # uses Arel, so it can be chained with other finder methods\n\n### `has_localization_table` Arguments\nIf given, the first argument is the name used for the association, otherwise it defaults to `strings`.\n\n* `class_name` (default: base class name + class_suffix) - the name of the localization class.\n* `required` (default: false) - if true, at least a localization object for the primary language (see Configuration section) must be present or validation will fail\n* `optional` (default: []) - if `required` is true, can be used to specify that specific attributes are optional\n\nAny options that can be passed into `has_many` can also be passed along and will be used when creating the association.\n\t\n## Configuration\n`HasLocalizationTable` can also be configured as follows. Note that if any configuration option responds to `call`, it will be called.\n\n\tHasLocalizationTable.configure do |config|\n\t  # Default suffix to use for Localization class names\n\t  # ie. Article -\u003e ArticleLocalization\n\t  config.class_suffix = \"Localization\"\n\t  \n\t  # Default localizations association name\n      config.default_association_name = :localizations\n      \n      # Class name for Locale objects\n\t  config.locale_class = \"Locale\"\n\t  \n\t  # Foreign key used in localization tables to relate to a Locale\n      config.locale_foreign_key = \"locale_id\"\n      \n      # Primary (main) locale\n\t  config.primary_locale = -\u003e{ Locale.primary_language }\n\t  \n\t  # Current locale\n\t  config.current_locale = -\u003e{ Locale.current_language }\n\t  \n\t  # All available locales\n\t  config.all_locales = -\u003e{ Locale.all }\n\tend\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvandersluis%2Fhas_localization_table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdvandersluis%2Fhas_localization_table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvandersluis%2Fhas_localization_table/lists"}