gettext_i18n_rails 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed99097612654d09733a3d63ac71dfc1284aac5d
|
4
|
+
data.tar.gz: 3509111d78ec79cab4102e021b91911cda7efe75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b5cd433328403fe28752dda13a54255376fffa27ca76cd8dde4b14eaaed66a072863943c94139f05683affbe00ff18ce5bc09e47aa8c6c0bc71f5141394e96d
|
7
|
+
data.tar.gz: e09b985cbf7eaaf11204ad0248eb49060e0a9a45baeb737826bdcaa4dfeec325bb79303fdd84becf6146ad009859dd5b3769f9c282a3a1a9d6be4039601812b8
|
@@ -9,7 +9,7 @@ module GettextI18nRails
|
|
9
9
|
def self.parse(file, msgids = [])
|
10
10
|
return msgids unless load_library
|
11
11
|
code = convert_to_code(File.read(file))
|
12
|
-
RubyGettextExtractor.parse_string(code,
|
12
|
+
RubyGettextExtractor.parse_string(code, msgids, file)
|
13
13
|
rescue Racc::ParseError => e
|
14
14
|
$stderr.puts "file ignored: ruby_parser cannot read #{extension} files with 1.9 syntax --- #{file}: (#{e.message.strip})"
|
15
15
|
return msgids
|
@@ -1,37 +1,36 @@
|
|
1
|
-
|
1
|
+
gem 'ruby_parser', '>= 3.7.1' # sync with gemspec
|
2
2
|
require 'ruby_parser'
|
3
3
|
|
4
|
+
gem 'sexp_processor'
|
5
|
+
require 'sexp_processor'
|
6
|
+
|
4
7
|
module RubyGettextExtractor
|
5
8
|
extend self
|
6
9
|
|
7
10
|
def parse(file, targets = []) # :nodoc:
|
8
|
-
|
9
|
-
parse_string(content, file, targets)
|
11
|
+
parse_string(File.new(file), targets)
|
10
12
|
end
|
11
13
|
|
12
|
-
def parse_string(content,
|
13
|
-
|
14
|
+
def parse_string(content, targets = [], file = nil)
|
15
|
+
syntax_tree = RubyParser.for_current_ruby.parse(content)
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
Extractor19.new(file, targets)
|
19
|
-
end
|
20
|
-
parser.run(content)
|
21
|
-
end
|
17
|
+
processor = Extractor.new(targets, file)
|
18
|
+
processor.require_empty = false
|
19
|
+
processor.process(syntax_tree)
|
22
20
|
|
23
|
-
|
24
|
-
return file =~ /\.rb$/
|
21
|
+
processor.results
|
25
22
|
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
class Extractor < SexpProcessor
|
25
|
+
attr_reader :results
|
26
|
+
|
27
|
+
def initialize(targets, file_name = nil)
|
28
|
+
@file_name = file_name
|
29
|
+
@targets = {}
|
31
30
|
@results = []
|
32
31
|
|
33
32
|
targets.each do |a|
|
34
|
-
k,
|
33
|
+
k, _v = a
|
35
34
|
# things go wrong if k already exists, but this
|
36
35
|
# should not happen (according to the gettext doc)
|
37
36
|
@targets[k] = a
|
@@ -41,99 +40,100 @@ module RubyGettextExtractor
|
|
41
40
|
super()
|
42
41
|
end
|
43
42
|
|
44
|
-
def run(content)
|
45
|
-
# ruby parser has an ugly bug which causes that several \000's take
|
46
|
-
# ages to parse. This avoids this probelm by stripping them away (they probably wont appear in keys anyway)
|
47
|
-
# See bug report: http://rubyforge.org/tracker/index.php?func=detail&aid=26898&group_id=439&atid=1778
|
48
|
-
safe_content = content.gsub(/\\\d\d\d/, '')
|
49
|
-
self.parse(safe_content)
|
50
|
-
return @results
|
51
|
-
end
|
52
|
-
|
53
43
|
def extract_string(node)
|
54
|
-
|
55
|
-
|
56
|
-
|
44
|
+
case node.first
|
45
|
+
when :str
|
46
|
+
node.last
|
47
|
+
when :call
|
57
48
|
type, recv, meth, args = node
|
58
|
-
|
59
|
-
# node has to be in form of "string"+"other_string"
|
49
|
+
# node has to be in form of "string" + "other_string"
|
60
50
|
return nil unless recv && meth == :+
|
61
51
|
|
62
|
-
first_part
|
52
|
+
first_part = extract_string(recv)
|
63
53
|
second_part = extract_string(args)
|
64
54
|
|
65
|
-
|
66
|
-
return first_part.to_s + second_part.to_s
|
55
|
+
first_part && second_part ? first_part.to_s + second_part.to_s : nil
|
67
56
|
else
|
68
|
-
|
57
|
+
nil
|
69
58
|
end
|
70
59
|
end
|
71
60
|
|
72
|
-
def
|
73
|
-
key =
|
74
|
-
if args.size == 2
|
75
|
-
key = extract_string(args.value)
|
76
|
-
else
|
77
|
-
# this could be n_("aaa","aaa2",1)
|
78
|
-
# all strings arguemnts are extracted and joined with \004 or \000
|
79
|
-
|
80
|
-
arguments = args[1..(-1)]
|
61
|
+
def extract_key_singular(args, separator)
|
62
|
+
key = extract_string(args) if args.size == 2 || args.size == 4
|
81
63
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
# only add strings
|
86
|
-
res << str if str
|
87
|
-
end
|
64
|
+
return nil unless key
|
65
|
+
key.gsub("\n", '\n').gsub("\t", '\t').gsub("\0", '\0')
|
66
|
+
end
|
88
67
|
|
89
|
-
|
90
|
-
|
68
|
+
def extract_key_plural(args, separator)
|
69
|
+
# this could be n_("aaa", "aaa plural", @retireitems.length)
|
70
|
+
# s(s(:str, "aaa"),
|
71
|
+
# s(:str, "aaa plural"),
|
72
|
+
# s(:call, s(:ivar, :@retireitems), :length))
|
73
|
+
# all strings arguments are extracted and joined with \004 or \000
|
74
|
+
arguments = args[0..(-2)]
|
75
|
+
|
76
|
+
res = []
|
77
|
+
arguments.each do |a|
|
78
|
+
next unless a.kind_of? Sexp
|
79
|
+
str = extract_string(a)
|
80
|
+
res << str if str
|
91
81
|
end
|
92
82
|
|
93
|
-
|
94
|
-
|
95
|
-
key.gsub!("\n", '\n')
|
96
|
-
key.gsub!("\t", '\t')
|
97
|
-
key.gsub!("\0", '\0')
|
83
|
+
key = res.empty? ? nil : res.join(separator)
|
98
84
|
|
99
|
-
return key
|
85
|
+
return nil unless key
|
86
|
+
key.gsub("\n", '\n').gsub("\t", '\t').gsub("\0", '\0')
|
100
87
|
end
|
101
88
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
# skip
|
89
|
+
def store_key(key, args)
|
90
|
+
if key
|
91
|
+
res = @targets[key]
|
92
|
+
|
93
|
+
unless res
|
94
|
+
res = [key]
|
95
|
+
@results << res
|
96
|
+
@targets[key] = res
|
111
97
|
end
|
112
98
|
|
113
|
-
|
114
|
-
|
99
|
+
file_name = @file_name.nil? ? args.file : @file_name
|
100
|
+
res << "#{file_name}:#{args.line}"
|
101
|
+
end
|
102
|
+
end
|
115
103
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
104
|
+
def gettext_simple_call(args)
|
105
|
+
# args comes in 2 forms:
|
106
|
+
# s(s(:str, "Button Group Order:"))
|
107
|
+
# s(:str, "Button Group Order:")
|
108
|
+
# normalizing:
|
109
|
+
args = args.first if Sexp === args.sexp_type
|
121
110
|
|
122
|
-
|
123
|
-
|
124
|
-
|
111
|
+
key = extract_key_singular(args, "\004")
|
112
|
+
store_key(key, args)
|
113
|
+
end
|
125
114
|
|
126
|
-
|
115
|
+
def gettext_plural_call(args)
|
116
|
+
key = extract_key_plural(args, "\000")
|
117
|
+
store_key(key, args)
|
127
118
|
end
|
128
|
-
end
|
129
119
|
|
130
|
-
|
131
|
-
|
132
|
-
|
120
|
+
def process_call exp
|
121
|
+
_call = exp.shift
|
122
|
+
_recv = process exp.shift
|
123
|
+
meth = exp.shift
|
133
124
|
|
134
|
-
|
135
|
-
|
136
|
-
|
125
|
+
case meth
|
126
|
+
when :_, :p_, :N_, :pgettext, :s_
|
127
|
+
gettext_simple_call(exp)
|
128
|
+
when :n_
|
129
|
+
gettext_plural_call(exp)
|
130
|
+
end
|
137
131
|
|
132
|
+
until exp.empty? do
|
133
|
+
process(exp.shift)
|
134
|
+
end
|
138
135
|
|
136
|
+
s()
|
137
|
+
end
|
138
|
+
end
|
139
139
|
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.3.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: 2015-
|
11
|
+
date: 2015-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fast_gettext
|
@@ -100,14 +100,28 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 3.7.1
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 3.7.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sexp_processor
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: rspec
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|