gettext_i18n_rails 1.11.0 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gettext_i18n_rails/base_parser.rb +4 -7
- data/lib/gettext_i18n_rails/gettext_hooks.rb +2 -10
- data/lib/gettext_i18n_rails/model_attributes_finder.rb +14 -3
- data/lib/gettext_i18n_rails/version.rb +1 -1
- metadata +3 -4
- data/lib/gettext_i18n_rails/ruby_gettext_extractor.rb +0 -137
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69d12d7e3eebbd04ad80e403f237187601791f071ca5ff28d014b5c4a9bb08d8
|
4
|
+
data.tar.gz: cb74abbea8ef5e823ba2e6cf34c8f739ce3305d30cd7a5e431644c78e63dcc5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a30e6228cc71ec651fcbb0a69ccc37ded90217a03e273fc3ed01eabed2993344681b4a0c40f4ae674574fd19acd3400c7913397a03573c35dfd16929ab8d5a79
|
7
|
+
data.tar.gz: fa9ec02c26510fc184b3c0d1476ca595e7f5212a30037c597cf04f535e1ecad8538f452fbd707b438073f21b979f147a26bee2b817097d5bc79055b145325409
|
@@ -6,13 +6,10 @@ module GettextI18nRails
|
|
6
6
|
File.extname(file) == ".#{extension}"
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.parse(file,
|
10
|
-
return
|
9
|
+
def self.parse(file, options = {}, _msgids = [])
|
10
|
+
return _msgids unless load_library
|
11
11
|
code = convert_to_code(File.read(file))
|
12
|
-
|
13
|
-
rescue Racc::ParseError => e
|
14
|
-
$stderr.puts "file ignored: ruby_parser cannot read #{extension} files with 1.9 syntax --- #{file}: (#{e.message.strip})"
|
15
|
-
return msgids
|
12
|
+
GetText::RubyParser.new(file, options).parse_source(code)
|
16
13
|
end
|
17
14
|
|
18
15
|
def self.libraries
|
@@ -37,7 +34,7 @@ module GettextI18nRails
|
|
37
34
|
return false
|
38
35
|
end
|
39
36
|
|
40
|
-
require '
|
37
|
+
require 'gettext/tools/parser/ruby'
|
41
38
|
@library_loaded = loaded
|
42
39
|
end
|
43
40
|
end
|
@@ -1,22 +1,14 @@
|
|
1
1
|
module GettextI18nRails
|
2
2
|
module GettextHooks
|
3
|
-
#
|
3
|
+
# shorter call / maybe the interface changes again ...
|
4
4
|
def self.add_parser(parser)
|
5
5
|
xgettext.add_parser(parser)
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.xgettext
|
9
9
|
@xgettext ||= begin
|
10
|
-
require 'gettext/tools/xgettext'
|
10
|
+
require 'gettext/tools/xgettext'
|
11
11
|
GetText::Tools::XGetText
|
12
|
-
rescue LoadError
|
13
|
-
begin
|
14
|
-
require 'gettext/tools/rgettext' # 2.0 - 2.2
|
15
|
-
GetText::RGetText
|
16
|
-
rescue LoadError # # 1.x
|
17
|
-
require 'gettext/rgettext'
|
18
|
-
GetText::RGetText
|
19
|
-
end
|
20
12
|
end
|
21
13
|
end
|
22
14
|
end
|
@@ -46,6 +46,17 @@ module GettextI18nRails
|
|
46
46
|
@existing_tables = (Rails::VERSION::MAJOR >= 5 ? connection.data_sources : connection.tables)
|
47
47
|
end
|
48
48
|
|
49
|
+
# Rails 7.0 has deprecated direct_descendants in favor of subclasses.
|
50
|
+
# It was removed completely in Rails 7.1.
|
51
|
+
# This will maintain backwards compatibility with Rails 3.0 - 6.1
|
52
|
+
def subclass_method
|
53
|
+
if Rails::VERSION::MAJOR < 7
|
54
|
+
:direct_descendants
|
55
|
+
else
|
56
|
+
:subclasses
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
49
60
|
# Rails < 3.0 doesn't have DescendantsTracker.
|
50
61
|
# Instead of iterating over ObjectSpace (slow) the decision was made NOT to support
|
51
62
|
# class hierarchies with abstract base classes in Rails 2.x
|
@@ -53,7 +64,7 @@ module GettextI18nRails
|
|
53
64
|
return [] if model.abstract_class? && Rails::VERSION::MAJOR < 3
|
54
65
|
|
55
66
|
if model.abstract_class?
|
56
|
-
model.
|
67
|
+
model.send(subclass_method).reject {|m| ignored?(m.table_name, ignored_tables)}.inject([]) do |attrs, m|
|
57
68
|
attrs.push(model_attributes(m, ignored_tables, ignored_cols)).flatten.uniq
|
58
69
|
end
|
59
70
|
elsif !ignored?(model.table_name, ignored_tables) && @existing_tables.include?(model.table_name)
|
@@ -68,11 +79,11 @@ module GettextI18nRails
|
|
68
79
|
# Ensure autoloaders are set up before we attempt to eager load!
|
69
80
|
Rails.application.autoloaders.each(&:setup) if Rails.application.respond_to?(:autoloaders)
|
70
81
|
Rails.application.eager_load! # make sure that all models are loaded so that direct_descendants works
|
71
|
-
descendants = ::ActiveRecord::Base.
|
82
|
+
descendants = ::ActiveRecord::Base.send(subclass_method)
|
72
83
|
|
73
84
|
# In rails 5+ user models are supposed to inherit from ApplicationRecord
|
74
85
|
if defined?(::ApplicationRecord)
|
75
|
-
descendants += ApplicationRecord.
|
86
|
+
descendants += ApplicationRecord.send(subclass_method)
|
76
87
|
descendants.delete ApplicationRecord
|
77
88
|
end
|
78
89
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gettext_i18n_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fast_gettext
|
@@ -199,7 +199,6 @@ files:
|
|
199
199
|
- lib/gettext_i18n_rails/i18n_hacks.rb
|
200
200
|
- lib/gettext_i18n_rails/model_attributes_finder.rb
|
201
201
|
- lib/gettext_i18n_rails/railtie.rb
|
202
|
-
- lib/gettext_i18n_rails/ruby_gettext_extractor.rb
|
203
202
|
- lib/gettext_i18n_rails/slim_parser.rb
|
204
203
|
- lib/gettext_i18n_rails/string_interpolate_fix.rb
|
205
204
|
- lib/gettext_i18n_rails/tasks.rb
|
@@ -224,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
223
|
- !ruby/object:Gem::Version
|
225
224
|
version: '0'
|
226
225
|
requirements: []
|
227
|
-
rubygems_version: 3.
|
226
|
+
rubygems_version: 3.4.10
|
228
227
|
signing_key:
|
229
228
|
specification_version: 4
|
230
229
|
summary: Simple FastGettext Rails integration.
|
@@ -1,137 +0,0 @@
|
|
1
|
-
gem 'ruby_parser', '>= 3.7.1' # sync with gemspec
|
2
|
-
require 'ruby_parser'
|
3
|
-
|
4
|
-
gem 'sexp_processor'
|
5
|
-
require 'sexp_processor'
|
6
|
-
|
7
|
-
module RubyGettextExtractor
|
8
|
-
extend self
|
9
|
-
|
10
|
-
def parse(file, targets = []) # :nodoc:
|
11
|
-
parse_string(File.read(file), targets, file)
|
12
|
-
end
|
13
|
-
|
14
|
-
def parse_string(content, targets = [], file)
|
15
|
-
syntax_tree = RubyParser.for_current_ruby.parse(content, file)
|
16
|
-
|
17
|
-
processor = Extractor.new(targets)
|
18
|
-
processor.require_empty = false
|
19
|
-
processor.process(syntax_tree)
|
20
|
-
|
21
|
-
processor.results
|
22
|
-
end
|
23
|
-
|
24
|
-
class Extractor < SexpProcessor
|
25
|
-
attr_reader :results
|
26
|
-
|
27
|
-
def initialize(targets)
|
28
|
-
@targets = {}
|
29
|
-
@results = []
|
30
|
-
|
31
|
-
targets.each do |a|
|
32
|
-
k, _v = a
|
33
|
-
# things go wrong if k already exists, but this
|
34
|
-
# should not happen (according to the gettext doc)
|
35
|
-
@targets[k] = a
|
36
|
-
@results << a
|
37
|
-
end
|
38
|
-
|
39
|
-
super()
|
40
|
-
end
|
41
|
-
|
42
|
-
def extract_string(node)
|
43
|
-
case node.first
|
44
|
-
when :str
|
45
|
-
node.last
|
46
|
-
when :call
|
47
|
-
type, recv, meth, args = node
|
48
|
-
# node has to be in form of "string" + "other_string"
|
49
|
-
return nil unless recv && meth == :+
|
50
|
-
|
51
|
-
first_part = extract_string(recv)
|
52
|
-
second_part = extract_string(args)
|
53
|
-
|
54
|
-
first_part && second_part ? first_part.to_s + second_part.to_s : nil
|
55
|
-
else
|
56
|
-
nil
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def extract_key_singular(args, separator)
|
61
|
-
key = extract_string(args) if args.size == 2 || args.size == 4
|
62
|
-
|
63
|
-
return nil unless key
|
64
|
-
key.gsub("\n", '\n').gsub("\t", '\t').gsub("\0", '\0')
|
65
|
-
end
|
66
|
-
|
67
|
-
def extract_key_plural(args, separator)
|
68
|
-
# this could be n_("aaa", "aaa plural", @retireitems.length)
|
69
|
-
# s(s(:str, "aaa"),
|
70
|
-
# s(:str, "aaa plural"),
|
71
|
-
# s(:call, s(:ivar, :@retireitems), :length))
|
72
|
-
# all strings arguments are extracted and joined with \004 or \000
|
73
|
-
arguments = args[0..(-2)]
|
74
|
-
|
75
|
-
res = []
|
76
|
-
arguments.each do |a|
|
77
|
-
next unless a.kind_of? Sexp
|
78
|
-
str = extract_string(a)
|
79
|
-
res << str if str
|
80
|
-
end
|
81
|
-
|
82
|
-
key = res.empty? ? nil : res.join(separator)
|
83
|
-
|
84
|
-
return nil unless key
|
85
|
-
key.gsub("\n", '\n').gsub("\t", '\t').gsub("\0", '\0')
|
86
|
-
end
|
87
|
-
|
88
|
-
def store_key(key, args)
|
89
|
-
if key
|
90
|
-
res = @targets[key]
|
91
|
-
|
92
|
-
unless res
|
93
|
-
res = [key]
|
94
|
-
@results << res
|
95
|
-
@targets[key] = res
|
96
|
-
end
|
97
|
-
|
98
|
-
res << "#{args.file}:#{args.line}"
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def gettext_simple_call(args)
|
103
|
-
# args comes in 2 forms:
|
104
|
-
# s(s(:str, "Button Group Order:"))
|
105
|
-
# s(:str, "Button Group Order:")
|
106
|
-
# normalizing:
|
107
|
-
args = args.first if Sexp === args.sexp_type
|
108
|
-
|
109
|
-
key = extract_key_singular(args, "\004")
|
110
|
-
store_key(key, args)
|
111
|
-
end
|
112
|
-
|
113
|
-
def gettext_plural_call(args)
|
114
|
-
key = extract_key_plural(args, "\000")
|
115
|
-
store_key(key, args)
|
116
|
-
end
|
117
|
-
|
118
|
-
def process_call exp
|
119
|
-
_call = exp.shift
|
120
|
-
_recv = process exp.shift
|
121
|
-
meth = exp.shift
|
122
|
-
|
123
|
-
case meth
|
124
|
-
when :_, :p_, :N_, :pgettext, :s_
|
125
|
-
gettext_simple_call(exp)
|
126
|
-
when :n_
|
127
|
-
gettext_plural_call(exp)
|
128
|
-
end
|
129
|
-
|
130
|
-
until exp.empty? do
|
131
|
-
process(exp.shift)
|
132
|
-
end
|
133
|
-
|
134
|
-
s()
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|