gettext_i18n_rails 2.1.0 → 2.2.0
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.
- checksums.yaml +4 -4
- data/lib/gettext_i18n_rails/action_controller.rb +2 -6
- data/lib/gettext_i18n_rails/active_model/name.rb +3 -3
- data/lib/gettext_i18n_rails/active_model/translation.rb +18 -1
- data/lib/gettext_i18n_rails/active_record.rb +1 -1
- data/lib/gettext_i18n_rails/model_attributes_finder.rb +28 -38
- data/lib/gettext_i18n_rails/version.rb +1 -1
- data/lib/gettext_i18n_rails.rb +15 -0
- metadata +10 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e54b27b13a1bc165ba1d15d79124499d2adf0560db0a6b15fd03561568cdf23c
|
|
4
|
+
data.tar.gz: 284c940646692e1873590a4c549fd15b96632293ca103f3d4749cc46abc37aba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20c95818e777b9a708cfdcd1f819c1b1accdf3b877d20e8e1eb063c735083751e7ec10c34bc1f74154566faac287986a9139976b5aaa674d86acd5b59011a080
|
|
7
|
+
data.tar.gz: 2a46d0373c0d1641cf62ff67d74fea96a25f2e4b7fe3008e5332e8dc92d4e18ac7d4bc4aa194e69abfecfc439e13aa71947026b1d0f0a31dd65ed75328b05dd4
|
|
@@ -10,10 +10,6 @@ path_controller = ->() {
|
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
ActiveSupport.on_load(:action_controller_base) do
|
|
15
|
-
path_controller.call
|
|
16
|
-
end
|
|
17
|
-
else
|
|
13
|
+
ActiveSupport.on_load(:action_controller_base) do
|
|
18
14
|
path_controller.call
|
|
19
|
-
end
|
|
15
|
+
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
module ActiveModel
|
|
2
2
|
Name.class_eval do
|
|
3
3
|
def human(options={})
|
|
4
|
-
|
|
4
|
+
msgid = @klass.gettext_model_name_msgid
|
|
5
5
|
|
|
6
6
|
if count = options[:count]
|
|
7
|
-
n_(
|
|
7
|
+
n_(msgid, msgid.pluralize, count)
|
|
8
8
|
else
|
|
9
|
-
_(
|
|
9
|
+
_(msgid)
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -8,7 +8,8 @@ module ActiveModel
|
|
|
8
8
|
def gettext_translation_for_attribute_name(attribute)
|
|
9
9
|
attribute = attribute.to_s
|
|
10
10
|
if attribute.end_with?('_id')
|
|
11
|
-
|
|
11
|
+
# foreign keys share the associated model's msgid (see #207)
|
|
12
|
+
gettext_resolve_legacy_msgid(attribute.sub(/_id\z/, '').camelize, humanize_class_name(attribute))
|
|
12
13
|
else
|
|
13
14
|
attribute_key = attribute.split('.').map! {|a| a.humanize }.join('|')
|
|
14
15
|
root = inheritance_tree_root(self).to_s
|
|
@@ -40,5 +41,21 @@ module ActiveModel
|
|
|
40
41
|
name ||= self.to_s
|
|
41
42
|
name.underscore.humanize
|
|
42
43
|
end
|
|
44
|
+
|
|
45
|
+
# Canonical msgid for a model name is the raw class name (see #207),
|
|
46
|
+
# e.g. "SomeNamespace::SomeModel" -- consistent with human_attribute_name.
|
|
47
|
+
def gettext_model_name_msgid
|
|
48
|
+
gettext_resolve_legacy_msgid(to_s, humanize_class_name)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Returns +current+, unless only the legacy msgid resolves to a
|
|
52
|
+
# translation -- then +legacy+ is returned and a deprecation is warned
|
|
53
|
+
# once. Keeps pre-#207 .po files working during the transition.
|
|
54
|
+
def gettext_resolve_legacy_msgid(current, legacy)
|
|
55
|
+
return current if current == legacy || FastGettext.cached_find(current) || !FastGettext.cached_find(legacy)
|
|
56
|
+
|
|
57
|
+
GettextI18nRails.warn_legacy_model_msgid(legacy, current)
|
|
58
|
+
legacy
|
|
59
|
+
end
|
|
43
60
|
end
|
|
44
61
|
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require 'rails/version'
|
|
2
|
-
require 'rails'
|
|
2
|
+
require 'rails'
|
|
3
3
|
|
|
4
4
|
module GettextI18nRails
|
|
5
5
|
#write all found models/columns to a file where GetTexts ruby parser can find them
|
|
@@ -9,12 +9,11 @@ module GettextI18nRails
|
|
|
9
9
|
File.open(file,'w') do |f|
|
|
10
10
|
f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
|
|
11
11
|
ModelAttributesFinder.new.find(options).each do |model,column_names|
|
|
12
|
-
f.puts(
|
|
12
|
+
f.puts(gettext_extraction_call(model.to_s))
|
|
13
13
|
|
|
14
14
|
#all columns namespaced under the model
|
|
15
15
|
column_names.each do |attribute|
|
|
16
|
-
|
|
17
|
-
f.puts("_('#{translation}')")
|
|
16
|
+
f.puts(gettext_extraction_call(model.gettext_translation_for_attribute_name(attribute)))
|
|
18
17
|
end
|
|
19
18
|
end
|
|
20
19
|
f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!"
|
|
@@ -28,6 +27,18 @@ module GettextI18nRails
|
|
|
28
27
|
end
|
|
29
28
|
module_function :store_model_attributes
|
|
30
29
|
|
|
30
|
+
# Model-name msgids (no '|') are emitted as an n_() singular/plural pair, so the
|
|
31
|
+
# .po file carries msgid_plural for `model_name.human(count:)`. Attribute msgids
|
|
32
|
+
# (scoped with '|') have no plural form and stay singular. See issue #207.
|
|
33
|
+
def gettext_extraction_call(msgid)
|
|
34
|
+
if msgid.include?('|')
|
|
35
|
+
"_('#{msgid}')"
|
|
36
|
+
else
|
|
37
|
+
"n_('#{msgid}', '#{msgid.pluralize}')"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
module_function :gettext_extraction_call
|
|
41
|
+
|
|
31
42
|
class ModelAttributesFinder
|
|
32
43
|
# options:
|
|
33
44
|
# :ignore_tables => ['cars',/_settings$/,...]
|
|
@@ -43,29 +54,15 @@ module GettextI18nRails
|
|
|
43
54
|
end
|
|
44
55
|
|
|
45
56
|
def initialize
|
|
46
|
-
|
|
47
|
-
@existing_tables = (Rails::VERSION::MAJOR >= 5 ? connection.data_sources : connection.tables)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Rails 7.0 has deprecated direct_descendants in favor of subclasses.
|
|
51
|
-
# It was removed completely in Rails 7.1.
|
|
52
|
-
# This will maintain backwards compatibility with Rails 3.0 - 6.1
|
|
53
|
-
def subclass_method
|
|
54
|
-
if Rails::VERSION::MAJOR < 7
|
|
55
|
-
:direct_descendants
|
|
56
|
-
else
|
|
57
|
-
:subclasses
|
|
58
|
-
end
|
|
57
|
+
@existing_tables = ::ActiveRecord::Base.connection.data_sources
|
|
59
58
|
end
|
|
60
59
|
|
|
61
60
|
# Rails < 3.0 doesn't have DescendantsTracker.
|
|
62
61
|
# Instead of iterating over ObjectSpace (slow) the decision was made NOT to support
|
|
63
62
|
# class hierarchies with abstract base classes in Rails 2.x
|
|
64
63
|
def model_attributes(model, ignored_tables, ignored_cols)
|
|
65
|
-
return [] if model.abstract_class? && Rails::VERSION::MAJOR < 3
|
|
66
|
-
|
|
67
64
|
if model.abstract_class?
|
|
68
|
-
model.
|
|
65
|
+
model.subclasses.reject {|m| ignored?(m.table_name, ignored_tables)}.inject([]) do |attrs, m|
|
|
69
66
|
attrs.push(model_attributes(m, ignored_tables, ignored_cols)).flatten.uniq
|
|
70
67
|
end
|
|
71
68
|
elsif !ignored?(model.table_name, ignored_tables) && @existing_tables.include?(model.table_name)
|
|
@@ -76,25 +73,18 @@ module GettextI18nRails
|
|
|
76
73
|
end
|
|
77
74
|
|
|
78
75
|
def models
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
end
|
|
76
|
+
# Ensure autoloaders are set up before we attempt to eager load!
|
|
77
|
+
Rails.application.autoloaders.each(&:setup) if Rails.application.respond_to?(:autoloaders)
|
|
78
|
+
Rails.application.eager_load! # make sure that all models are loaded so that direct_descendants works
|
|
79
|
+
descendants = ::ActiveRecord::Base.subclasses
|
|
80
|
+
|
|
81
|
+
# In rails 5+ user models are supposed to inherit from ApplicationRecord
|
|
82
|
+
if defined?(::ApplicationRecord)
|
|
83
|
+
descendants += ApplicationRecord.subclasses
|
|
84
|
+
descendants.delete ApplicationRecord
|
|
85
|
+
end
|
|
90
86
|
|
|
91
|
-
|
|
92
|
-
else
|
|
93
|
-
::ActiveRecord::Base.connection.tables \
|
|
94
|
-
.map { |t| table_name_to_namespaced_model(t) } \
|
|
95
|
-
.compact \
|
|
96
|
-
.collect { |c| c.superclass.abstract_class? ? c.superclass : c }
|
|
97
|
-
end.uniq.sort_by(&:name)
|
|
87
|
+
descendants.uniq.sort_by(&:name)
|
|
98
88
|
end
|
|
99
89
|
|
|
100
90
|
def ignored?(name,patterns)
|
data/lib/gettext_i18n_rails.rb
CHANGED
|
@@ -3,6 +3,21 @@ require 'gettext_i18n_rails/gettext_hooks'
|
|
|
3
3
|
|
|
4
4
|
module GettextI18nRails
|
|
5
5
|
IGNORE_TABLES = [/^sitemap_/, /_versions$/, 'schema_migrations', 'sessions', 'delayed_jobs']
|
|
6
|
+
|
|
7
|
+
# Issue #207: model-name msgids changed from the humanized form
|
|
8
|
+
# ("Big car") to the raw class name ("BigCar"), matching attributes.
|
|
9
|
+
# The humanized form is still looked up as a fallback; warn once per
|
|
10
|
+
# msgid so apps can migrate their .po files.
|
|
11
|
+
def self.warn_legacy_model_msgid(legacy, current)
|
|
12
|
+
@warned_legacy_model_msgids ||= {}
|
|
13
|
+
return if @warned_legacy_model_msgids.key?(legacy)
|
|
14
|
+
@warned_legacy_model_msgids[legacy] = true
|
|
15
|
+
warn(
|
|
16
|
+
"[gettext_i18n_rails] msgid #{legacy.inspect} is deprecated, " \
|
|
17
|
+
"re-extract and translate #{current.inspect} instead " \
|
|
18
|
+
"(https://github.com/grosser/gettext_i18n_rails/issues/207)"
|
|
19
|
+
)
|
|
20
|
+
end
|
|
6
21
|
end
|
|
7
22
|
|
|
8
23
|
# translate from everywhere
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gettext_i18n_rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Grosser
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: fast_gettext
|
|
@@ -44,14 +43,14 @@ dependencies:
|
|
|
44
43
|
requirements:
|
|
45
44
|
- - ">="
|
|
46
45
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
46
|
+
version: '0'
|
|
48
47
|
type: :development
|
|
49
48
|
prerelease: false
|
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
50
|
requirements:
|
|
52
51
|
- - ">="
|
|
53
52
|
- !ruby/object:Gem::Version
|
|
54
|
-
version:
|
|
53
|
+
version: '0'
|
|
55
54
|
- !ruby/object:Gem::Dependency
|
|
56
55
|
name: haml
|
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -140,17 +139,16 @@ dependencies:
|
|
|
140
139
|
name: sqlite3
|
|
141
140
|
requirement: !ruby/object:Gem::Requirement
|
|
142
141
|
requirements:
|
|
143
|
-
- - "
|
|
142
|
+
- - ">="
|
|
144
143
|
- !ruby/object:Gem::Version
|
|
145
|
-
version: '
|
|
144
|
+
version: '0'
|
|
146
145
|
type: :development
|
|
147
146
|
prerelease: false
|
|
148
147
|
version_requirements: !ruby/object:Gem::Requirement
|
|
149
148
|
requirements:
|
|
150
|
-
- - "
|
|
149
|
+
- - ">="
|
|
151
150
|
- !ruby/object:Gem::Version
|
|
152
|
-
version: '
|
|
153
|
-
description:
|
|
151
|
+
version: '0'
|
|
154
152
|
email: michael@grosser.it
|
|
155
153
|
executables: []
|
|
156
154
|
extensions: []
|
|
@@ -180,7 +178,6 @@ homepage: http://github.com/grosser/gettext_i18n_rails
|
|
|
180
178
|
licenses:
|
|
181
179
|
- MIT
|
|
182
180
|
metadata: {}
|
|
183
|
-
post_install_message:
|
|
184
181
|
rdoc_options: []
|
|
185
182
|
require_paths:
|
|
186
183
|
- lib
|
|
@@ -188,15 +185,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
188
185
|
requirements:
|
|
189
186
|
- - ">="
|
|
190
187
|
- !ruby/object:Gem::Version
|
|
191
|
-
version: 3.
|
|
188
|
+
version: 3.2.0
|
|
192
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
190
|
requirements:
|
|
194
191
|
- - ">="
|
|
195
192
|
- !ruby/object:Gem::Version
|
|
196
193
|
version: '0'
|
|
197
194
|
requirements: []
|
|
198
|
-
rubygems_version: 3.
|
|
199
|
-
signing_key:
|
|
195
|
+
rubygems_version: 3.6.9
|
|
200
196
|
specification_version: 4
|
|
201
197
|
summary: Simple FastGettext Rails integration.
|
|
202
198
|
test_files: []
|