drogus-genderized 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008 Piotr Sarnacki
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,7 @@
1
+ h1. Genderized
2
+
3
+ Rails plugin supporting gender with I18n translations. It requires russian gem
4
+
5
+ h2. Usage
6
+
7
+
@@ -0,0 +1,31 @@
1
+ # The following is taken from custom_error_message plugin by David Easley
2
+ # (http://rubyforge.org/projects/custom-err-msg/)
3
+ module ActiveRecord
4
+ class Errors
5
+
6
+ # Redefine the ActiveRecord::Errors::full_messages method:
7
+ # Returns all the full error messages in an array. 'Base' messages are handled as usual.
8
+ # Non-base messages are prefixed with the attribute name as usual UNLESS they begin with '^'
9
+ # in which case the attribute name is omitted.
10
+ # E.g. validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
11
+ def full_messages
12
+ full_messages = []
13
+
14
+ @errors.each_key do |attr|
15
+ @errors[attr].each do |msg|
16
+ next if msg.nil?
17
+
18
+ if attr == "base"
19
+ full_messages << msg
20
+ elsif msg =~ /^\^/
21
+ full_messages << msg[1..-1]
22
+ else
23
+ full_messages << @base.class.human_attribute_name(attr) + " " + msg
24
+ end
25
+ end
26
+ end
27
+
28
+ return full_messages
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ module ActiveRecord
2
+ class Errors
3
+
4
+ # Add gender support to messages.
5
+ # Try to get :gender key of attribute. If it's not set, pass
6
+ # the default gender (neuter)
7
+ def generate_message_with_gender(attribute, message = :invalid, options = {})
8
+ gender_defaults = @base.class.self_and_descendents_from_active_record.map do |klass|
9
+ :"activerecord.attributes.#{klass.name.underscore}.#{attribute}.gender"
10
+ end
11
+
12
+ gender_defaults << "neuter"
13
+ key = gender_defaults.shift
14
+ gender = I18n.translate(key, {:default => gender_defaults})
15
+ options.merge!({:gender => gender})
16
+
17
+ generate_message_without_gender(attribute, message, options)
18
+ end
19
+
20
+ alias_method_chain :generate_message, :gender
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ module I18n
2
+ module Backend
3
+
4
+
5
+ # Genderized backend.
6
+ # Currently it is subclass of Advanced backend from
7
+ # russian gem - it will be changed in naxt releases.
8
+ class Genderized < Advanced
9
+
10
+ # If entry is a hash and it includes given gender,
11
+ # return entry for given gender.
12
+ def genderize(locale, entry, gender)
13
+ return entry unless entry.is_a?(Hash) and gender and entry.has_key?(gender.to_sym)
14
+
15
+ entry[gender.to_sym]
16
+ end
17
+
18
+ def translate(locale, key, options = {})
19
+ raise InvalidLocale.new(locale) if locale.nil?
20
+ return key.map{|k| translate locale, k, options } if key.is_a? Array
21
+
22
+ reserved = :scope, :default, :gender
23
+ count, scope, default, gender = options.values_at(:count, *reserved)
24
+ options.delete(:default)
25
+ values = options.reject{|name, value| reserved.include? name }
26
+
27
+ entry = lookup(locale, key, scope)
28
+ if entry.nil?
29
+ entry = default(locale, default, options)
30
+ if entry.nil?
31
+ raise(I18n::MissingTranslationData.new(locale, key, options))
32
+ end
33
+ end
34
+ entry = genderize(locale, entry, gender)
35
+ entry = pluralize locale, entry, count
36
+ entry = interpolate locale, entry, values
37
+ entry
38
+ end
39
+ end
40
+ end
41
+ end
data/lib/genderized.rb ADDED
@@ -0,0 +1,30 @@
1
+ KCODE='u'
2
+
3
+ $:.push File.join(File.dirname(__FILE__), 'genderized')
4
+
5
+ # genderized backend
6
+ require 'backend/genderized'
7
+
8
+ # Rails hacks
9
+ if defined?(ActiveRecord)
10
+ require 'active_record_ext/custom_error_message'
11
+ require 'active_record_ext/error_messages_with_gender'
12
+ end
13
+
14
+ module Genderized
15
+ module VERSION
16
+ MAJOR = 0
17
+ MINOR = 0
18
+ TINY = 2
19
+
20
+ STRING = [MAJOR, MINOR, TINY].join('.')
21
+ end
22
+
23
+ class << self
24
+ def set_backend
25
+ I18n.backend = I18n::Backend::Genderized.new
26
+ end
27
+ end
28
+ end
29
+
30
+ Genderized.set_backend
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drogus-genderized
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Piotr Sarnacki
8
+ autorequire: genderized
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-02 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: yaroslav-russian
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.6
23
+ version:
24
+ description: Basic suppot for translations with gender support for Ruby and Rails
25
+ email: piotr.sarnacki@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README.textile
32
+ - MIT-LICENSE
33
+ files:
34
+ - lib/active_record_ext
35
+ - lib/active_record_ext/error_messages_with_gender.rb
36
+ - lib/active_record_ext/custom_error_message.rb
37
+ - lib/genderized
38
+ - lib/genderized/backend
39
+ - lib/genderized/backend/genderized.rb
40
+ - lib/genderized.rb
41
+ - README.textile
42
+ - MIT-LICENSE
43
+ has_rdoc: true
44
+ homepage: http://github.com/yaroslav/russian/
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.2.0
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: Basic suppot for translations with gender support for Ruby and Rails
69
+ test_files: []
70
+