{"id":22025777,"url":"https://github.com/para-cms/para-i18n","last_synced_at":"2025-05-07T09:35:51.853Z","repository":{"id":56887415,"uuid":"58532792","full_name":"para-cms/para-i18n","owner":"para-cms","description":"Para plugin to translate your models","archived":false,"fork":false,"pushed_at":"2020-09-14T13:46:02.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T08:45:06.750Z","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/para-cms.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-11T09:44:29.000Z","updated_at":"2020-09-14T13:46:05.000Z","dependencies_parsed_at":"2022-08-21T00:20:52.219Z","dependency_job_id":null,"html_url":"https://github.com/para-cms/para-i18n","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/para-cms%2Fpara-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/para-cms%2Fpara-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/para-cms%2Fpara-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/para-cms%2Fpara-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/para-cms","download_url":"https://codeload.github.com/para-cms/para-i18n/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252851869,"owners_count":21814233,"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-11-30T07:19:46.700Z","updated_at":"2025-05-07T09:35:51.832Z","avatar_url":"https://github.com/para-cms.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Para::I18n\n\nThis gem allows for translating models content within the [Para](https://github.com/para-cms/para)\nadmin interface.\n\nIt works by adding a translations layer to ActiveRecord models, like Globalize\ndoes, and with a similar API, but using JSON fields instead of tables.\n\n**Note** : This gem only works with Postgres 9.4+\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'para-i18n'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install para-i18n\n\nAdd the para-i18n javascript file to your app's admin manifest at `app/assets/javascripts/admin/app.(js|coffee)` :\n\n```javascript\n//= require para/i18n\n```\n\n## Usage\n\nTo allow models to be translated, you need to add the `_translations:jsonb`\ncolumn to your model.\n\nYou can use the `para:i18n:translate` generator to generate the migration.\nFor example, to translate a page model :\n\n```bash\nrails generate para:i18n:translate page -m\n```\n\nNote that the `-m` option automatically migrates after the migration is\ncreated.\n\nNow that your model has the translations field in the table, juste use the\n`translates` macro in your model to define which fields will be translated :\n\n```ruby\nclass Page \u003c ActiveRecord::Base\n  translates :title, :content\nend\n```\n\nNow, any `crud` component managing the `Page` model will show a button to access\nthe translation interface for existing entries.\n\n### Overriding the translations form\n\nThe translation form can be overriden by generating it with the `para:i18n:form`\ngenerator. This is useful to delete or add fields to translate that are not\nproperly displayed by the default view.\n\nFor example, the `Page` model translation form can be generated the following\nway :\n\n```bash\nrails g para:i18n:form page\n```\n\nThis will create a partial at `app/views/admin/pages/_translations_form.html.haml`\nthat you can override.\n\n### Translation fields customization\n\nThis gem uses a special [Simple Form](https://github.com/plataformatec/simple_form)\ninput to manage translations.\n\nExample :\n\n```ruby\n= form.input :title, as: :i18n, locale: @target_locale\n```\n\nWhen generating the translations form, you can edit those inputs, remove or add\nsome inputs.\n\n#### Managing nested resources\n\nYou can simply manage nested resources by using the `simple_fields_for` form\nhelper :\n\n```ruby\n= form.simple_fields_for :nested_resources do |fields|\n  = fields.input :nested_title, as: :i18n, locale: @target_locale\n```\n\n#### Passing options to the translation field\n\nThe I18n field generates a plain HTML section with the original contents of the\nfield (in the `I18n.default_locale` locale), and a sub-input, which uses the\ndefault type that Para infers from the attribute.\n\nYou can override the generated field type or pass other options by using the\n`:input_html` option :\n\n```ruby\n= form.input :value, as: :i18n, locale: @target_locale, input_html: { as: :numeric, spinner: false }\n```\n\nAlso, if your original content contains useful HTML, you can use the `:html_safe`\nto be applied to the original content by using the `:original_html` option :\n\n```ruby\n= form.input :value, as: :i18n, locale: @target_locale, original_html: { html_safe: true }\n```\n\n### Locales fallbacks support\n\nThe gem fully supports Rails' I18n fallbacks and will try to fallback to any\navailable translation using the `I18n.fallbacks` hash if you enable them.\n\nIf not enabled, any untranslated content will be empty.\n\n### Friendly id support\n\nThe gem comes with friendly_id i18n support, with a dedicated `:i18n` module to\ninclude instead of the `:slugged` module into your models friendly_id options.\n\nFor example, for the page :\n\n```ruby\nclass Page \u003c ActiveRecord::Base\n  translates :title, :slug\n\n  friendly_id :title, use: [:finders, :i18n]\nend\n```\n\n\u003e **Warning** : You always need to put the `:i18n` fiendly_id module after all\nother modules, so the finder methods included in this module take the current\nlocale into account.\n\nThis will automatically build localized slugs when updating the `title` in any\nlocale, and will allow you to find the resources with the translated slugs.\n\nNote that if I18n fallbacks are enabled, it will try to fall back to the next\nlocale if no resource was found for the given slug and locale.\n\n## Migrating from Globalize\n\nThere's a dedicated section in the Wiki that can help your migrate your app grom Globalize to Para::I18n.\n\nYou can find this guide here : [Migrating from Globalize](https://github.com/para-cms/para-i18n/wiki/Migrating-from-Globalize)\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/para-cms/para-i18n.\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%2Fpara-cms%2Fpara-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpara-cms%2Fpara-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpara-cms%2Fpara-i18n/lists"}