retoo-ruby_gettext_extractor 0.2.1
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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lib/ruby_gettext_extractor.rb +142 -0
- data/ruby_gettext_extractor.gemspec +65 -0
- data/test/cases/N_.rb +66 -0
- data/test/cases/gettext.rb +96 -0
- data/test/cases/helper.rb +10 -0
- data/test/cases/new.rb +7 -0
- data/test/cases/ngettext.rb +74 -0
- data/test/cases/pgettext.rb +31 -0
- data/test/ruby_gettext_extractor_test.rb +87 -0
- data/test/test_helper.rb +9 -0
- metadata +86 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Reto Schüttel
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= ruby_gettext_extractor
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Reto Schüttel. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ruby_gettext_extractor"
|
8
|
+
gem.summary = %Q{Alternative gettext parser for ruby files}
|
9
|
+
gem.description = %Q{Alternative and more powerful gettext parser for ruby files. It covers some special cases which the normal parser can't handle}
|
10
|
+
gem.email = "reto (ät) schuettel (dot) ch"
|
11
|
+
gem.homepage = "http://github.com/retoo/ruby-gettext-extractor"
|
12
|
+
gem.authors = ["Reto Schüttel"]
|
13
|
+
gem.add_dependency 'ruby_parser', '>= 2.0.3'
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
if File.exist?('VERSION')
|
47
|
+
version = File.read('VERSION')
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "ruby_gettext_extractor #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
@@ -0,0 +1,142 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# parser/ruby.rb - look for gettext msg strings in ruby files
|
3
|
+
# Copyright (C) 2009 Reto Schüttel <reto (ät) schuettel (dot) ch>
|
4
|
+
# You may redistribute it and/or modify it under the same license terms as Ruby.
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'ruby_parser'
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'gettext/tools/rgettext'
|
11
|
+
rescue LoadError #version prior to 2.0
|
12
|
+
require 'gettext/rgettext'
|
13
|
+
end
|
14
|
+
|
15
|
+
module RubyGettextExtractor
|
16
|
+
extend self
|
17
|
+
|
18
|
+
def parse(file, targets = []) # :nodoc:
|
19
|
+
content = File.read(file)
|
20
|
+
parse_string(content, file, targets)
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_string(content, file, targets=[])
|
24
|
+
# file is just for information in error messages
|
25
|
+
parser = Extractor.new(file, targets)
|
26
|
+
results = parser.run(content)
|
27
|
+
end
|
28
|
+
|
29
|
+
def target?(file) # :nodoc:
|
30
|
+
return file =~ /\.rb$/
|
31
|
+
end
|
32
|
+
|
33
|
+
class Extractor < RubyParser
|
34
|
+
def initialize(filename, targets)
|
35
|
+
@filename = filename
|
36
|
+
@targets = Hash.new
|
37
|
+
@results = []
|
38
|
+
|
39
|
+
targets.each do |a|
|
40
|
+
k, v = a
|
41
|
+
# things go wrong if k already exists, but this
|
42
|
+
# should not happen (according to the gettext doc)
|
43
|
+
@targets[k] = a
|
44
|
+
@results << a
|
45
|
+
end
|
46
|
+
|
47
|
+
super()
|
48
|
+
end
|
49
|
+
|
50
|
+
def run(content)
|
51
|
+
self.parse(content)
|
52
|
+
return @results
|
53
|
+
end
|
54
|
+
|
55
|
+
def extract_string(node)
|
56
|
+
if node.first == :str
|
57
|
+
return node.last
|
58
|
+
elsif node.first == :call
|
59
|
+
type, recv, meth, args = node
|
60
|
+
|
61
|
+
# node has to be in form of "string"+("other_string")
|
62
|
+
return nil unless recv && meth == :+
|
63
|
+
|
64
|
+
# descent recurrsivly to determine the 'receiver' of the string concatination
|
65
|
+
# "foo" + "bar" + baz" is
|
66
|
+
# ("foo".+("bar")).+("baz")
|
67
|
+
first_part = extract_string(recv)
|
68
|
+
|
69
|
+
if args.first == :arglist && args.size == 2
|
70
|
+
second_part = extract_string(args.last)
|
71
|
+
|
72
|
+
return nil if second_part.nil?
|
73
|
+
|
74
|
+
return first_part + second_part
|
75
|
+
else
|
76
|
+
raise "uuh?"
|
77
|
+
end
|
78
|
+
else
|
79
|
+
return nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def extract_key(args, seperator)
|
84
|
+
key = nil
|
85
|
+
if args.size == 2
|
86
|
+
key = extract_string(args.value)
|
87
|
+
else
|
88
|
+
# this could be n_("aaa","aaa2",1)
|
89
|
+
# all strings arguemnts are extracted and joined with \004 or \000
|
90
|
+
|
91
|
+
arguments = args[1..(-1)]
|
92
|
+
|
93
|
+
res = []
|
94
|
+
arguments.each do |a|
|
95
|
+
str = extract_string(a)
|
96
|
+
# only add strings
|
97
|
+
res << str if str
|
98
|
+
end
|
99
|
+
|
100
|
+
return nil if res.empty?
|
101
|
+
key = res.join(seperator)
|
102
|
+
end
|
103
|
+
|
104
|
+
return nil unless key
|
105
|
+
|
106
|
+
key.gsub!("\n", '\n')
|
107
|
+
key.gsub!("\t", '\t')
|
108
|
+
key.gsub!("\0", '\0')
|
109
|
+
|
110
|
+
return key
|
111
|
+
end
|
112
|
+
|
113
|
+
def new_call recv, meth, args = nil
|
114
|
+
# we dont care if the method is called on a a object
|
115
|
+
if recv.nil?
|
116
|
+
if (meth == :_ || meth == :p_ || meth == :N_ || meth == :pgettext)
|
117
|
+
key = extract_key(args, "\004")
|
118
|
+
elsif meth == :n_
|
119
|
+
key = extract_key(args, "\000")
|
120
|
+
else
|
121
|
+
# skip
|
122
|
+
end
|
123
|
+
|
124
|
+
if key
|
125
|
+
res = @targets[key]
|
126
|
+
|
127
|
+
unless res
|
128
|
+
res = [key]
|
129
|
+
@results << res
|
130
|
+
@targets[key] = res
|
131
|
+
end
|
132
|
+
|
133
|
+
res << "#{@filename}:#{lexer.lineno}"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
super recv, meth, args
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
GetText::RGetText.add_parser(RubyGettextExtractor)
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ruby_gettext_extractor}
|
8
|
+
s.version = "0.2.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Reto Sch\303\274ttel"]
|
12
|
+
s.date = %q{2009-08-09}
|
13
|
+
s.description = %q{Alternative and more powerful gettext parser for ruby files. It covers some special cases which the normal parser can't handle}
|
14
|
+
s.email = %q{reto (ät) schuettel (dot) ch}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/ruby_gettext_extractor.rb",
|
27
|
+
"ruby_gettext_extractor.gemspec",
|
28
|
+
"test/cases/N_.rb",
|
29
|
+
"test/cases/gettext.rb",
|
30
|
+
"test/cases/helper.rb",
|
31
|
+
"test/cases/new.rb",
|
32
|
+
"test/cases/ngettext.rb",
|
33
|
+
"test/cases/pgettext.rb",
|
34
|
+
"test/ruby_gettext_extractor_test.rb",
|
35
|
+
"test/test_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/retoo/ruby-gettext-extractor}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.5}
|
41
|
+
s.summary = %q{Alternative gettext parser for ruby files}
|
42
|
+
s.test_files = [
|
43
|
+
"test/cases/gettext.rb",
|
44
|
+
"test/cases/helper.rb",
|
45
|
+
"test/cases/N_.rb",
|
46
|
+
"test/cases/new.rb",
|
47
|
+
"test/cases/ngettext.rb",
|
48
|
+
"test/cases/pgettext.rb",
|
49
|
+
"test/ruby_gettext_extractor_test.rb",
|
50
|
+
"test/test_helper.rb"
|
51
|
+
]
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
55
|
+
s.specification_version = 3
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_runtime_dependency(%q<ruby_parser>, [">= 2.0.3"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<ruby_parser>, [">= 2.0.3"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<ruby_parser>, [">= 2.0.3"])
|
64
|
+
end
|
65
|
+
end
|
data/test/cases/N_.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'gettext'
|
2
|
+
include GetText
|
3
|
+
|
4
|
+
class TestRubyParser_N
|
5
|
+
bindtextdomain("testN_rubyparser", :path => "locale")
|
6
|
+
|
7
|
+
def testN_1
|
8
|
+
N_("aaa")
|
9
|
+
end
|
10
|
+
|
11
|
+
def testN_2
|
12
|
+
N_("aaa\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
def testN_3
|
16
|
+
N_("bbb\nccc")
|
17
|
+
end
|
18
|
+
|
19
|
+
def testN_4
|
20
|
+
N_("bbb
|
21
|
+
ccc
|
22
|
+
ddd
|
23
|
+
")
|
24
|
+
end
|
25
|
+
|
26
|
+
def testN_5
|
27
|
+
N_("eee")
|
28
|
+
end
|
29
|
+
|
30
|
+
def testN_6
|
31
|
+
N_("eee") + "foo" + N_("fff")
|
32
|
+
end
|
33
|
+
|
34
|
+
def testN_7
|
35
|
+
N_("ggg"\
|
36
|
+
"hhh"\
|
37
|
+
"iii")
|
38
|
+
end
|
39
|
+
|
40
|
+
def testN_8
|
41
|
+
N_('a"b"c"')
|
42
|
+
end
|
43
|
+
|
44
|
+
def testN_9
|
45
|
+
N_("d\"e\"f\"")
|
46
|
+
end
|
47
|
+
|
48
|
+
def testN_10
|
49
|
+
N_("jjj") +
|
50
|
+
N_("kkk")
|
51
|
+
end
|
52
|
+
|
53
|
+
def testN_11
|
54
|
+
N_("lll" + "mmm")
|
55
|
+
end
|
56
|
+
|
57
|
+
def testN_12
|
58
|
+
puts N_(msg), "ppp" #Ignored
|
59
|
+
end
|
60
|
+
|
61
|
+
def testN_13
|
62
|
+
N_("nnn\n" +
|
63
|
+
"ooo")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'gettext'
|
2
|
+
include GetText
|
3
|
+
|
4
|
+
class TestRubyParser
|
5
|
+
bindtextdomain("rubyparser", :path => "locale")
|
6
|
+
|
7
|
+
def test_1
|
8
|
+
_("aaa")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_2
|
12
|
+
_("aaa\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_3
|
16
|
+
_("bbb\nccc")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_4
|
20
|
+
_("bbb
|
21
|
+
ccc
|
22
|
+
ddd
|
23
|
+
")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_5
|
27
|
+
_("eee")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_6
|
31
|
+
_("eee") + "foo" + _("fff")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_7
|
35
|
+
_("ggg"\
|
36
|
+
"hhh"\
|
37
|
+
"iii")
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_8
|
41
|
+
_('a"b"c"')
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_9
|
45
|
+
_("d\"e\"f\"")
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_10
|
49
|
+
_("jjj") +
|
50
|
+
_("kkk")
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_11
|
54
|
+
_("lll" + "mmm")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_12
|
58
|
+
puts _(msg), "ppp" #Ignored
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_13
|
62
|
+
_("nnn\n" +
|
63
|
+
"ooo")
|
64
|
+
end
|
65
|
+
def test_14
|
66
|
+
_("\#")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_15
|
70
|
+
_('#')
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_16
|
74
|
+
_('\taaa')
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_17
|
78
|
+
ret = _(<<EOF
|
79
|
+
Here document1
|
80
|
+
Here document2
|
81
|
+
EOF
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_18
|
86
|
+
"<div>#{_('in_quote')}</div>"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
module ActionController
|
91
|
+
class Base
|
92
|
+
end
|
93
|
+
end
|
94
|
+
class ApplicationController < ActionController::Base
|
95
|
+
"#{Time.now.strftime('%m/%d')}"
|
96
|
+
end
|
data/test/cases/new.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'gettext'
|
2
|
+
include GetText
|
3
|
+
|
4
|
+
class TestRubyParser_n
|
5
|
+
bindtextdomain("rubyparser", :path => "locale")
|
6
|
+
|
7
|
+
def test_1
|
8
|
+
n_("aaa","aaa2",1)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_2
|
12
|
+
n_("bbb\n", "ccc2\nccc2", 1)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_3_1
|
16
|
+
n_("ddd\nddd",
|
17
|
+
"ddd2\nddd2",
|
18
|
+
1)
|
19
|
+
end
|
20
|
+
def test_3_2
|
21
|
+
n_("eee\neee\n" ,
|
22
|
+
"eee2\neee2\n" ,
|
23
|
+
1)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_4
|
27
|
+
n_("ddd
|
28
|
+
eee
|
29
|
+
", "ddd
|
30
|
+
eee2", 1)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_5_1
|
34
|
+
n_("fff", "fff2", 1)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_5_2
|
38
|
+
n_("fff", "fff2", 1) + "foo" + n_("ggg", "ggg2", 1)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_6
|
42
|
+
n_("ggg"\
|
43
|
+
"hhh"\
|
44
|
+
"iii",
|
45
|
+
"jjj"\
|
46
|
+
"kkk"\
|
47
|
+
"lll", 1)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_7
|
51
|
+
n_('a"b"c"', 'a"b"c"2', 1)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_8
|
55
|
+
n_("d\"e\"f\"", "d\"e\"f\"2", 1)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_9
|
59
|
+
n_("mmm" + "mmm","mmm2" + "mmm2",1) +
|
60
|
+
n_("nnn" ,"nnn2" ,1)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_10
|
64
|
+
_("ooo")
|
65
|
+
n_("ooo", "ppp", 1)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_11
|
69
|
+
n_("qqq", "rrr", 1)
|
70
|
+
n_("qqq", "sss", 1) # This is merged to "qqq\000rrr".
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'gettext'
|
2
|
+
|
3
|
+
class TestPGetText
|
4
|
+
include GetText
|
5
|
+
bindtextdomain("pgettext", :path => "locale")
|
6
|
+
|
7
|
+
def test_1
|
8
|
+
p_("AAA", "BBB")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_2
|
12
|
+
pgettext("AAA", "BBB")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_3
|
16
|
+
pgettext("AAA|BBB", "CCC")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_4
|
20
|
+
p_("AAA", "CCC") #not found
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_5
|
24
|
+
p_("CCC", "BBB")
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_6 # not pgettext.
|
28
|
+
_("BBB")
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# most of these tests are taken from the GetText Distribution. There are comments where
|
4
|
+
# changes had to be made.
|
5
|
+
|
6
|
+
class TestGetTextParser < Test::Unit::TestCase
|
7
|
+
def test_ruby
|
8
|
+
ary = RubyGettextExtractor.parse('test/cases/gettext.rb')
|
9
|
+
|
10
|
+
assert_equal(['aaa', 'test/cases/gettext.rb:8'], ary[0])
|
11
|
+
assert_equal(['aaa\n', 'test/cases/gettext.rb:12'], ary[1])
|
12
|
+
assert_equal(['bbb\nccc', 'test/cases/gettext.rb:16'], ary[2])
|
13
|
+
assert_equal(['bbb\nccc\nddd\n', 'test/cases/gettext.rb:20'], ary[3])
|
14
|
+
assert_equal(['eee', 'test/cases/gettext.rb:27', 'test/cases/gettext.rb:31'], ary[4])
|
15
|
+
assert_equal(['fff', 'test/cases/gettext.rb:31'], ary[5])
|
16
|
+
# position difference, 37 instead of 35 (not relevant in daily use)
|
17
|
+
assert_equal(['ggghhhiii', 'test/cases/gettext.rb:37'], ary[6])
|
18
|
+
assert_equal(['a"b"c"', 'test/cases/gettext.rb:41'], ary[7])
|
19
|
+
assert_equal(['d"e"f"', 'test/cases/gettext.rb:45'], ary[8])
|
20
|
+
assert_equal(['jjj', 'test/cases/gettext.rb:49'], ary[9])
|
21
|
+
assert_equal(['kkk', 'test/cases/gettext.rb:50'], ary[10])
|
22
|
+
assert_equal(['lllmmm', 'test/cases/gettext.rb:54'], ary[11])
|
23
|
+
# position difference caused by multiline statement, 63 instead of 62
|
24
|
+
assert_equal(['nnn\nooo', 'test/cases/gettext.rb:63'], ary[12])
|
25
|
+
assert_equal(["\#", 'test/cases/gettext.rb:66', 'test/cases/gettext.rb:70'], ary[13])
|
26
|
+
assert_equal(["\\taaa", 'test/cases/gettext.rb:74'], ary[14])
|
27
|
+
# position difference caused by here doc, 84 instead of 78 (bit annyoing
|
28
|
+
assert_equal(["Here document1\\nHere document2\\n", 'test/cases/gettext.rb:84'], ary[15])
|
29
|
+
assert_equal(["in_quote", 'test/cases/gettext.rb:88'], ary[16])
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_ruby_N
|
33
|
+
ary = RubyGettextExtractor.parse('test/cases/N_.rb')
|
34
|
+
|
35
|
+
assert_equal(['aaa', 'test/cases/N_.rb:8'], ary[0])
|
36
|
+
assert_equal(['aaa\n', 'test/cases/N_.rb:12'], ary[1])
|
37
|
+
assert_equal(['bbb\nccc', 'test/cases/N_.rb:16'], ary[2])
|
38
|
+
assert_equal(['bbb\nccc\nddd\n', 'test/cases/N_.rb:20'], ary[3])
|
39
|
+
assert_equal(['eee', 'test/cases/N_.rb:27', 'test/cases/N_.rb:31'], ary[4])
|
40
|
+
assert_equal(['fff', 'test/cases/N_.rb:31'], ary[5])
|
41
|
+
# position difference caused by multilin statement, 37 instead of 35
|
42
|
+
assert_equal(['ggghhhiii', 'test/cases/N_.rb:37'], ary[6])
|
43
|
+
assert_equal(['a"b"c"', 'test/cases/N_.rb:41'], ary[7])
|
44
|
+
assert_equal(['d"e"f"', 'test/cases/N_.rb:45'], ary[8])
|
45
|
+
assert_equal(['jjj', 'test/cases/N_.rb:49'], ary[9])
|
46
|
+
assert_equal(['kkk', 'test/cases/N_.rb:50'], ary[10])
|
47
|
+
assert_equal(['lllmmm', 'test/cases/N_.rb:54'], ary[11])
|
48
|
+
# position difference caused by multiline statement, 63 instead of 62
|
49
|
+
assert_equal(['nnn\nooo', 'test/cases/N_.rb:63'], ary[12])
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_ruby_n
|
53
|
+
ary = RubyGettextExtractor.parse('test/cases/ngettext.rb')
|
54
|
+
assert_equal(["aaa\000aaa2", 'test/cases/ngettext.rb:8'], ary[0])
|
55
|
+
assert_equal(["bbb\\n\000ccc2\\nccc2", 'test/cases/ngettext.rb:12'], ary[1])
|
56
|
+
# position difference caused by multiline statement, 18 instead of 16
|
57
|
+
assert_equal(["ddd\\nddd\000ddd2\\nddd2", 'test/cases/ngettext.rb:18'], ary[2])
|
58
|
+
# position difference caused by multiline statement, 23 instead of 21
|
59
|
+
assert_equal(["eee\\neee\\n\000eee2\\neee2\\n", 'test/cases/ngettext.rb:23'], ary[3])
|
60
|
+
assert_equal(["ddd\\neee\\n\000ddd\\neee2", 'test/cases/ngettext.rb:27'], ary[4])
|
61
|
+
assert_equal(["fff\000fff2", 'test/cases/ngettext.rb:34', 'test/cases/ngettext.rb:38'], ary[5])
|
62
|
+
assert_equal(["ggg\000ggg2", 'test/cases/ngettext.rb:38'], ary[6])
|
63
|
+
# position difference caused by multiline statement, 47 instead of 42
|
64
|
+
assert_equal(["ggghhhiii\000jjjkkklll", 'test/cases/ngettext.rb:47'], ary[7])
|
65
|
+
assert_equal(["a\"b\"c\"\000a\"b\"c\"2", 'test/cases/ngettext.rb:51'], ary[8])
|
66
|
+
assert_equal(["mmmmmm\000mmm2mmm2", 'test/cases/ngettext.rb:59'], ary[10])
|
67
|
+
assert_equal(["nnn\000nnn2", 'test/cases/ngettext.rb:60'], ary[11])
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_ruby_p
|
71
|
+
ary = RubyGettextExtractor.parse('test/cases/pgettext.rb')
|
72
|
+
assert_equal(["AAA\004BBB", "test/cases/pgettext.rb:8", "test/cases/pgettext.rb:12"], ary[0])
|
73
|
+
assert_equal(["AAA|BBB\004CCC", "test/cases/pgettext.rb:16"], ary[1])
|
74
|
+
assert_equal(["AAA\004CCC", "test/cases/pgettext.rb:20"], ary[2])
|
75
|
+
assert_equal(["CCC\004BBB", "test/cases/pgettext.rb:24"], ary[3])
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_new_cases
|
79
|
+
ary = RubyGettextExtractor.parse('test/cases/new.rb')
|
80
|
+
assert_equal(["baz", "test/cases/new.rb:5"], ary[0])
|
81
|
+
assert_equal(["foobarbaz", "test/cases/new.rb:5"], ary[1])
|
82
|
+
assert_equal(["world", "test/cases/new.rb:6"], ary[2])
|
83
|
+
assert_equal(["foo", "test/cases/new.rb:6"], ary[3])
|
84
|
+
assert_equal(["ruby_is_wicked", "test/cases/new.rb:6"], ary[4])
|
85
|
+
assert_equal(["foocliclaclublibuzbiz", "test/cases/new.rb:7"], ary[5])
|
86
|
+
end
|
87
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: retoo-ruby_gettext_extractor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Reto Sch\xC3\xBCttel"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-09 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ruby_parser
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.0.3
|
24
|
+
version:
|
25
|
+
description: Alternative and more powerful gettext parser for ruby files. It covers some special cases which the normal parser can't handle
|
26
|
+
email: "reto (\xC3\xA4t) schuettel (dot) ch"
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- lib/ruby_gettext_extractor.rb
|
42
|
+
- ruby_gettext_extractor.gemspec
|
43
|
+
- test/cases/N_.rb
|
44
|
+
- test/cases/gettext.rb
|
45
|
+
- test/cases/helper.rb
|
46
|
+
- test/cases/new.rb
|
47
|
+
- test/cases/ngettext.rb
|
48
|
+
- test/cases/pgettext.rb
|
49
|
+
- test/ruby_gettext_extractor_test.rb
|
50
|
+
- test/test_helper.rb
|
51
|
+
has_rdoc: false
|
52
|
+
homepage: http://github.com/retoo/ruby-gettext-extractor
|
53
|
+
licenses:
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --charset=UTF-8
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Alternative gettext parser for ruby files
|
78
|
+
test_files:
|
79
|
+
- test/cases/gettext.rb
|
80
|
+
- test/cases/helper.rb
|
81
|
+
- test/cases/N_.rb
|
82
|
+
- test/cases/new.rb
|
83
|
+
- test/cases/ngettext.rb
|
84
|
+
- test/cases/pgettext.rb
|
85
|
+
- test/ruby_gettext_extractor_test.rb
|
86
|
+
- test/test_helper.rb
|