Giter VIP home page Giter VIP logo

globalize2's Introduction

Globalize2

Globalize2 is the successor of Globalize for Rails.

It is compatible with and builds on the new I18n api in Ruby on Rails. and adds model translations to ActiveRecord.

Globalize2 is much more lightweight and compatible than its predecessor was. Model translations in Globalize2 use default ActiveRecord features and do not limit any ActiveRecord functionality any more.

Requirements

ActiveRecord
I18n

(or Rails > 2.2)

Installation

To install Globalize2 with its default setup just use:


script/plugin install git://github.com/joshmh/globalize2.git

Model translations

Model translations allow you to translate your models’ attribute values. E.g.


class Post < ActiveRecord::Base
  translates :title, :text
end

Allows you to values for the attributes :title and :text per locale:


I18n.locale = :en
post.title # => Globalize2 rocks!

I18n.locale = :he
post.title # => גלובאלייז2 שולט!

In order to make this work, you’ll need to add the appropriate translation tables. Globalize2 comes with a handy helper method to help you do this. It’s called create_translation_table!. Here’s an example:


class CreatePosts < ActiveRecord::Migration
  def self.up
    create_table :posts do |t|
      t.timestamps
    end
    Post.create_translation_table! :title => :string, :text => :text
  end
  def self.down
    drop_table :posts
    Post.drop_translation_table!
  end
end

Note that the ActiveRecord model Post must already exist and have a translates directive listing the translated fields.

Migration from Globalize

See this script by Tomasz Stachewicz: http://gist.github.com/120867

globalize2's People

Contributors

hukl avatar joshmh avatar mseppae avatar phuesler avatar veger avatar zencocoon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.