项目作者: richardvenneman

项目描述 :
🌐 Mobility integration plugin for the Trestle admin framework
高级语言: Ruby
项目地址: git://github.com/richardvenneman/trestle-mobility.git
创建时间: 2019-04-08T10:05:36Z
项目社区:https://github.com/richardvenneman/trestle-mobility

开源协议:MIT License

下载


Trestle Mobility Integration (trestle-mobility)

Mobility integration plugin for the Trestle admin framework

Gem

Features / problems

  • Manage Mobility translations with a space-efficient dropdown interface in Trestle
  • Supports text fields, text area’s and check boxes
  • Integrates with DeepL Pro to automatically translate fields

Trestle Mobility screenshot

Getting started

These instructions assume you have a working Trestle application. To integrate trestle-mobility, first add it to your application’s Gemfile:

  1. gem 'trestle-mobility'

Run bundle install, and then run the install generator to set up configuration options.

  1. $ rails generate trestle:mobility:install

Usage

Trestle Mobility requires you to enable Mobility’s locale_accessors plugin.

Assuming you’ve setup your models with Mobility’s translates directives, you can use the mobility_text_field, mobility_text_area and mobility_check_box field types:

  1. Trestle.resource(:posts) do
  2. form do |post|
  3. mobility_text_field :title
  4. mobility_text_field :subtitle
  5. mobility_text_area :content
  6. mobility_check_box :published
  7. end
  8. end

Trestle Mobility allows you to specify the language that is selected by default:

  1. mobility_text_field :subtitle, selected: "nl"

By default Trestle Mobility uses I18n.available_locales to generate the form fields, but you can specify the languages on a per-field basis:

  1. mobility_text_field :title, locales: %w(nl de fr)

Quoting Mobility’s README:

(Note however that Mobility will complain if you have I18n.enforce_available_locales set to true and you try accessing a locale not present in I18n.available_locales; set it to false if you want to allow any locale.)

DeepL translation

Trestle Mobility DeepL integration screenshot

Trestle Mobility can automatically populate empty field values with translations from other languages. This functionality is powered by the excellent deepl-rb gem. To make use of this, add deepl-rb to your Gemfile and specify your DeepL Pro API key in your Trestle initializer:

  1. config.mobility.deepl_api_key = "YOUR-API-KEY"

It is possible to pass any DeepL API options to the field (check out the deepl-rb documentation section on params):

  1. mobility_text_area :content, rows: 14, deepl_query_params: { tag_handling: "xml" }