{"id":21285498,"url":"https://github.com/takeyuweb/globalize-automatic","last_synced_at":"2025-06-20T00:04:22.836Z","repository":{"id":56874624,"uuid":"79728029","full_name":"takeyuweb/globalize-automatic","owner":"takeyuweb","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-10T06:59:16.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-04T08:36:11.553Z","etag":null,"topics":["globalize","rails"],"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/takeyuweb.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-01-22T16:06:40.000Z","updated_at":"2018-12-03T15:17:32.000Z","dependencies_parsed_at":"2022-08-20T10:11:12.124Z","dependency_job_id":null,"html_url":"https://github.com/takeyuweb/globalize-automatic","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/takeyuweb/globalize-automatic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Fglobalize-automatic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Fglobalize-automatic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Fglobalize-automatic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Fglobalize-automatic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takeyuweb","download_url":"https://codeload.github.com/takeyuweb/globalize-automatic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Fglobalize-automatic/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260852095,"owners_count":23072587,"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":["globalize","rails"],"created_at":"2024-11-21T11:20:45.800Z","updated_at":"2025-06-20T00:04:17.792Z","avatar_url":"https://github.com/takeyuweb.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Globalize Automatic\n-\n\n## Installation\n\n```ruby\ngem install globalize-automatic\n```\n\n### Rails 5.0\n\nIn your Gemfile\n\n```ruby\ngem 'globalize-automatic', github: 'takeyuweb/globalize-automatic', branch: 'rails-5-0'\n```\n\nand\n\n```bash\nbundle install\n```\n\n## Configuration\n\n```ruby\n# config/initializers/globalize_automatic.rb\nrequire 'globalize-automatic'\nGlobalize::Automatic.translator = \n  Globalize::Automatic::Translator::EasyTranslate.new\n\n# EasyTranslate configuration\nEasyTranslate.api_key = 'xxx'\n```\n\n## Example\n\n### 宣言\n\n```ruby\nclass Post\n  # Automatically translated from English.\n  translates :title, :text, automatic: :en\nend\n```\n\n```ruby\nclass Post\n  # Automatically translated from English or Japanese. (English preferred)\n  translates :title, :text, automatic: %i(en ja)\nend\n```\n\n```ruby\nclass Post\n  # Automatically translated from English\n  translates :title, :text, automatic: { from: :en, to: %i(ja fr vi) }\nend\n```\n\n```ruby\nclass CreatePostAutomatics \u003c ActiveRecord::Migration\n  def up\n    Post.create_translation_table! title: :string, text: :text\n    Post.create_automatic_translation_table! :title, :text\n  end\n    \n  def down\n    Post.drop_translation_table!\n    Post.drop_automatic_translation_table!\n  end\nend\n```\n\n#### 自動翻訳対象を追加\n\n```ruby\nclass AddPostAutomatics \u003c ActiveRecord::Migration\n  def up\n    Post.add_translation_fields! description: :text\n    Post.add_automatic_translation_fields! :description\n  end\n    \n  def down\n    remove_column :post_automatic_translations, :description\n    remove_column :post_automatic_translations, :description_automatically\n  end\nend\n```\n\n### 更新\n\n#### 自動翻訳\n\n```ruby\nI18n.locale = :en\npost.title = 'globalize'\npost.save!\n\npost.title_ja_automatic # =\u003e false\npost.title_vi_automatic # =\u003e true\n\npost.reload\n\nI18n.locale = :ja\npost.title # =\u003e nil\nI18n.locale = :vi\npost.title # =\u003e 'โลกาภิวัฒน์'\n```\n\n```ruby\npost.attributes = {\n   title_en: 'globalize',\n   title_ja_automatic: true\n}\npost.save!\n\npost.reload\n\nI18n.locale = :en\npost.title # =\u003e 'globalize'\nI18n.locale = :ja\npost.title # =\u003e '国際化'\n```\n\n#### 自動翻訳無効化\n\n```ruby\npost.attributes = {\n   title_en: 'globalize',\n   title_fr_automatic: false,\n   title_fr: 'Hoge'\n}\npost.save!\n\npost.reload\n\nI18n.locale = :en\npost.title # =\u003e 'globalize'\nI18n.locale = :vi\npost.title # =\u003e 'โลกาภิวัฒน์'\nI18n.locale = :fr\npost.title # =\u003e 'hoge'\n```\n\n### 自動翻訳の原文優先順位\n\n```ruby\nclass Post\n  # Automatically translated from English or Japanese. (English preferred)\n  translates :title, :text, automatic: %i(en ja)\nend\n\npost = Post.new\npost.attributes = {\n    title_en: 'English',\n    title_ja: '日本語'\n}\npost.save!\n\npost.reload\n\nI18n.locale = :fr\npost.title # =\u003e 'Anglais' # It means 'English'.\n```\n\n```ruby\nclass Post\n  # Automatically translated from English or Japanese. (English preferred)\n  translates :title, :text, automatic: %i(en ja)\nend\n\npost = Post.new\npost.attributes = {\n    title_en: nil,\n    title_ja: '日本語'\n}\npost.save!\n\npost.reload\n\nI18n.locale = :fr\npost.title # =\u003e 'Japonais' # It means '日本語'.\n```\n\n### 取得\n\n#### 翻訳文属性名\n\n[globalize-accessors](https://github.com/globalize/globalize-accessors)\n\n```ruby\nPost.globalize_attribute_names # =\u003e [:title_ja, :title_en, :title_fr, :title_vi, :text_ja, :text_en, :text_fr, :text_vi]\n```\n\n#### 自動翻訳有効/無効属性名\n\n```ruby\nPost.automatic_translation_attribute_names # =\u003e [:title_ja_automatically, :title_en_automatically, :title_fr_automatically, :title_vi_automatically, :text_ja_automatically, :text_en_automatically, :text_fr_automatically, :text_vi_automatically]\n```\n\nstrong parameters\n\n```ruby\npermitted = Post.globalize_attribute_names + Post.automatic_translation_attribute_names\nparams.require(:post).permit(*permitted)\n```\n\n### 非同期\n\nActiveJobを利用による非同期翻訳\n\n```ruby\n# config/initializers/globalize_automatic.rb\nGlobalize::Automatic.asynchronously = true\n```\n\n### 他の翻訳ライブラリやサービスへの対応\n\nTranslatorクラスを書けば対応できます。\n\n```ruby\nclass YourTranslator \u003c Globalize::Automatic::Translator\n  def translate(text, from, to)\n    # 適当な翻訳処理を行って訳文を返す\n    return translated\n  end\nend\n\nGlobalize::Automatic.translator = YourTranslator::EasyTranslate.new\n```\n\n## TODO\n\n- EasyTranslate依存の切り出し\n  - 他の翻訳ライブラリやサービスへの対応。\n    - Microsoft Translator\n    - Gengo etc\n\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/takeyuweb/globalize_automatic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.\n\n## Licence\n\nCopyright (c) 2017 Yuichi Takeuchi released under the MIT license\n\nThis project rocks and uses MIT-LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakeyuweb%2Fglobalize-automatic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakeyuweb%2Fglobalize-automatic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakeyuweb%2Fglobalize-automatic/lists"}