No release in over 3 years
Low commit activity in last 3 years
Validates translated attributes accessed with globalized accessors
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 4.2
~> 0.9
~> 1.3

Runtime

 Project Readme

Code Climate CI

Globalize-Validations

Globalize Validations validates your translated attributes for each given locales. The errors are added to the globalize attributes accessor names (example title_en).

globalize-validations is compatible with Rails 5.2, Rails 6.x and Rails 7.0.x.

Documentation

API documentation is available at rdoc.info.

Installation

Add this line to your application's Gemfile:

gem 'globalize-validations'

And then execute:

$ bundle

Usage

Default

class Page < ActiveRecord::Base
  translates :title, :body
  globalize_accessors locales: [:en, :es, :fr, :pl], attributes: [:title]
  globalize_validations # Will use Model.globalize_locales by default

  # Add all your validations before
  validate :validates_globalized_attributes
end

With custom locales

class Page < ActiveRecord::Base
  translates :title, :body
  globalize_accessors locales: [:en, :es, :fr, :pl], attributes: [:title]
  globalize_validations locales: [:en, :es] # Validates only `:en` and `:es` locales

  # Add all your validations before
  validate :validates_globalized_attributes
end

With custom locales as Proc

class Page < ActiveRecord::Base
  translates :title, :body
  globalize_accessors locales: [:en, :es, :fr, :pl], attributes: [:title]
  globalize_validations locales: Proc.new { |page| page.available_locales }

  # Add all your validations before
  validate :validates_globalized_attributes
end

Licence

Copyright (c) 2014 BookingSync released under the MIT license