GithubHelp home page GithubHelp logo

sowlutions / rails_admin_globalize_field Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rockhalil/rails_admin_globalize_field

0.0 0.0 0.0 78 KB

Tabbed interface and custom field type for globalize translations for Rails_admin

License: MIT License

JavaScript 1.91% Ruby 72.80% CSS 3.20% HTML 22.09%

rails_admin_globalize_field's Introduction

RailsAdminGlobalizeField

RailsAdminGlobalizeField adds tabbed interface to rails_admin for multilingual models (using globalize gem)

It adds custom field type that you can use for globalize translations association.

This gem uses Translation models generated by globalize, so you don't need to add any additional model to your app (as some older globalize3 gists suggested).

Installation

Add and configure globalize gem first.

  gem 'globalize', '~> 4.0'

Then add this gem and run bundle

  gem 'rails_admin_globalize_field'

Usage

Don't forget to set I18n.available_locale config, because it uses that to determine what tabs to show

Add translation models to config.included_models in initializers/rails_admin.rb:

  config.included_models = ['Model','Model::Translation']

Add accepts_nested_attributes_for for translations to your translated model.

  class Model < ActiveRecord::Base
    translates :title, :desc
    accepts_nested_attributes_for :translations, allow_destroy: true
  end

Add configuration to your translated model and associated translation model. :locale field is always required.

  config.model 'Post' do
    configure :translations, :globalize_tabs
  end

  config.model 'Model::Translation' do
    visible false
    configure :locale, :hidden do
      help ''
    end
    include_fields :locale, :title, :desc
  end

Add this stylesheet into app/assets/stylesheets/rails_admin/theming.scss:

  /*
   *= require rails_admin/ra.globalize_tabs
  */

If you need to add validation to the translation class, you can add it on translation_class inside translated model:

  translation_class.validates :title, presence: true

Known issues

If you need to use null: false options on any column in translations table, you'll have to use this globalize fork for now. See: globalize/globalize#325

Screenshot

Screenshot

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

rails_admin_globalize_field's People

Contributors

scarfacedeb avatar rockhalil avatar stream7 avatar rwd 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.