GithubHelp home page GithubHelp logo

uken / i18n-active_record Goto Github PK

View Code? Open in Web Editor NEW

This project forked from svenfuchs/i18n-active_record

0.0 47.0 2.0 148 KB

I18n ActiveRecord backend

License: MIT License

Ruby 99.04% Logos 0.96%

i18n-active_record's Introduction

I18n::Backend::ActiveRecord

This repository contains the I18n ActiveRecord backend and support code that has been extracted from the I18n.

Installation

For Bundler put the following in your Gemfile:

  gem 'i18n-active_record',
      :git => 'git://github.com/svenfuchs/i18n-active_record.git',
      :require => 'i18n/active_record'

Next create a active record model named Translation with the Rails Generator.
Your migration should look like this:

  class CreateTranslations < ActiveRecord::Migration
    def self.up
      create_table :translations do |t|
        t.string :locale
        t.string :key
        t.text   :value
        t.text   :interpolations
        t.boolean :is_proc, :default => false

        t.timestamps
      end
    end

    def self.down
      drop_table :translations
    end
  end

With this translation model you will be able to manage your translation, and add new translations or languages through
it.

To load I18n::Backend::ActiveRecord into your Rails application, create a new file in config/initializers named locale.rb.

A simple configuration for your locale.rb could look like this:

  require 'i18n/backend/active_record'
  I18n.backend = I18n::Backend::ActiveRecord.new

A more advanced example (Thanks Moritz), which uses YAML files and ActiveRecord for lookups:

  require 'i18n/backend/active_record'
  
  Translation  = I18n::Backend::ActiveRecord::Translation
  
  if Translation.table_exists?
    I18n.backend = I18n::Backend::ActiveRecord.new

    I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
    I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Flatten)
    I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
    I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)

    I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
  end

Usage

You can now use I18n.t('Your String') to lookup translations in the database.

Maintainers

  • Sven Fuchs

i18n-active_record's People

Contributors

agustinf avatar avakhov avatar jeremyw avatar kaspth avatar mpataki avatar nearlyfreeapps avatar pawelnguyen avatar slbug avatar svenfuchs avatar timfjord avatar tomfast avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.