i15r 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/i15r.gemspec +45 -47
- data/lib/i15r/base.rb +2 -2
- data/lib/i15r/pattern_matchers/haml/tag_content_matcher.rb +5 -5
- data/spec/erb/tag_content_matcher_spec.rb +1 -0
- data/spec/haml/tag_content_matcher_spec.rb +22 -4
- data/spec/pattern_matcher_spec.rb +2 -1
- data/spec/support/new_user.html.haml +1 -1
- data/todos.markdown +9 -2
- metadata +19 -8
- data/.gitignore +0 -2
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/i15r.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{i15r}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Balint Erdi"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-28}
|
13
13
|
s.default_executable = %q{i15r}
|
14
14
|
s.description = %q{ The internationalizer. Replaces plain text strings in your views and replaces them with I18n message strings so you only have to provide the translations.
|
15
15
|
}
|
@@ -19,62 +19,60 @@ Gem::Specification.new do |s|
|
|
19
19
|
"README.markdown"
|
20
20
|
]
|
21
21
|
s.files = [
|
22
|
-
"
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
"todos.markdown"
|
22
|
+
"CHANGELOG",
|
23
|
+
"MIT-LICENSE",
|
24
|
+
"Manifest",
|
25
|
+
"README.markdown",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/i15r",
|
29
|
+
"i15r.gemspec",
|
30
|
+
"init.rb",
|
31
|
+
"lib/i15r.rb",
|
32
|
+
"lib/i15r/base.rb",
|
33
|
+
"lib/i15r/pattern_matcher.rb",
|
34
|
+
"lib/i15r/pattern_matchers/base.rb",
|
35
|
+
"lib/i15r/pattern_matchers/erb.rb",
|
36
|
+
"lib/i15r/pattern_matchers/erb/rails_helper_matcher.rb",
|
37
|
+
"lib/i15r/pattern_matchers/erb/tag_attribute_matcher.rb",
|
38
|
+
"lib/i15r/pattern_matchers/erb/tag_content_matcher.rb",
|
39
|
+
"lib/i15r/pattern_matchers/haml.rb",
|
40
|
+
"lib/i15r/pattern_matchers/haml/rails_helper_matcher.rb",
|
41
|
+
"lib/i15r/pattern_matchers/haml/tag_content_matcher.rb",
|
42
|
+
"spec/erb/rails_helper_matcher_spec.rb",
|
43
|
+
"spec/erb/tag_attribute_matcher_spec.rb",
|
44
|
+
"spec/erb/tag_content_matcher_spec.rb",
|
45
|
+
"spec/haml/rails_helper_matcher_spec.rb",
|
46
|
+
"spec/haml/tag_content_matcher_spec.rb",
|
47
|
+
"spec/i15r_spec.rb",
|
48
|
+
"spec/pattern_matcher_spec.rb",
|
49
|
+
"spec/spec.opts",
|
50
|
+
"spec/spec_helper.rb",
|
51
|
+
"spec/support/new_flight.html.erb",
|
52
|
+
"spec/support/new_user.html.haml",
|
53
|
+
"tasks/i15r.rake",
|
54
|
+
"todos.markdown"
|
56
55
|
]
|
57
56
|
s.homepage = %q{http://github.com/balinterdi/i15r}
|
58
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
59
57
|
s.require_paths = ["lib"]
|
60
|
-
s.rubygems_version = %q{1.3.
|
58
|
+
s.rubygems_version = %q{1.3.7}
|
61
59
|
s.summary = %q{The internationalizer. Makes your Ruby app international}
|
62
60
|
s.test_files = [
|
63
61
|
"spec/erb/rails_helper_matcher_spec.rb",
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
"spec/erb/tag_attribute_matcher_spec.rb",
|
63
|
+
"spec/erb/tag_content_matcher_spec.rb",
|
64
|
+
"spec/haml/rails_helper_matcher_spec.rb",
|
65
|
+
"spec/haml/tag_content_matcher_spec.rb",
|
66
|
+
"spec/i15r_spec.rb",
|
67
|
+
"spec/pattern_matcher_spec.rb",
|
68
|
+
"spec/spec_helper.rb"
|
71
69
|
]
|
72
70
|
|
73
71
|
if s.respond_to? :specification_version then
|
74
72
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
75
73
|
s.specification_version = 3
|
76
74
|
|
77
|
-
if Gem::Version.new(Gem::
|
75
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
78
76
|
else
|
79
77
|
end
|
80
78
|
else
|
data/lib/i15r/base.rb
CHANGED
@@ -10,7 +10,7 @@ module I15R
|
|
10
10
|
def self.get_i18n_message_string(text, prefix)
|
11
11
|
#TODO: downcase does not work properly for accented chars, like 'Ú'
|
12
12
|
#TODO: [:punct:] would be nice but it includes _ which we don't want to remove
|
13
|
-
key = text.strip.downcase.gsub(/[\s]/, '_').gsub(/[!?.,:"';]/, '')
|
13
|
+
key = text.strip.downcase.gsub(/[\s]/, '_').gsub(/[!?.,:"';()]/, '')
|
14
14
|
indent = ""
|
15
15
|
(0..prefix.split(".").size).each { |i| indent = " " + indent }
|
16
16
|
# silenced_if_testing do
|
@@ -144,4 +144,4 @@ module I15R
|
|
144
144
|
$testing
|
145
145
|
end
|
146
146
|
end
|
147
|
-
end
|
147
|
+
end
|
@@ -2,11 +2,11 @@ module I15R
|
|
2
2
|
module PatternMatchers
|
3
3
|
module Haml
|
4
4
|
class TagContentMatcher < Base
|
5
|
-
|
5
|
+
|
6
6
|
def self.run(text, prefix)
|
7
7
|
super(text, prefix, :haml)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def self.match_haml_implicit_div_tag_content
|
11
11
|
#TODO: really ugly. so many negative groups
|
12
12
|
# to prevent #new-user-link= link_to '...', new_user_path to match
|
@@ -22,11 +22,11 @@ module I15R
|
|
22
22
|
register_matcher :match_haml_implicit_div_tag_content
|
23
23
|
|
24
24
|
def self.match_haml_explicit_tag_content
|
25
|
-
patt = /^(.*%[\w+
|
25
|
+
patt = /^(.*%[\w]+)\s+(.*)$/
|
26
26
|
matches(:haml) do |text, prefix|
|
27
27
|
if m = patt.match(text)
|
28
28
|
i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
|
29
|
-
i18ned_row = %(#{m[1]}I18n.t("#{i18n_string}"))
|
29
|
+
i18ned_row = %(#{m[1]}= I18n.t("#{i18n_string}"))
|
30
30
|
[m[0], i18ned_row]
|
31
31
|
end
|
32
32
|
end
|
@@ -34,7 +34,7 @@ module I15R
|
|
34
34
|
register_matcher :match_haml_explicit_tag_content
|
35
35
|
|
36
36
|
def self.match_haml_tag_content_just_text_on_line
|
37
|
-
patt = /^(\s*)([
|
37
|
+
patt = /^(\s*)([^.#!%\s][[:alpha:][:upper:]\s\d\!\-\.\?]+)$/
|
38
38
|
matches(:haml) do |text, prefix|
|
39
39
|
if m = patt.match(text)
|
40
40
|
i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
|
@@ -35,6 +35,7 @@ describe I15R::PatternMatchers::Erb::TagContentMatcher do
|
|
35
35
|
I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
|
36
36
|
end
|
37
37
|
|
38
|
+
#1.8fail
|
38
39
|
it "should replace a word with non-ascii characters" do
|
39
40
|
plain = %(<label for="when">Mañana</label>)
|
40
41
|
i18ned = %(<label for="when"><%= I18n.t("users.new.mañana") %></label>)
|
@@ -11,7 +11,7 @@ describe I15R::PatternMatchers::Haml::TagContentMatcher do
|
|
11
11
|
|
12
12
|
it "should replace a tag's content where the tag is an explicit one" do
|
13
13
|
plain = %(%p Please check your inbox and click on the activation link.)
|
14
|
-
i18ned = %(%p I18n.t("users.show.please_check_your_inbox_and_click_on_the_activation_link"))
|
14
|
+
i18ned = %(%p= I18n.t("users.show.please_check_your_inbox_and_click_on_the_activation_link"))
|
15
15
|
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.show").should == i18ned
|
16
16
|
end
|
17
17
|
|
@@ -25,7 +25,24 @@ describe I15R::PatternMatchers::Haml::TagContentMatcher do
|
|
25
25
|
plain = %( .field)
|
26
26
|
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == plain
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
|
+
it "should not replace a line with just an hmtl tag and no text" do
|
30
|
+
plain = "%p"
|
31
|
+
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == plain
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not include the %tag in the generated message string" do
|
35
|
+
plain = "%h2 Resend unlock instructions"
|
36
|
+
i18ned = %(%h2= I18n.t("users.new.resend_unlock_instructions"))
|
37
|
+
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == i18ned
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should suppress ( and ) in the generated I18n message string" do
|
41
|
+
plain = "%i (we need your current password to confirm your changes)"
|
42
|
+
i18ned = %(%i= I18n.t("users.new.we_need_your_current_password_to_confirm_your_changes"))
|
43
|
+
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == i18ned
|
44
|
+
end
|
45
|
+
|
29
46
|
describe "when text has non-english characters" do
|
30
47
|
it "should replace a tag's content where the tag is an implicit div" do
|
31
48
|
plain = %(#form_head Türkçe)
|
@@ -35,14 +52,15 @@ describe I15R::PatternMatchers::Haml::TagContentMatcher do
|
|
35
52
|
|
36
53
|
it "should replace a tag's content where the tag is an explicit one" do
|
37
54
|
plain = %(%p Egy, kettő, három, négy, öt.)
|
38
|
-
i18ned = %(%p I18n.t("users.show.egy_kettő_három_négy_öt"))
|
55
|
+
i18ned = %(%p= I18n.t("users.show.egy_kettő_három_négy_öt"))
|
39
56
|
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.show").should == i18ned
|
40
57
|
end
|
41
58
|
|
59
|
+
#1.8fail
|
42
60
|
it "should replace a tag's content which is simple text all by itself on a line" do
|
43
61
|
plain = %(Türkçe)
|
44
62
|
i18ned = %(= I18n.t("users.new.türkçe"))
|
45
63
|
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == i18ned
|
46
64
|
end
|
47
65
|
end
|
48
|
-
end
|
66
|
+
end
|
@@ -17,10 +17,11 @@ describe I15R::PatternMatchers::Base do
|
|
17
17
|
I15R::PatternMatchers::Base.run(plain, "users.new", :erb).should == i18ned
|
18
18
|
end
|
19
19
|
|
20
|
+
#1.8fail
|
20
21
|
it "should properly replace a line with two matches that have non-ascii chars" do
|
21
22
|
plain = %(C'est ça: <a title="site root" href="/"><img src="site_logo.png" /></a>)
|
22
23
|
i18ned = %(<%= I18n.t("users.new.cest_ça") %>: <a title="<%= I18n.t("users.new.site_root") %>" href="/"><img src="site_logo.png" /></a>)
|
23
24
|
I15R::PatternMatchers::Base.run(plain, "users.new", :erb).should == i18ned
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
end
|
data/todos.markdown
CHANGED
@@ -30,15 +30,22 @@ This is easy to fix, the whitespace has to be readded just like the punctuation
|
|
30
30
|
|
31
31
|
* DONE dry-run option: only show the diffs but do not actually overwrite the files
|
32
32
|
|
33
|
-
### 0
|
33
|
+
### 0.3.1
|
34
34
|
|
35
35
|
* haml matchers
|
36
36
|
* DONE nothing is replaced in haml files although specs pass. Probably something related to receiving the whole file content as one blob of text and not as lines. It works with erb, though.
|
37
37
|
* sort out the ugly hierarchy, make it consistent (e.g add "erb" directory as there is a haml one), do not require files in lib by full path (e.g instead of require 'i15r/pattern\_matchers\_/haml/rails\_helper_matcher' => require 'haml/rails\_helper_matcher'), etc.
|
38
|
+
|
39
|
+
### 0.4.0
|
40
|
+
|
41
|
+
* DONE handle non-ascii characters properly (UTF-8 support) when replacing them. Mañana should become I18n.t("prefix.manana"), for instance. That is, regular expressions should be utf-8 aware.
|
42
|
+
|
43
|
+
### 0.?
|
44
|
+
|
38
45
|
* make a PatternMatcher::Erb (and Haml) class that implements the run method and make the classes that now exist modules that these classes include/extend
|
39
46
|
* make the haml matchers nicer (was thrown together very hastily for a client project)
|
40
47
|
* make prefix not replace the inferred message string prefix, but really act as a prefix. (e.g if anetcom is given as a prefix, and the inferred message string is 'users.new' it should not be 'anetcom.name', but 'anetcom.users.new.name')
|
41
|
-
* handle non-ascii characters properly (UTF-8 support) when replacing them. Mañana should become I18n.t("prefix.manana"), for instance. That is, regular expressions should be utf-8 aware.
|
42
48
|
* write the necessary i18n strings back into the yaml file
|
43
49
|
* make interactive mode possible. the user is asked about each message to be replaced. he can choose to replace it, skip it or even edit it. Ideally the message would be shown in its context.
|
50
|
+
* make specs pass with ruby 1.8, see specs tagged with #1.8fail, probably the "weird characters" in the specs should be replaced by their unicode codes (e.g \u1234)
|
44
51
|
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i15r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 11
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 2
|
10
|
+
version: 0.4.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Balint Erdi
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-11-28 00:00:00 +01:00
|
13
19
|
default_executable: i15r
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -22,7 +28,6 @@ extensions: []
|
|
22
28
|
extra_rdoc_files:
|
23
29
|
- README.markdown
|
24
30
|
files:
|
25
|
-
- .gitignore
|
26
31
|
- CHANGELOG
|
27
32
|
- MIT-LICENSE
|
28
33
|
- Manifest
|
@@ -61,26 +66,32 @@ homepage: http://github.com/balinterdi/i15r
|
|
61
66
|
licenses: []
|
62
67
|
|
63
68
|
post_install_message:
|
64
|
-
rdoc_options:
|
65
|
-
|
69
|
+
rdoc_options: []
|
70
|
+
|
66
71
|
require_paths:
|
67
72
|
- lib
|
68
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
69
75
|
requirements:
|
70
76
|
- - ">="
|
71
77
|
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
72
81
|
version: "0"
|
73
|
-
version:
|
74
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
75
84
|
requirements:
|
76
85
|
- - ">="
|
77
86
|
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
78
90
|
version: "0"
|
79
|
-
version:
|
80
91
|
requirements: []
|
81
92
|
|
82
93
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.3.
|
94
|
+
rubygems_version: 1.3.7
|
84
95
|
signing_key:
|
85
96
|
specification_version: 3
|
86
97
|
summary: The internationalizer. Makes your Ruby app international
|
data/.gitignore
DELETED