hooktstudios-globalize3 0.2.0.beta8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ module Globalize
2
+ module ActiveRecord
3
+ class Translation < ::ActiveRecord::Base
4
+ class << self
5
+ # Sometimes ActiveRecord queries .table_exists? before the table name
6
+ # has even been set which results in catastrophic failure.
7
+ def table_exists?
8
+ table_name.present? && super
9
+ end
10
+
11
+ def with_locales(*locales)
12
+ # Avoid using "IN" with SQL queries when only using one locale.
13
+ locales = locales.flatten.map(&:to_s)
14
+ locales = locales.first if locales.one?
15
+ where(:locale => locales)
16
+ end
17
+ alias with_locale with_locales
18
+
19
+ def translated_locales
20
+ select('DISTINCT locale').map(&:locale)
21
+ end
22
+ end
23
+
24
+ def locale
25
+ read_attribute(:locale).to_sym
26
+ end
27
+
28
+ def locale=(locale)
29
+ write_attribute(:locale, locale.to_s)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ # Setting this will force polymorphic associations to subclassed objects
36
+ # to use their table_name rather than the parent object's table name,
37
+ # which will allow you to get their models back in a more appropriate
38
+ # format.
39
+ #
40
+ # See http://www.ruby-forum.com/topic/159894 for details.
41
+ Globalize::ActiveRecord::Translation.abstract_class = true
@@ -0,0 +1,5 @@
1
+ module Globalize
2
+ module Versioning
3
+ autoload :PaperTrail, 'globalize/versioning/paper_trail'
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ require 'paper_trail'
2
+
3
+ module Globalize
4
+ module Versioning
5
+ module PaperTrail
6
+ # At present this isn't used but we may use something similar in paper trail
7
+ # shortly, so leaving it around to reference easily.
8
+ #def versioned_columns
9
+ #super + self.class.translated_attribute_names
10
+ #end
11
+ end
12
+ end
13
+ end
14
+
15
+ ActiveRecord::Base.class_eval do
16
+ class << self
17
+ def has_paper_trail_with_globalize(*args)
18
+ has_paper_trail_without_globalize(*args)
19
+ include Globalize::Versioning::PaperTrail
20
+ end
21
+ alias_method_chain :has_paper_trail, :globalize
22
+ end
23
+ end
24
+
25
+ Version.class_eval do
26
+
27
+ before_save do |version|
28
+ version.locale = Globalize.locale.to_s
29
+ end
30
+
31
+ def self.locale_conditions_to_sql
32
+ "locale = '#{Globalize.locale.to_s}'"
33
+ end
34
+
35
+ scope :for_this_locale, lambda{ { :conditions => locale_conditions_to_sql } }
36
+
37
+ def sibling_versions_with_locales
38
+ sibling_versions_without_locales.for_this_locale
39
+ end
40
+ alias_method_chain :sibling_versions, :locales
41
+ end
@@ -0,0 +1 @@
1
+ require 'globalize'
@@ -0,0 +1,3 @@
1
+ module Globalize3
2
+ VERSION = '0.2.0.beta8'
3
+ end
@@ -0,0 +1,41 @@
1
+ # A simple exception handler that behaves like the default exception handler
2
+ # but additionally logs missing translations to a given log.
3
+ #
4
+ # Useful for identifying missing translations during testing.
5
+ #
6
+ # E.g.
7
+ #
8
+ # require 'globalize/i18n/missing_translations_log_handler'
9
+ # I18n.missing_translations_logger = RAILS_DEFAULT_LOGGER
10
+ # I18n.exception_handler = :missing_translations_log_handler
11
+ #
12
+ # To set up a different log file:
13
+ #
14
+ # logger = Logger.new("#{RAILS_ROOT}/log/missing_translations.log")
15
+ # I18n.missing_translations_logger = logger
16
+
17
+ module I18n
18
+ @@missing_translations_logger = nil
19
+
20
+ class << self
21
+ def missing_translations_logger
22
+ @@missing_translations_logger ||= begin
23
+ require 'logger' unless defined?(Logger)
24
+ Logger.new(STDOUT)
25
+ end
26
+ end
27
+
28
+ def missing_translations_logger=(logger)
29
+ @@missing_translations_logger = logger
30
+ end
31
+
32
+ def missing_translations_log_handler(exception, locale, key, options)
33
+ if MissingTranslationData === exception
34
+ missing_translations_logger.warn(exception.message)
35
+ return exception.message
36
+ else
37
+ raise exception
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ # A simple exception handler that behaves like the default exception handler
2
+ # but also raises on missing translations.
3
+ #
4
+ # Useful for identifying missing translations during testing.
5
+ #
6
+ # E.g.
7
+ #
8
+ # require 'globalize/i18n/missing_translations_raise_handler'
9
+ # I18n.exception_handler = :missing_translations_raise_handler
10
+ module I18n
11
+ class << self
12
+ def missing_translations_raise_handler(exception, locale, key, options)
13
+ raise exception
14
+ end
15
+ end
16
+ end
17
+
18
+ I18n.exception_handler = :missing_translations_raise_handler
19
+
20
+ ActionView::Helpers::TranslationHelper.module_eval do
21
+ def translate(key, options = {})
22
+ I18n.translate(key, options)
23
+ end
24
+ alias :t :translate
25
+ end
@@ -0,0 +1,35 @@
1
+ require 'active_record/attribute_methods/query'
2
+
3
+ module ActiveRecord
4
+ module AttributeMethods
5
+ module Query
6
+ def query_attribute(attr_name)
7
+ unless value = read_attribute(attr_name)
8
+ false
9
+ else
10
+ column = self.class.columns_hash[attr_name]
11
+ if column.nil?
12
+
13
+ # TODO submit a rails patch
14
+
15
+ # not sure what active_record tests say but i guess this should mean:
16
+ # call to_i and check zero? if the value is a Numeric or starts with
17
+ # a digit, so it can meaningfully be typecasted by to_i
18
+
19
+ # if Numeric === value || value !~ /[^0-9]/
20
+ if Numeric === value || value.to_s =~ /^[0-9]/
21
+ !value.to_i.zero?
22
+ else
23
+ return false if ActiveRecord::ConnectionAdapters::Column::FALSE_VALUES.include?(value)
24
+ !value.blank?
25
+ end
26
+ elsif column.number?
27
+ !value.zero?
28
+ else
29
+ !value.blank?
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ require 'active_record/serializers/xml_serializer'
2
+
3
+ ActiveRecord::XmlSerializer::Attribute.class_eval do
4
+ def compute_type_with_translations
5
+ klass = @serializable.class
6
+ if klass.translates? && klass.translated_attribute_names.include?(name.to_sym)
7
+ :string
8
+ else
9
+ compute_type_without_translations
10
+ end
11
+ end
12
+ alias_method_chain :compute_type, :translations
13
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hooktstudios-globalize3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0.beta8
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Sven Fuchs
9
+ - Joshua Harvey
10
+ - Clemens Kofler
11
+ - John-Paul Bader
12
+ - Tomasz Stachewicz
13
+ - Philip Arndt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+ date: 2012-06-20 00:00:00.000000000Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: activerecord
21
+ requirement: &70095976764300 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ type: :runtime
28
+ prerelease: false
29
+ version_requirements: *70095976764300
30
+ - !ruby/object:Gem::Dependency
31
+ name: activemodel
32
+ requirement: &70095976763800 !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: *70095976763800
41
+ - !ruby/object:Gem::Dependency
42
+ name: paper_trail
43
+ requirement: &70095976763340 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '2'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: *70095976763340
52
+ - !ruby/object:Gem::Dependency
53
+ name: database_cleaner
54
+ requirement: &70095976762880 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - =
58
+ - !ruby/object:Gem::Version
59
+ version: 0.5.2
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *70095976762880
63
+ - !ruby/object:Gem::Dependency
64
+ name: mocha
65
+ requirement: &70095976762500 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: *70095976762500
74
+ - !ruby/object:Gem::Dependency
75
+ name: pathname_local
76
+ requirement: &70095976762040 !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: *70095976762040
85
+ - !ruby/object:Gem::Dependency
86
+ name: test_declarative
87
+ requirement: &70095976761620 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: *70095976761620
96
+ - !ruby/object:Gem::Dependency
97
+ name: sqlite3
98
+ requirement: &70095976761200 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: *70095976761200
107
+ description: ! 'Rails I18n: de-facto standard library for ActiveRecord 3 model/data
108
+ translation.'
109
+ email: nobody@globalize-rails.org
110
+ executables: []
111
+ extensions: []
112
+ extra_rdoc_files: []
113
+ files:
114
+ - lib/globalize/active_record/act_macro.rb
115
+ - lib/globalize/active_record/adapter.rb
116
+ - lib/globalize/active_record/attributes.rb
117
+ - lib/globalize/active_record/class_methods.rb
118
+ - lib/globalize/active_record/exceptions.rb
119
+ - lib/globalize/active_record/instance_methods.rb
120
+ - lib/globalize/active_record/migration.rb
121
+ - lib/globalize/active_record/translation.rb
122
+ - lib/globalize/active_record.rb
123
+ - lib/globalize/versioning/paper_trail.rb
124
+ - lib/globalize/versioning.rb
125
+ - lib/globalize.rb
126
+ - lib/globalize3/version.rb
127
+ - lib/globalize3.rb
128
+ - lib/i18n/missing_translations_log_handler.rb
129
+ - lib/i18n/missing_translations_raise_handler.rb
130
+ - lib/patches/active_record/query_method.rb
131
+ - lib/patches/active_record/xml_attribute_serializer.rb
132
+ - Gemfile
133
+ - LICENSE
134
+ - Rakefile
135
+ - README.textile
136
+ homepage: http://github.com/svenfuchs/globalize3
137
+ licenses: []
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>'
152
+ - !ruby/object:Gem::Version
153
+ version: 1.3.1
154
+ requirements: []
155
+ rubyforge_project: ! '[none]'
156
+ rubygems_version: 1.8.10
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: ! 'Rails I18n: de-facto standard library for ActiveRecord 3 model/data translation'
160
+ test_files: []