Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chipairon-i18n-active_record

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chipairon-i18n-active_record

  • 0.0.4
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

h1. I18n::Backend::ActiveRecord

This repository contains the I18n ActiveRecord backend and support code that has been extracted from the "I18n":http://github.com/svenfuchs/i18n.

h2. 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 adavanced example (Thanks Moritz), which uses YAML files and ActiveRecord for lookups:

  require 'i18n/backend/active_record'
  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)

h2. Usage

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

h2. Maintainers

  • Sven Fuchs

FAQs

Package last updated on 21 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc