Git Product home page Git Product logo

activeadmin-globalize's Introduction

ActiveAdmin::Globalize

Makes it easy to translate your resource fields.

Gem Version Build Status

Installation

This version targets Rails 4 and greater and ActiveAdmin >= 1.0.0.pre.

gem 'activeadmin-globalize', '~> 1.0.0.pre', github: 'fabn/activeadmin-globalize', branch: 'develop'

As soon as ActiveAdmin 1.x is released to rubygems, I'll release the gem with no need for github dependency. See this issue for more details.

Previous version with support for Rails 3 is maintained in branch support/0.6.x

Your model

active_admin_translates :title, :description do
  validates_presence_of :title
end

In your Active Admin resource definition

Important note: I'm working on a fix for #4 because after AA deprecated and then removed #form_buffers the syntax shown below for form declaration doesn't work as is. See comments in code and discussion to fix it until I found a solution.

# For usage with strong parameters you'll need to permit them
permit_params translations_attributes: [:id, :locale, :title, :description, :_destroy]

index do
  # textual translation status
  translation_status
  # or with flag icons
  translation_status_flags
  # ...
  actions
end

# This was the original syntax proposed in this gem, however currently it doesn't work
form do |f|
  # ...
  f.translated_inputs "Translated fields", switch_locale: false do |t|
    t.input :title
    t.input :description
  end
  # ...
end

# Instead you have to nest the block inside an #inputs block and the title
# should be passed to the inputs method
form do |f|
  # ...
  f.inputs "Translated fields" do
    f.translated_inputs 'ignored title', switch_locale: false do |t|
      t.input :title
      t.input :description
    end
  end
  # ...
end

# You can also set locales to show in tabs
# For example we want to show English translation fields without tab, and want to show other languages within tabs 
form do |f|
  # ...
  f.inputs do
    Globalize.with_locale(:en) do
      f.input :title
    end
  end
  f.inputs "Translated fields" do
    f.translated_inputs 'ignored title', switch_locale: false, available_locales: (I18n.available_locales - [:en]) do |t|
      t.input :title
      t.input :description
    end
  end
  # ...
end

# You can also set default language tab
# For example we want to make Bengali translation tab as default
form do |f|
  # ...
  f.inputs "Translated fields" do
    f.translated_inputs 'ignored title', switch_locale: false, default_locale: :bn do |t|
      t.input :title
      t.input :description
    end
  end
  # ...
end

If switch_locale is set, each tab will be rendered switching locale.

Hints

To use the dashed locale keys as 'pt-BR' or 'pt-PT' you need to convert a string to symbol (in application.rb)

  config.i18n.available_locales = [:en, :it, :de, :es, :"pt-BR"]

Credits

This work is based on original idea by @stefanoverna, I needed it for AA 0.6.x so I forked the original project and expanded it with more features.

activeadmin-globalize's People

Contributors

ahmadsherif avatar armands2ar avatar delphaber avatar dtengeri avatar fabn avatar humancopy avatar jeansreal avatar jklimke avatar joanamartins avatar marcusg avatar mzampetti avatar nebirhos avatar raihan2006i avatar sepastian avatar spleenteo avatar stefanoverna avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.