i15r 0.3.1 → 0.4.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
data/bin/i15r CHANGED
File without changes
data/i15r.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{i15r}
8
- s.version = "0.3.1"
8
+ s.version = "0.4.0"
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{2009-12-14}
12
+ s.date = %q{2010-01-08}
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
  }
data/lib/i15r/base.rb CHANGED
@@ -8,7 +8,9 @@ module I15R
8
8
  attr_reader :options
9
9
 
10
10
  def self.get_i18n_message_string(text, prefix)
11
- key = text.strip.downcase.gsub(/\s/, '_').gsub(/[\W]/, '')
11
+ #TODO: downcase does not work properly for accented chars, like 'Ú'
12
+ #TODO: [:punct:] would be nice but it includes _ which we don't want to remove
13
+ key = text.strip.downcase.gsub(/[\s]/, '_').gsub(/[!?.,:"';]/, '')
12
14
  indent = ""
13
15
  (0..prefix.split(".").size).each { |i| indent = " " + indent }
14
16
  # silenced_if_testing do
@@ -10,7 +10,7 @@ module I15R
10
10
  end
11
11
 
12
12
  def self.match_tag_content_on_one_line
13
- patt = /^(.*)>(\s*)(\w[\s\w:'"!?\.,]+)\s*<\/(.*)$/
13
+ patt = /^(.*)>(\s*)([[:alnum:][:upper:]][\s[:alnum:][:upper:][:punct:]]+)\s*<\/(.*)$/i
14
14
  matches(:erb) do |text, prefix|
15
15
  if m = patt.match(text)
16
16
  i18n_string = I15R::Base.get_i18n_message_string(m[3], prefix)
@@ -23,7 +23,7 @@ module I15R
23
23
  register_matcher :match_tag_content_on_one_line
24
24
 
25
25
  def self.match_tag_content_multiline
26
- patt = /^(\s*)(\w[\w\s,]*)(.*)$/
26
+ patt = /^(\s*)([[:alnum:][:upper:]][[:alnum:][:upper:][:space:],']*)(.*)$/i
27
27
  matches(:erb) do |text, prefix|
28
28
  if m = patt.match(text)
29
29
  i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
@@ -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*)([^.#\s][\w\s\d\!\-\.\?]+)$/
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)
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'i15r/pattern_matcher'
2
4
  require "spec"
3
5
 
@@ -21,7 +23,7 @@ describe I15R::PatternMatchers::Erb::RailsHelperMatcher do
21
23
  i18ned = %(<%= f.label :name, I18n.t("users.new.name") %>)
22
24
  I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
23
25
  end
24
-
26
+
25
27
  it "should replace the label text of a label_tag helper" do
26
28
  plain = %(<%= label_tag :name, "Name" %>)
27
29
  i18ned = %(<%= label_tag :name, I18n.t("users.new.name") %>)
@@ -39,5 +41,43 @@ describe I15R::PatternMatchers::Erb::RailsHelperMatcher do
39
41
  i18ned = %(<%= submit_tag I18n.t("users.new.create_user") %>)
40
42
  I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
41
43
  end
44
+
45
+ describe "when text has non-english characters" do
46
+ it "should replace a title in a link_to helper" do
47
+ plain = %(<p class="highlighted"><%= link_to 'Új felhasználó', new_user_path %>?</p>)
48
+ i18ned = %(<p class="highlighted"><%= link_to I18n.t("users.index.Új_felhasználó"), new_user_path %>?</p>)
49
+ I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.index").should == i18ned
50
+ end
51
+
52
+ it "should replace a title in a link_to helper with html attributes" do
53
+ plain = %(<p><%= link_to "Új felhasználó létrehozása", new_user_path, { :class => "add" } -%></p>)
54
+ i18ned = %(<p><%= link_to I18n.t("users.index.Új_felhasználó_létrehozása"), new_user_path, { :class => "add" } -%></p>)
55
+ I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.index").should == i18ned
56
+ end
57
+
58
+ it "should replace the label text in a label helper" do
59
+ plain = %(<%= f.label :name, "Név" %>)
60
+ i18ned = %(<%= f.label :name, I18n.t("users.new.név") %>)
61
+ I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
62
+ end
63
+
64
+ it "should replace the label text that has non-english chars of a label_tag helper" do
65
+ plain = %(<%= label_tag :name, "Név" %>)
66
+ i18ned = %(<%= label_tag :name, I18n.t("users.new.név") %>)
67
+ I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
68
+ end
69
+
70
+ it "should replace the title of a submit helper in a form builder" do
71
+ plain = %(<%= f.submit "Új felhasználó" %>)
72
+ i18ned = %(<%= f.submit I18n.t("users.new.Új_felhasználó") %>)
73
+ I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
74
+ end
75
+
76
+ it "should replace the title of a submit_tag helper" do
77
+ plain = %(<%= submit_tag "Új felhasználó" %>)
78
+ i18ned = %(<%= submit_tag I18n.t("users.new.Új_felhasználó") %>)
79
+ I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
80
+ end
81
+ end
42
82
 
43
83
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'i15r/pattern_matcher'
2
4
  require "spec"
3
5
 
@@ -10,4 +12,10 @@ describe I15R::PatternMatchers::Erb::TagAttributeMatcher do
10
12
  I15R::PatternMatchers::Erb::TagAttributeMatcher.run(plain, "users.new").should == i18ned
11
13
  end
12
14
 
15
+ it "should replace a link's title that has non-english characters" do
16
+ plain = %(<a title="raçine du site" href="/"><img src="site_logo.png" /></a>)
17
+ i18ned = %(<a title="<%= I18n.t("users.new.raçine_du_site") %>" href="/"><img src="site_logo.png" /></a>)
18
+ I15R::PatternMatchers::Erb::TagAttributeMatcher.run(plain, "users.new").should == i18ned
19
+ end
20
+
13
21
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'i15r/pattern_matcher'
2
4
  require "spec"
3
5
 
@@ -32,5 +34,11 @@ describe I15R::PatternMatchers::Erb::TagContentMatcher do
32
34
  i18ned = %(<label for="user-name"> <%= I18n.t("users.new.name") %> </label>)
33
35
  I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
34
36
  end
37
+
38
+ it "should replace a word with non-ascii characters" do
39
+ plain = %(<label for="when">Mañana</label>)
40
+ i18ned = %(<label for="when"><%= I18n.t("users.new.mañana") %></label>)
41
+ I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
42
+ end
35
43
 
36
44
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
4
 
3
5
  describe I15R::PatternMatchers::Haml::RailsHelperMatcher do
@@ -43,4 +45,48 @@ describe I15R::PatternMatchers::Haml::RailsHelperMatcher do
43
45
  I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
44
46
  end
45
47
 
48
+ describe "when text has non-english characters" do
49
+ it "should replace a title in a link_to helper in a %tag row" do
50
+ plain = %(%p= link_to 'Új felhasználó', new_user_path)
51
+ i18ned = %(%p= link_to I18n.t("users.index.Új_felhasználó"), new_user_path)
52
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.index").should == i18ned
53
+ end
54
+
55
+ it "should replace a title in a link_to helper in an implicit div row" do
56
+ plain = %(#new_user_link= link_to 'Új felhasználó', new_user_path)
57
+ i18ned = %(#new_user_link= link_to I18n.t("users.index.Új_felhasználó"), new_user_path)
58
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.index").should == i18ned
59
+ end
60
+
61
+ it "should replace the label text in a label helper" do
62
+ plain = %(= f.label :password, "Contraseña")
63
+ i18ned = %(= f.label :password, I18n.t("users.new.contraseña"))
64
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i18ned
65
+ end
66
+
67
+ it "should preserve whitespace when replacing a label helper" do
68
+ plain = %( = f.label :password, "Contraseña")
69
+ i18ned = %( = f.label :password, I18n.t("users.new.contraseña"))
70
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i18ned
71
+ end
72
+
73
+ it "should replace a title in a link_to helper that uses parens and other text in the same row in an implicit div row" do
74
+ plain = %q(= "Elfőgadom a #{link_to('feltételeket', terms_and_conditions_path)}")
75
+ i15d = %q(= I18n.t("users.new.elfőgadom_a", :link => link_to(I18n.t("users.new.feltételeket"), terms_and_conditions_path)))
76
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
77
+ end
78
+
79
+ it "should replace a title in a link_to helper that does not use parens and other text in the same row in an implicit div row" do
80
+ plain = %q(= "Elfőgadom a #{link_to 'feltételeket', terms_and_conditions_path}")
81
+ i15d = %q(= I18n.t("users.new.elfőgadom_a", :link => link_to(I18n.t("users.new.feltételeket"), terms_and_conditions_path)))
82
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
83
+ end
84
+
85
+ it "should replace a title in a link_to helper that uses the haml == operator" do
86
+ plain = %q(== Elfőgadom a #{link_to('feltételeket', terms_and_conditions_path)})
87
+ i15d = %q(== I18n.t("users.new.elfőgadom_a", :link => link_to(I18n.t("users.new.feltételeket"), terms_and_conditions_path)))
88
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
89
+ end
90
+ end
91
+
46
92
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
4
 
3
5
  describe I15R::PatternMatchers::Haml::TagContentMatcher do
@@ -23,4 +25,24 @@ describe I15R::PatternMatchers::Haml::TagContentMatcher do
23
25
  plain = %( .field)
24
26
  I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == plain
25
27
  end
28
+
29
+ describe "when text has non-english characters" do
30
+ it "should replace a tag's content where the tag is an implicit div" do
31
+ plain = %(#form_head Türkçe)
32
+ i18ned = %(#form_head= I18n.t("users.edit.türkçe"))
33
+ I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.edit").should == i18ned
34
+ end
35
+
36
+ it "should replace a tag's content where the tag is an explicit one" do
37
+ plain = %(%p Egy, kettő, három, négy, öt.)
38
+ i18ned = %(%p I18n.t("users.show.egy_kettő_három_négy_öt"))
39
+ I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.show").should == i18ned
40
+ end
41
+
42
+ it "should replace a tag's content which is simple text all by itself on a line" do
43
+ plain = %(Türkçe)
44
+ i18ned = %(= I18n.t("users.new.türkçe"))
45
+ I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == i18ned
46
+ end
47
+ end
26
48
  end
data/spec/i15r_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
- # puts %(#{File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "i15r")})
1
+ # encoding: UTF-8
2
+
2
3
  $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
3
4
 
4
5
  require "i15r"
@@ -59,6 +60,14 @@ describe I15R::Base do
59
60
  it "should replace spaces with underscores" do
60
61
  I15R::Base.get_i18n_message_string("New name", "users.index").should == "users.index.new_name"
61
62
  end
63
+
64
+ it "should not rip out a non-english letter" do
65
+ I15R::Base.get_i18n_message_string("Mañana", "users.index").should == "users.index.mañana"
66
+ end
67
+
68
+ it "should replace a ' with an underscore" do
69
+ I15R::Base.get_i18n_message_string("C'est ça", "users.index").should == "users.index.cest_ça"
70
+ end
62
71
  end
63
72
 
64
73
  describe "when substituting the plain contents with i18n message strings" do
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
2
4
 
3
5
  require 'i15r/pattern_matcher'
@@ -8,10 +10,17 @@ describe I15R::PatternMatchers::Base do
8
10
  plain = %(#main)
9
11
  I15R::PatternMatchers::Base.run(plain, "users.new", :haml).should == plain
10
12
  end
13
+
11
14
  it "should properly replace a line with two matches" do
12
15
  plain = %(This is it: <a title="site root" href="/"><img src="site_logo.png" /></a>)
13
16
  i18ned = %(<%= I18n.t("users.new.this_is_it") %>: <a title="<%= I18n.t("users.new.site_root") %>" href="/"><img src="site_logo.png" /></a>)
14
17
  I15R::PatternMatchers::Base.run(plain, "users.new", :erb).should == i18ned
15
18
  end
19
+
20
+ it "should properly replace a line with two matches that have non-ascii chars" do
21
+ plain = %(C'est ça: <a title="site root" href="/"><img src="site_logo.png" /></a>)
22
+ i18ned = %(<%= I18n.t("users.new.cest_ça") %>: <a title="<%= I18n.t("users.new.site_root") %>" href="/"><img src="site_logo.png" /></a>)
23
+ I15R::PatternMatchers::Base.run(plain, "users.new", :erb).should == i18ned
24
+ end
16
25
 
17
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i15r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Balint Erdi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-14 00:00:00 +01:00
12
+ date: 2010-01-08 00:00:00 +01:00
13
13
  default_executable: i15r
14
14
  dependencies: []
15
15