gettext_i18n_rails 1.11.0 → 1.12.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21ca313fab159243b410640c4fdd81980a9f9a9c9f7500b904b1b520cd25a596
|
4
|
+
data.tar.gz: 63f42039049902975af11131868ee12906d137151f43bdd5e86551fadc733080
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d07bbab9c35abdb23b4e208b22c08c9be2051ac64dfa043c9a47013ca6ff92c8741356b950df53e809d90003c44db6183e9167e34a83856242c6a0d80c113486
|
7
|
+
data.tar.gz: aba525c859c885518513c71d2086d2bfe1cb65fa48c3781bf8ac64a9e1d8009626519011b4011d7b51f9ca10ab9a8e1ffb71dcc269586fe97ecf82ceb0afa7de
|
@@ -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
|
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.12.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: 2023-
|
11
|
+
date: 2023-06-21 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
|
@@ -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
|