[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8030":3},{"id":4,"name":5,"fullName":6,"owner":5,"repo":5,"description":7,"homepage":8,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":21,"topics":22,"createdAt":9,"pushedAt":9,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":15,"starSnapshotCount":15,"syncStatus":26,"lastSyncTime":27,"discoverSource":28},8030,"globalize","globalize\u002Fglobalize","Rails I18n de-facto standard library for ActiveRecord model\u002Fdata translation.","",null,"Ruby",2157,500,30,6,0,1,30.1,"Other",false,"main",true,[],"2026-06-12 02:01:47","![Globalize](http:\u002F\u002Fglobalize.github.io\u002Fglobalize\u002Fimages\u002Fglobalize.png)\n\n[![Build Status](https:\u002F\u002Fgithub.com\u002Fglobalize\u002Fglobalize\u002Fworkflows\u002FCI\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fglobalize\u002Fglobalize\u002Factions)\n[![Open Source Helpers](https:\u002F\u002Fwww.codetriage.com\u002Fglobalize\u002Fglobalize\u002Fbadges\u002Fusers.svg)](https:\u002F\u002Fwww.codetriage.com\u002Fglobalize\u002Fglobalize)\n\nGlobalize builds on the [I18n API in Ruby on Rails](http:\u002F\u002Fguides.rubyonrails.org\u002Fi18n.html)\nto add model translations to ActiveRecord models.\n\nIn other words: a way to translate actual user-generated content, for example; a single blog post with multiple translations.\n\n## Current state of the gem\n\nGlobalize is seen as relatively feature complete and is not very actively maintained, as none of the current maintainers actively use it. It should still work just fine, and we try to keep it up to date with new Ruby and Rails releases. \n\nPull Requests are very welcome, even if you get a delayed response, especially for compatibility with new versions of Rails. \n\n## Alternative solutions\n\n* [Mobility](https:\u002F\u002Fgithub.com\u002Fshioyama\u002Fmobility) - pluggable translation framework supporting many strategies, including translatable columns, translation tables and hstore\u002Fjsonb (Chris Salzberg). Mobility is seen by many (including Globalize maintainers) as a natural successor to Globalize.\n* [Traco](https:\u002F\u002Fgithub.com\u002Fbarsoom\u002Ftraco) - use multiple columns in the same model (Barsoom)\n* [hstore_translate](https:\u002F\u002Fgithub.com\u002Fcfabianski\u002Fhstore_translate) - use PostgreSQL's hstore datatype to store translations, instead of separate translation tables (Cédric Fabianski)\n* [json_translate](https:\u002F\u002Fgithub.com\u002Fcfabianski\u002Fjson_translate) - use PostgreSQL's json\u002Fjsonb datatype to store translations, instead of separate translation tables (Cédric Fabianski)\n* [Trasto](https:\u002F\u002Fgithub.com\u002Fyabawock\u002Ftrasto) - store translations directly in the model in a Postgres Hstore column\n\n## Related solutions\n\n* [friendly_id-globalize](https:\u002F\u002Fgithub.com\u002Fnorman\u002Ffriendly_id-globalize) - lets you use Globalize to translate slugs (Norman Clarke)\n\n## Requirements\n\n* ActiveRecord >= 7.0 (see below for installation with older ActiveRecord)\n* I18n\n\n## Installation\n\nTo install the ActiveRecord 7.x and 8.x compatible version of Globalize with its default setup, just use:\n\n```ruby\ngem install globalize\n```\n\nWhen using Bundler, put this in your Gemfile:\n\n```ruby\ngem \"globalize\", \"~> 7.0\"\n```\n\nPlease help us by letting us know what works, and what doesn't, when using pre-release code. To use a pre-release, put this in your Gemfile:\n\n```ruby\ngem \"globalize\", git: \"https:\u002F\u002Fgithub.com\u002Fglobalize\u002Fglobalize\", branch: \"main\"\n```\n\n## Older ActiveRecord\n* Use Version 6.3 or lower\n\nActiveRecord 4.2 to 6.1:\n\n```ruby\ngem \"globalize\", \"~> 6.3\"\n```\n\n## Model translations\n\nModel translations allow you to translate your models' attribute values. E.g.\n\n```ruby\nclass Post \u003C ActiveRecord::Base\n  translates :title, :text\nend\n```\n\nAllows you to translate the attributes :title and :text per locale:\n\n```ruby\nI18n.locale = :en\npost.title # => Globalize rocks!\n\nI18n.locale = :he\npost.title # => גלובאלייז2 שולט!\n```\n\nYou can also set translations with mass-assignment by specifying the locale:\n\n```ruby\npost.attributes = { title: \"גלובאלייז2 שולט!\", locale: :he }\n```\n\nIn order to make this work, you'll need to add the appropriate translation tables.\nGlobalize comes with a handy helper method to help you do this.\nIt's called `create_translation_table!`. Here's an example:\n\nNote that your migrations can use `create_translation_table!` and `drop_translation_table!`\nonly inside the `up` and `down` instance methods, respectively. You cannot use `create_translation_table!`\nand `drop_translation_table!` inside the `change` instance method.\n\n### Creating translation tables\n\nAlso note that before you can create a translation table, you have to define the translated attributes via `translates` in your model as shown above.\n\n```ruby\nclass CreatePosts \u003C ActiveRecord::Migration\n  def change\n    create_table :posts do |t|\n      t.timestamps\n    end\n\n    reversible do |dir|\n      dir.up do\n        Post.create_translation_table! :title => :string, :text => :text\n      end\n\n      dir.down do\n        Post.drop_translation_table!\n      end\n    end\n  end\nend\n```\n\nAlso, you can pass options for specific columns. Here’s an example:\n\n```ruby\nclass CreatePosts \u003C ActiveRecord::Migration\n  def change\n    create_table :posts do |t|\n      t.timestamps\n    end\n\n    reversible do |dir|\n      dir.up do\n        Post.create_translation_table! :title => :string,\n          :text => {:type => :text, :null => false, :default => \"abc\"}\n      end\n\n      dir.down do\n        Post.drop_translation_table!\n      end\n    end\n  end\nend\n```\n\nNote that the ActiveRecord model `Post` must already exist and have a `translates`\ndirective listing the translated fields.\n\n## Migrating existing data to and from the translated version\n\nAs well as creating a translation table, you can also use `create_translation_table!`\nto migrate across any existing data to the default locale. This can also operate\nin reverse to restore any translations from the default locale back to the model\nwhen you don't want to use a translation table anymore using `drop_translation_table!`\n\nThis feature makes use of `untranslated_attributes` which allows access to the\nmodel's attributes as they were before the translation was applied. Here's an\nexample (which assumes you already have a model called `Post` and its table\nexists):\n\n```ruby\nclass TranslatePosts \u003C ActiveRecord::Migration\n  def change\n    reversible do |dir|\n      dir.up do\n        Post.create_translation_table!({\n          :title => :string,\n          :text => :text\n        }, {\n          :migrate_data => true\n        })\n      end\n\n      dir.down do\n        Post.drop_translation_table! :migrate_data => true\n      end\n    end\n  end\nend\n```\n\nNOTE: Make sure you drop the translated columns from the parent table after all your data is safely migrated.\n\nTo automatically remove the translated columns from the parent table after the data migration, please use option `remove_source_columns`.\n\n```ruby\nclass TranslatePosts \u003C ActiveRecord::Migration\n  def self.up\n    Post.create_translation_table!({\n      :title => :string,\n      :text => :text\n    }, {\n      :migrate_data => true,\n      :remove_source_columns => true\n    })\n  end\n\n  def self.down\n    Post.drop_translation_table! :migrate_data => true\n  end\nend\n```\n\n\nIn order to use a specific locale for migrated data, you can use `I18n.with_locale`:\n\n```ruby\n    I18n.with_locale(:bo) do\n      Post.create_translation_table!({\n        :title => :string,\n        :text => :text\n      }, {\n        :migrate_data => true\n      })\n    end\n```\n\n## Adding additional fields to the translation table\n\nIn order to add a new field to an existing translation table, you can use `add_translation_fields!`:\n\n```ruby\nclass AddAuthorToPost \u003C ActiveRecord::Migration\n  def change\n    reversible do |dir|\n      dir.up do\n        Post.add_translation_fields! author: :text\n      end\n\n      dir.down do\n        remove_column :post_translations, :author\n      end\n    end\n  end\nend\n```\n\nNOTE: Remember to add the new field to the model:\n\n```ruby\ntranslates :title, :author\n```\n## Gotchas\n\nBecause globalize uses the `:locale` key to specify the locale during\nmass-assignment, you should avoid having a `locale` attribute on the parent\nmodel.\n\nIf you like your translated model to update if a translation changes, use the `touch: true` option together with `translates`:\n\n```ruby\n  translates :name, touch: true\n```\n\n## Known Issues\n\nIf you're getting the `ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column \"column_name\" violates not-null constraint` error, the only known way to deal with it as of now is to remove not-null constraint for the globalized columns:\n\n```ruby\nclass RemoveNullConstraintsFromResourceTranslations \u003C ActiveRecord::Migration\n  def change\n    change_column_null :resource_translations, :column_name, true\n  end\nend\n```\n\n## Versioning with Globalize\n\nSee the [globalize-versioning](https:\u002F\u002Fgithub.com\u002Fglobalize\u002Fglobalize-versioning) gem.\n\n## I18n fallbacks for empty translations\n\nIt is possible to enable fallbacks for empty translations. It will depend on the\nconfiguration setting you have set for I18n translations in your Rails config.\n\nYou can enable them by adding the next line to `config\u002Fapplication.rb` (or only\n`config\u002Fenvironments\u002Fproduction.rb` if you only want them in production)\n\n```ruby\n# For version 1.1.0 and above of the `i18n` gem:\nconfig.i18n.fallbacks = [I18n.default_locale]\n# Below version 1.1.0 of the `i18n` gem:\nconfig.i18n.fallbacks = true\n```\n\nBy default, globalize will only use fallbacks when your translation model does\nnot exist or the translation value for the item you've requested is `nil`.\nHowever it is possible to also use fallbacks for `blank` translations by adding\n`:fallbacks_for_empty_translations => true` to the `translates` method.\n\n```ruby\nclass Post \u003C ActiveRecord::Base\n  translates :title, :name\nend\n\nputs post.translations.inspect\n# => [#\u003CPost::Translation id: 1, post_id: 1, locale: \"en\", title: \"Globalize rocks!\", name: \"Globalize\">,\n      #\u003CPost::Translation id: 2, post_id: 1, locale: \"nl\", title: \"\", name: nil>]\n\nI18n.locale = :en\npost.title # => \"Globalize rocks!\"\npost.name  # => \"Globalize\"\n\nI18n.locale = :nl\npost.title # => \"\"\npost.name  # => \"Globalize\"\n```\n\n```ruby\nclass Post \u003C ActiveRecord::Base\n  translates :title, :name, :fallbacks_for_empty_translations => true\nend\n\nputs post.translations.inspect\n# => [#\u003CPost::Translation id: 1, post_id: 1, locale: \"en\", title: \"Globalize rocks!\", name: \"Globalize\">,\n      #\u003CPost::Translation id: 2, post_id: 1, locale: \"nl\", title: \"\", name: nil>]\n\nI18n.locale = :en\npost.title # => \"Globalize rocks!\"\npost.name  # => \"Globalize\"\n\nI18n.locale = :nl\npost.title # => \"Globalize rocks!\"\npost.name  # => \"Globalize\"\n```\n\n## Fallback locales to each other\n\nIt is possible to setup locales to fallback to each other.\n\n```ruby\nclass Post \u003C ActiveRecord::Base\n  translates :title, :name\nend\n\nGlobalize.fallbacks = {:en => [:en, :pl], :pl => [:pl, :en]}\n\nI18n.locale = :en\nen_post = Post.create(:title => \"en_title\")\n\nI18n.locale = :pl\npl_post = Post.create(:title => \"pl_title\")\nen_post.title # => \"en_title\"\n\nI18n.locale = :en\nen_post.title # => \"en_title\"\npl_post.title # => \"pl_title\"\n```\n\n\n## Scoping objects by those with translations\n\nTo only return objects that have a translation for the given locale we can use\nthe `with_translations` scope. This will only return records that have a\ntranslations for the passed in locale.\n\n```ruby\nPost.with_translations(\"en\")\n# => [\n  #\u003CPost::Translation id: 1, post_id: 1, locale: \"en\", title: \"Globalize rocks!\", name: \"Globalize\">,\n  #\u003CPost::Translation id: 2, post_id: 1, locale: \"nl\", title: \"\", name: nil>\n]\n\nPost.with_translations(I18n.locale)\n# => [\n  #\u003CPost::Translation id: 1, post_id: 1, locale: \"en\", title: \"Globalize rocks!\", name: \"Globalize\">,\n  #\u003CPost::Translation id: 2, post_id: 1, locale: \"nl\", title: \"\", name: nil>\n]\n\nPost.with_translations(\"de\")\n# => []\n```\n\n## Show different languages\n\nIn views, if there is content from different locales that you wish to display,\nyou should use the `with_locale` option with a block, as below:\n\n```erb\n\u003C% Globalize.with_locale(:en) do %>\n  \u003C%= render \"my_translated_partial\" %>\n\u003C% end %>\n```\n\nYour partial will now be rendered with the `:en` locale set as the current locale.\n\n## Interpolation\n\nGlobalize supports interpolation in a similar manner to I18n.\n\n```ruby\nclass Post \u003C ActiveRecord::Base\n  translates :title\nend\n\nI18n.locale = :en\npost.title = \"Globalize %{superlative}!\"\n\npost.title\n# #=> \"Globalize %{superlative}!\"\n\npost.title(:foo => \"bar\")\n# SomeError: missing interpolation argument :superlative\n\npost.title(:superlative => \"rocks\")\n# #=> \"Globalize rocks!\"\n```\n\n## Fragment caching\n\nDon't forget to add globalize locale into the `cache_key` to separate different localizations of the record.\nOne of the possible ways to implement it:\n\n```ruby\n# inside translated model\ndef cache_key\n  [super, Globalize.locale.to_s].join(\"-\")\nend\n```\n\n## Thread-safety\n\nGlobalize uses [request_store](https:\u002F\u002Fgithub.com\u002Fsteveklabnik\u002Frequest_store) gem to clean up thread-global variable after every request.\nRequestStore includes a Railtie that will configure everything properly.\n\nIf you're not using Rails, you may need to consult RequestStore's [README](https:\u002F\u002Fgithub.com\u002Fsteveklabnik\u002Frequest_store#no-rails-no-problem) to configure it.\n\n## Tutorials and articles\n* [Go Global with Rails and I18n](http:\u002F\u002Fwww.sitepoint.com\u002Fgo-global-rails-i18n\u002F) - introductory article about i18n in Rails (Ilya Bodrov)\n\n## Official Globalize extensions\n\n* [globalize-accessors](https:\u002F\u002Fgithub.com\u002Fglobalize\u002Fglobalize-accessors) - generator of accessor methods for models. *(e.g. title_en, title_cz)*\n* [globalize-versioning](https:\u002F\u002Fgithub.com\u002Fglobalize\u002Fglobalize-versioning) - versioning support for using Globalize with [`paper_trail`](https:\u002F\u002Fgithub.com\u002Fairblade\u002Fpaper_trail).\n","Globalize 是一个基于 Ruby on Rails 的 I18n API 为 ActiveRecord 模型提供数据翻译功能的库。其核心功能在于支持用户生成内容（如博客文章）的多语言翻译，通过简单的模型配置即可实现属性值的国际化。技术上，它依赖于 ActiveRecord 和 I18n 库，并且可以与 PostgreSQL 的 hstore 或 json\u002Fjsonb 数据类型结合使用来存储翻译信息。尽管目前维护活动较少，但 Globalize 仍然保持了对新版本 Ruby 和 Rails 的兼容性更新。适用于需要在 Rails 应用中实现数据库层面国际化处理的各种场景，尤其是那些需要管理多语言内容的应用程序。",2,"2026-06-11 03:15:44","top_language"]