No commit activity in last 3 years
No release in over 3 years
Extension from Virtus to add Localized feature
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 0
>= 0
 Project Readme

Virtus::Localized

Build Status

Virtus::Localized is an extension for virtus that adds the localized feature. It's based on the localized feature of MongoID and was requested via this issue

Installation

Add this line to your application's Gemfile:

gem 'virtus-localized'

And then execute:

$ bundle

Or install it yourself as:

$ gem install virtus-localized

Usage

You need to require it first:

  require 'virtus/localized'

Then it gives you the following flag when definig the attribute:

  class Post
    include Virtus.model

    attribute :title, String, localized: true
    attribute :body, String, localized: true
  end

It uses the i18n to detect the locale and creates an internal hash for the attribute:

  post = Post.new(title: 'Hello', body: 'English')

  p post.title
  # => 'Hello'

  p post.body
  # => 'English'

  I18n.locale = :es

  post.title = 'Hola'
  post.body = 'Español'

  p post.title
  # => 'Hola'

  p post.body
  # => 'Español'

  p post.instance_variable_get('@title')
  # { "en" => "Hello", "es" => "Hola" }

  p post.instance_variable_get('@body')
  # { "en" => "English", "es" => "Español" }

Contributing

  1. Fork it ( https://github.com/[my-github-username]/virtus-localized/fork )
  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 a new Pull Request

License

MIT