All Projects → sedubois → mobility-actiontext

sedubois / mobility-actiontext

Licence: MIT license
Translate Rails Action Text rich text with Mobility.

Programming Languages

ruby
36898 projects - #4 most used programming language
HTML
75241 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to mobility-actiontext

Mobility
Pluggable Ruby translation framework
Stars: ✭ 644 (+2285.19%)
Mutual labels:  i18n, ruby-gem, translation, localization
React I18nify
Simple i18n translation and localization components and helpers for React.
Stars: ✭ 123 (+355.56%)
Mutual labels:  i18n, translation, localization
Phabricator zh hans
Phabricator zh-Hans Translation & Tools.
Stars: ✭ 113 (+318.52%)
Mutual labels:  i18n, translation, localization
I18n Extract
Manage localization with static analysis. 🔍
Stars: ✭ 152 (+462.96%)
Mutual labels:  i18n, translation, localization
Atom I18n
:atom: One Atom i18n Package for Any Locale 🌏 🌎 🌍
Stars: ✭ 56 (+107.41%)
Mutual labels:  i18n, translation, localization
React Intl Hooks
React hooks for internationalization without the hassle ⚛️🌍
Stars: ✭ 64 (+137.04%)
Mutual labels:  i18n, translation, localization
Punic
PHP translation and localization made easy!
Stars: ✭ 133 (+392.59%)
Mutual labels:  i18n, translation, localization
Fluent.js
JavaScript implementation of Project Fluent
Stars: ✭ 622 (+2203.7%)
Mutual labels:  i18n, translation, localization
Es2015 I18n Tag
ES2015 template literal tag for i18n and l10n (translation and internationalization)
Stars: ✭ 171 (+533.33%)
Mutual labels:  i18n, translation, localization
Node Gettext
A JavaScript implementation of gettext, a localization framework.
Stars: ✭ 175 (+548.15%)
Mutual labels:  i18n, translation, localization
React Translated
A dead simple way to add complex translations (i18n) in a React (DOM/Native) project 🌎🌍🌏
Stars: ✭ 176 (+551.85%)
Mutual labels:  i18n, translation, localization
Parrot
Self-hosted Localization Management Platform built with Go and Angular
Stars: ✭ 967 (+3481.48%)
Mutual labels:  i18n, translation, localization
Frenchkiss.js
The blazing fast lightweight internationalization (i18n) module for javascript
Stars: ✭ 776 (+2774.07%)
Mutual labels:  i18n, translation, localization
Pseudo Localization
Dynamic pseudo-localization in the browser and nodejs
Stars: ✭ 109 (+303.7%)
Mutual labels:  i18n, translation, localization
Weblate
Web based localization tool with tight version control integration.
Stars: ✭ 2,719 (+9970.37%)
Mutual labels:  i18n, translation, localization
Dom I18n
Provides a very basic HTML multilingual support using JavaScript
Stars: ✭ 125 (+362.96%)
Mutual labels:  i18n, translation, localization
React Localize Redux
Dead simple localization for your React components
Stars: ✭ 384 (+1322.22%)
Mutual labels:  i18n, translation, localization
Easy localization
Easy and Fast internationalizing your Flutter Apps
Stars: ✭ 407 (+1407.41%)
Mutual labels:  i18n, translation, localization
Formatjs
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Stars: ✭ 12,869 (+47562.96%)
Mutual labels:  i18n, translation, localization
Linguist
Easy multilingual urls and redirection support for the Laravel framework
Stars: ✭ 188 (+596.3%)
Mutual labels:  i18n, translation, localization

Mobility Action Text

Gem Version Build Status

Translate Rails Action Text rich text with Mobility.

Installation

Add this line to your application's Gemfile:

gem 'mobility-actiontext'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install mobility-actiontext

Make sure that Action Text is installed, then run this migration:

class TranslateRichTexts < ActiveRecord::Migration[6.1]
  def change
    # or null: true to allow untranslated rich text
    add_column :action_text_rich_texts, :locale, :string, null: false

    remove_index :action_text_rich_texts,
                 column: [:record_type, :record_id, :name],
                 name: :index_action_text_rich_texts_uniqueness,
                 unique: true
    add_index :action_text_rich_texts,
              [:record_type, :record_id, :name, :locale],
              name: :index_action_text_rich_texts_uniqueness,
              unique: true
  end
end

Usage

# app/models/message.rb
class Message < ApplicationRecord
+  extend Mobility
+
-  has_rich_text :content
+  translates :content, backend: :action_text
end

Plain text

Although the main purpose of the action_text_rich_texts table is to store rich text, this gem allows using it for plain text as well. This could be useful to consolidate all text in a single table and to remove the need to migrate data when converting between one and the other.

# app/models/message.rb
class Message < ApplicationRecord
   extend Mobility

+  translates :title, backend: :action_text, plain: true
   translates :content, backend: :action_text
end

Implementation note

Action Text's rich text content is saved in its own model that can be associated with any existing Active Record model using a polymorphic relation. Likewise, Mobility's KeyValue backend allows to translate any model using a polymorphic relation. This gem makes use of this similarity by combining both features in a single step, thus offering rich text "for free", i.e. in theory at no extra performance cost compared to untranslated rich text or translated plain text.

This is done through the Mobility::Backends::ActionText::Translation model extending ActionText::RichText. This model is backed by Action Text's existing action_text_rich_texts table and its existing name, body and record attributes, to which is added a new locale attribute.

Read more on the genesis of this gem.

Development

After checking out the repo, run bundle install to install dependencies.

Execute tests by running:

cd test_app
bundle install
bundle exec rails test

To release a new version, update lib/mobility/action_text/version.rb and CHANGELOG.md, run bundle && cd test_app && bundle, commit, then run bundle exec rake release. This will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sedubois/mobility-actiontext.

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].