i15r 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f5fb80fbc94c10caa8a7e63cb3a26209078c447d
4
+ data.tar.gz: d7cbd90394f3c1bfd9cfa9611c33e88ddfe79820
5
+ SHA512:
6
+ metadata.gz: b4e0f3ed0360fb99589fd6c8b14253226dd3c7fa6db964e946d395822f23141a950f664b4c3f0fca298dc66a2a70430294830cb8346ca25e75255ad892ef1be4
7
+ data.tar.gz: 8bd3dc91150ccfa99e36567ee8fb8d2cbb700274927df65d741c5ccf5b64f880b2e4fd49ec27c614f54a7ed36032bddfe5a5c0bc8312b695c3ae682bb3e7ce28
data/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ ### 0.5.1
2
+ * If no path is given, suppose it is 'app' to accomodate Rails apps
3
+
4
+ ### 0.5.0
5
+ * Insert the replaced text as default in i18n translation string and do it by default
6
+ * The -p (--pretend) option for dry-running is now -n (--dry-run)
7
+ * Totally revamp how pattern matching/string replacing is done, fix some errors
8
+
9
+ ### 0.4.4
10
+ * Adapt best practices/tools of 2012 (skipped 2.5 years of development)
11
+
12
+ ### 0.1.2
13
+ * More i18n in rails helpers, suppress printing of message strings in test mode, script can run on several files
14
+
15
+ ### 0.1.1
16
+ * Whitespace issues cleared up.
17
+
18
+ ### 0.1
19
+ * First version.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,21 @@
1
+ ## How to contribute
2
+
3
+ ### Bugs
4
+
5
+ Please report any errors to the [issue tracker][issue_tracker].
6
+
7
+ ### Bug fixes
8
+
9
+ If you can submit a fix for a bug, then please fork the repository, and issue a pull request once done.
10
+
11
+ If the bug concerns the pattern matching or the replacing (text not replaced as it should be, or text
12
+ that should not replaced is) always submit a test to validate your fix against.
13
+
14
+ If it's not a bug and the fix is trivial, having a test is not an absolute necessity but you gets (lots of) bonus points.
15
+
16
+ ### Enhancements, feature requests
17
+
18
+ The process is basically the same as for bug fixes. If you provide code that does what you'd like to see in the gem,
19
+ please issue a pull request. If you propose a feature, [open a ticket][issue_tracker].
20
+
21
+ [issue_tracker]: http://github.com/balinterdi/i15r/issues
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i15r (0.5.1)
4
+ i15r (0.5.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/Guardfile CHANGED
@@ -1,6 +1,5 @@
1
1
  guard 'rspec' do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
3
+ watch(%r{^lib/i15r/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
5
5
  end
6
-
data/README.markdown CHANGED
@@ -1,11 +1,16 @@
1
- # I15r ![Build Status](https://api.travis-ci.org/balinterdi/i15r.png)
1
+ # I15r ![Build Status](https://api.travis-ci.org/balinterdi/i15r.png) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/balinterdi/i15r)
2
2
 
3
+ ## Goal
4
+
5
+ You prefer polishing your views to manually replacing strings in them to make them i18n compatible.
6
+ If I got that one right, i15r is for you. It automates the process that would otherwise drive most of us nuts.
3
7
 
4
8
  ## Summary
5
9
 
6
- I15r (Internationalizer) searches for all the non-i18n texts in your views in
7
- the given files/directory and replaces them with I18n messages. The message
8
- string is based on the file in which the text was found and the text itself
10
+ I15r (Internationalizer) searches for all the non-i18n texts in your erb and haml templates in
11
+ the given file/directory and replaces them with I18n messages.
12
+
13
+ The message string is based on the path of the file in which the text was found and the text itself
9
14
  that was replaced.
10
15
 
11
16
  E.g
@@ -32,21 +37,23 @@ will be replaced by
32
37
  <label for="user-name"><%= I18n.t("member.users.edit.name") %></label>
33
38
  <input type="text" id="user-name" name="user[name]" />
34
39
 
35
- It can process erb and haml files.
36
-
37
40
  ## Installation
38
41
 
42
+ ### Standalone
43
+
39
44
  gem install i15r
40
45
 
41
- or put the following in your Gemfile:
46
+ ### In-app
47
+
48
+ Put the following in your Gemfile:
42
49
 
43
- gem 'i15r', '~> 0.4.4'
50
+ gem 'i15r', '~> 0.5.1'
44
51
 
45
52
  ## Usage
46
53
 
47
54
  ### Convert a single file
48
55
 
49
- i15r path/leading/to/view
56
+ i15r path/leading/to/template
50
57
 
51
58
  ### Convert all files in a directory (deep search)
52
59
 
@@ -66,7 +73,9 @@ or
66
73
 
67
74
  ### Custom prefix
68
75
 
69
- If you don't want the filename to appear in the i18n message string, you can pass a prefix parameter that will be used to generate the message strings. For example if you have the following in a file called app/views/users/new.html.erb:
76
+ If you don't want the file path to appear in the i18n message string,
77
+ you can pass a prefix parameter that will be used to generate the message strings.
78
+ For example if you have the following in a file called app/views/users/new.html.erb:
70
79
 
71
80
  <label for="user-name">Name</label>
72
81
  <input type="text" id="user-name" name="user[name]" />
@@ -80,23 +89,86 @@ The file will then contain:
80
89
  <label for="user-name"><%= I18n.t("my_project.name") %></label>
81
90
  <input type="text" id="user-name" name="user[name]" />
82
91
 
83
- ## Disclaimer (sort of)
92
+ If you want the a prefix plus the file path to appear in the i18n message string,
93
+ you can pass a prefix_with_path parameter:
94
+
95
+ i15r app/views/users/new.html.erb --prefix_with_path my_project
96
+
97
+ The above file will then contain:
98
+
99
+ <label for="user-name"><%= I18n.t("my_project.users.new.name") %></label>
100
+ <input type="text" id="user-name" name="user[name]" />
101
+
102
+ ### Override I18n.t function name
103
+
104
+ If you don't want to use the full I18n.t name, use the
105
+ override_i18n_method parameter:
106
+
107
+ i15r app/views/users/new.html.erb --override_i18n_method t
108
+
109
+ This will cause output that normally results in:
110
+
111
+ <label for="user-name"><%= I18n.t("users.new.name") %></label>
112
+
113
+ to result in
114
+
115
+ <label for="user-name"><%= t("users.new.name") %></label>
116
+
117
+ ### No default translation
118
+
119
+ If you want to skip the default translation, you must add the
120
+ --no-default flag
121
+
122
+ For example, if calling
123
+
124
+ i15r app/views/users/new.html.erb
125
+
126
+ results in
127
+
128
+ <label for="user-name"><%= I18n.t("users.new.name", :default => 'Name') %></label>
129
+
130
+ Adding the --no-default flag
131
+
132
+ i15r app/views/users/new.html.erb --no-default
133
+
134
+ results in
135
+
136
+ <label for="user-name"><%= I18n.t("users.new.name") %></label>
137
+
138
+ ## Design principles & suggested use
139
+
140
+ I15R takes the 80-20 approach. It focuses on finding most of the text that needs
141
+ to be replaced in your templates and replacing them with the correct i18n strings.
142
+ It forgoes the 100% hit rate in favor of getting the 80% right and keeping the code
143
+ (relatively) simple. Consequently, please [report][issue_tracker] any bug that concerns
144
+ strings that should not have been replaced or ones that have been replaced incorrectly.
145
+
146
+ A good practice is to first run i15r with the --dry-run option to see what would be replaced
147
+ and then run it for real, without the --dry-run option. You can also run it on files that have
148
+ already been "internationalized" since i15r will just skip those rows.
149
+
150
+ ### See also
151
+
152
+ Your next step is probably to create a YML locale file containing all the strings i15r generated. You're in luck! [missing_t][missing_t] is a gem that can do this for you.
153
+
154
+ ## Contributing
155
+
156
+ Please submit any bugs or feature requests to the [issue tracker][issue_tracker].
157
+
158
+ If you'd like to contibute, please see [Contributing][contributing].
159
+
160
+ ## License
161
+
162
+ Copyright (c) 2009 Balint Erdi
163
+
164
+ MIT License
84
165
 
85
- Please note that this is an early version mainly built up of examples I've come
86
- through doing client work. I am pretty sure there are a number of cases which
87
- i15r -at the moment- does not handle well (or at all). If you find such an
88
- example, please [let me know][issue_tracker] or if you feel motivated, submit a
89
- patch. Oh, yes, to prevent unwanted changes to your view files, you should use
90
- a SCM (that goes without saying, of course) and probably use the --pretend
91
- option.
166
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
92
167
 
93
- [issue_tracker]: http://github.com/balinterdi/i15r/issues
168
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
94
169
 
95
- ## Licensing, contribution
170
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
96
171
 
97
- The source code of this gem can be found at
98
- [http://github.com/balinterdi/i15r/](http://github.com/balinterdi/i15r/). It is
99
- released under the MIT-LICENSE, so you can basically do anything with it.
100
- However, if you think your modifications only make the tool better, please send
101
- a pull request or patch and I will consider merging in your changes. Any
102
- suggestions or feedback are welcome to <balint@balinterdi.com>.
172
+ [issue_tracker]: https://github.com/balinterdi/i15r/issues
173
+ [contributing]: https://github.com/balinterdi/i15r/blob/master/CONTRIBUTING.md
174
+ [missing_t]: https://github.com/balinterdi/missing_t
data/bin/i15r CHANGED
@@ -17,12 +17,19 @@ def parse_options(args)
17
17
  "Apply PREFIX to generated I18n messages instead of deriving it from the path") do |prefix|
18
18
  options[:prefix] = prefix
19
19
  end
20
+ opts.on("--prefix_with_path PREFIX",
21
+ "Apply PREFIX to generated I18n messages in front of the path") do |prefix|
22
+ options[:prefix_with_path] = prefix
23
+ end
20
24
  opts.on("-n", "--dry-run", "Do not write the files, just show the diff") do
21
25
  options[:dry_run] = true
22
26
  end
23
27
  opts.on("--no-default", "Do not insert the replaced string as the :default in the I18n string") do
24
28
  options[:add_default] = false
25
29
  end
30
+ opts.on("--override_i18n_method METHOD", "Replace I18n.t with METHOD") do |m|
31
+ options[:override_i18n_method] = m
32
+ end
26
33
 
27
34
  opts.on_tail("-h", "--help", "Show this message") do
28
35
  puts opts
data/lib/i15r.rb CHANGED
@@ -9,7 +9,11 @@ class I15R
9
9
  end
10
10
 
11
11
  def prefix
12
- @options.fetch(:prefix, nil)
12
+ @options.fetch(:prefix, nil) || prefix_with_path
13
+ end
14
+
15
+ def prefix_with_path
16
+ @options.fetch(:prefix_with_path, nil)
13
17
  end
14
18
 
15
19
  def dry_run?
@@ -19,6 +23,10 @@ class I15R
19
23
  def add_default
20
24
  @options.fetch(:add_default, true)
21
25
  end
26
+
27
+ def override_i18n_method
28
+ @options.fetch(:override_i18n_method, nil)
29
+ end
22
30
  end
23
31
 
24
32
  attr_reader :config
@@ -55,18 +63,24 @@ class I15R
55
63
  end
56
64
  end
57
65
 
66
+ def full_prefix(path)
67
+ prefix = [config.prefix]
68
+ prefix << file_path_to_message_prefix(path) if include_path?
69
+ prefix.compact.join('.')
70
+ end
71
+
58
72
  def internationalize_file(path)
59
73
  text = @reader.read(path)
60
- prefix = config.prefix || file_path_to_message_prefix(path)
61
74
  template_type = path[/(?:.*)\.(.*)$/, 1]
62
75
  @printer.println("#{path}:")
63
76
  @printer.println("")
64
- i18ned_text = sub_plain_strings(text, prefix, template_type.to_sym)
77
+ i18ned_text = sub_plain_strings(text, full_prefix(path), template_type.to_sym)
65
78
  @writer.write(path, i18ned_text) unless config.dry_run?
66
79
  end
67
80
 
68
81
  def sub_plain_strings(text, prefix, file_type)
69
- pm = I15R::PatternMatcher.new(prefix, file_type, :add_default => config.add_default)
82
+ pm = I15R::PatternMatcher.new(prefix, file_type, :add_default => config.add_default,
83
+ :override_i18n_method => config.override_i18n_method)
70
84
  transformed_text = pm.run(text) do |old_line, new_line|
71
85
  @printer.print_diff(old_line, new_line)
72
86
  end
@@ -79,4 +93,9 @@ class I15R
79
93
  files = File.directory?(path) ? Dir.glob("#{path}/**/*.{erb,haml}") : [path]
80
94
  files.each { |file| internationalize_file(file) }
81
95
  end
96
+
97
+ def include_path?
98
+ config.prefix_with_path || !config.prefix
99
+ end
100
+
82
101
  end
@@ -1,15 +1,17 @@
1
+ # -*- coding: utf-8 -*-
1
2
  class I15R
2
3
  class PatternMatcher
3
4
  HAML_SYMBOLS = ["%", "#", "{", "}", "(", ")", ".", "_", "-"]
4
5
  PATTERNS = {
5
6
  :erb => [
6
- /<%=\s*link_to\s+(?<title>['"].+?['"])/,
7
+ /<%=\s*link_to\s+(?!.*&.*;)(?<title>['"].+?['"])/,
7
8
  /<%=.*label(_tag)?[^,]+?(?<label-title>(['"].+?['"]|:[[:alnum:]_]+))[^,]+%>.*$/,
8
9
  /<%=.*label(_tag)?.*?,\s*(?<label-title>(['"].+?['"]|:[[:alnum:]_]+))/,
9
10
  /<%=.*submit(_tag)?\s+(?<submit-text>(['"].+?['"]|:[[:alnum:]_]+))/,
10
- />(?<tag-content>[[:space:][:alnum:][:punct:]]+?)<\//,
11
+ />(?<tag-content>(?!&.*;)[[:space:][:alnum:][:punct:]]+?)<\//,
11
12
  /<a\s+title=['"](?<link-title>.+?)['"]/,
12
- /^\s*(?<pre-tag-text>[[:alnum:]]+[[:alnum:][:space:][:punct:]]*?)</
13
+ /^\s*(?<pre-tag-text>[[:alnum:]]+[[:alnum:][:space:][:punct:]]*?)</,
14
+ /^(?!^var .*)(?!.*(%>|{|})$)(?!.*(:|=).*(;|,)$)(?!.*return .*;$)(?!.*=)(?!^(if |unless ).*(\=|\&|\|))(?!^(if |unless )\S+$)(?!^end$)(?!.*do.*\|$)\s*(?<no-markup-content>[[:alnum:]]+[[:alnum:][:space:][:punct:]]*)/
13
15
  ],
14
16
  :haml => [
15
17
  /=.*link_to\s+(?<title>['"].+?['"]),/,
@@ -27,7 +29,7 @@ class I15R
27
29
  @prefix = prefix
28
30
  @file_type = file_type
29
31
  transformer_class = self.class.const_get("#{file_type.to_s.capitalize}Transformer")
30
- @transformer = transformer_class.new(options[:add_default])
32
+ @transformer = transformer_class.new(options[:add_default], options[:override_i18n_method] || 'I18n.t')
31
33
  end
32
34
 
33
35
  def translation_key(text)
@@ -41,11 +43,15 @@ class I15R
41
43
  lines = text.split("\n")
42
44
  new_lines = lines.map do |line|
43
45
  new_line = line
44
- PATTERNS[@file_type].detect do |pattern|
45
- if m = pattern.match(line)
46
- m.names.each do |group_name|
47
- if /\w/.match(m[group_name])
48
- new_line = @transformer.transform(m, m[group_name], line, translation_key(m[group_name]))
46
+ if line !~ /[[:alpha:]]/
47
+ new_line
48
+ else
49
+ PATTERNS[@file_type].detect do |pattern|
50
+ if m = pattern.match(line)
51
+ m.names.each do |group_name|
52
+ if /\w/.match(m[group_name])
53
+ new_line = @transformer.transform(m, m[group_name], line, translation_key(m[group_name]))
54
+ end
49
55
  end
50
56
  end
51
57
  end
@@ -59,8 +65,9 @@ class I15R
59
65
  end
60
66
 
61
67
  class Transformer
62
- def initialize(add_default)
68
+ def initialize(add_default, i18n_method)
63
69
  @add_default = add_default
70
+ @i18n_method = i18n_method
64
71
  end
65
72
 
66
73
  private
@@ -72,9 +79,9 @@ class I15R
72
79
  unless original[0] == "'" or original[0] == '"'
73
80
  original = %("#{original}")
74
81
  end
75
- %(I18n.t("#{key}", :default => #{original}))
82
+ %(#{@i18n_method}("#{key}", :default => #{original}))
76
83
  else
77
- %(I18n.t("#{key}"))
84
+ %(#{@i18n_method}("#{key}"))
78
85
  end
79
86
  end
80
87
  end
data/lib/i15r/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class I15R
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
data/spec/i15r_spec.rb CHANGED
@@ -39,9 +39,9 @@ describe I15R do
39
39
 
40
40
  describe "writing the changed file" do
41
41
  let(:path) { "app/views/users/new.html.erb" }
42
- let(:reader) { mock(:read => %Q{<label for="user-name">Name</label>}) }
43
- let(:writer) { mock("writer") }
44
- let(:printer) { mock("printer") }
42
+ let(:reader) { double(:read => %Q{<label for="user-name">Name</label>}) }
43
+ let(:writer) { double("writer") }
44
+ let(:printer) { double("printer") }
45
45
 
46
46
  subject { I15R.new(reader, writer, printer) }
47
47
 
@@ -59,8 +59,8 @@ describe I15R do
59
59
 
60
60
 
61
61
  describe "generating the prefix" do
62
- let(:reader) { mock(:read => %Q{<label for="user-name">Name</label>}) }
63
- let(:writer) { mock("writer") }
62
+ let(:reader) { double(:read => %Q{<label for="user-name">Name</label>}) }
63
+ let(:writer) { double("writer") }
64
64
 
65
65
  subject { I15R.new(reader, writer, I15R::NullPrinter.new) }
66
66
 
@@ -92,11 +92,22 @@ describe I15R do
92
92
  subject.internationalize_file(path)
93
93
  end
94
94
  end
95
+
96
+ describe "when there is an explicit prefix with path" do
97
+ let(:path) { "app/views/users/_badge.html.erb" }
98
+
99
+ subject { I15R.new(reader, writer, I15R::NullPrinter.new, :prefix_with_path => "nice") }
100
+
101
+ specify do
102
+ writer.should_receive(:write).with(path, %Q{<label for="user-name"><%= I18n.t("nice.users.badge.name", :default => "Name") %></label>\n})
103
+ subject.internationalize_file(path)
104
+ end
105
+ end
95
106
  end
96
107
 
97
108
  describe "the add_default option" do
98
109
  let(:path) { "app/users/views/index.html.haml" }
99
- let(:patter_matcher) { mock("pattern matcher", :run => "") }
110
+ let(:patter_matcher) { double("pattern matcher", :run => "") }
100
111
  let(:i15r) { I15R::Fixture.new }
101
112
 
102
113
  subject { I15R::Fixture.new }
@@ -9,9 +9,17 @@ describe I15R::PatternMatcher do
9
9
  describe "in erb templates" do
10
10
  let(:pattern_matcher) { I15R::PatternMatcher.new("users.new", :erb) }
11
11
 
12
+ describe "no-markup content" do
13
+ it { should internationalize("please visit").to('<%= I18n.t("users.new.please_visit") %>') }
14
+ it { should internationalize("12").to_the_same }
15
+ it { should internationalize("12 Monkeys").to('<%= I18n.t("users.new.12_monkeys") %>') }
16
+ end
17
+
12
18
  describe "in tag content" do
13
19
  it { should internationalize('<h1>New flight</h1>')
14
20
  .to('<h1><%= I18n.t("users.new.new_flight") %></h1>') }
21
+ it { should internationalize('<h1>Don\'t worry</h1>')
22
+ .to('<h1><%= I18n.t("users.new.dont_worry") %></h1>') }
15
23
  it { should internationalize(%(<label for="user-name">Name</label>))
16
24
  .to(%(<label for="user-name"><%= I18n.t("users.new.name") %></label>)) }
17
25
 
@@ -39,10 +47,84 @@ describe I15R::PatternMatcher do
39
47
  .to(%( <%= f.label I18n.t("users.new.name", :default => "name") %><br />)) }
40
48
  end
41
49
 
50
+ describe "when the default option is false" do
51
+ let(:pattern_matcher) { I15R::PatternMatcher.new("users.new", :erb, :add_default => false) }
52
+
53
+ it { should internationalize('<h1>New flight</h1>')
54
+ .to('<h1><%= I18n.t("users.new.new_flight") %></h1>') }
55
+ it { should internationalize(%( <%= f.label :name %><br />))
56
+ .to(%( <%= f.label I18n.t("users.new.name") %><br />)) }
57
+ end
58
+
59
+ describe "when the I18n function is overriden" do
60
+ let(:pattern_matcher) { I15R::PatternMatcher.new("users.new", :erb, :override_i18n_method => 't') }
61
+
62
+ it { should internationalize('<h1>New flight</h1>')
63
+ .to('<h1><%= t("users.new.new_flight") %></h1>') }
64
+ end
65
+
42
66
  describe "when a line is already international" do
43
67
  it { should internationalize(%( <%= f.label I18n.t("users.new.name") %>)).to_the_same }
44
68
  it { should internationalize(%( <%= f.label t("users.new.name") %>)).to_the_same }
45
69
  end
70
+
71
+ describe "when a line contains Ruby variables only" do
72
+ it { should internationalize(%( <%= hello_world %> )).to_the_same }
73
+ it { should internationalize(%( <h1><%= hello_world %></h1> )).to_the_same }
74
+ end
75
+
76
+ describe "when a line contains Ruby method calls with options" do
77
+ it { should internationalize(%( <%= hello_world(:option => true) %> )).to_the_same }
78
+ it { should internationalize(%( <%= hello_world(option: true) %> )).to_the_same }
79
+ it { should internationalize(%( <h1><%= hello_world(:option => true) %></h1> )).to_the_same }
80
+ it { should internationalize(%( <h1><%= hello_world(option: true) %></h1> )).to_the_same }
81
+ end
82
+
83
+ describe "when a line contains Ruby code" do
84
+ it { should internationalize("variable = value").to_the_same }
85
+ it { should internationalize("if something").to_the_same }
86
+ it { should internationalize("if some == value").to_the_same }
87
+ it { should internationalize("if some && value").to_the_same }
88
+ it { should internationalize("if some || value").to_the_same }
89
+ it { should internationalize("unless something").to_the_same }
90
+ it { should internationalize("unless some == value").to_the_same }
91
+ it { should internationalize("unless some && value").to_the_same }
92
+ it { should internationalize("unless some || value").to_the_same }
93
+ it { should internationalize("something do |val|").to_the_same }
94
+ it { should internationalize("end").to_the_same }
95
+ it { should internationalize("something %>").to_the_same }
96
+ it { should internationalize("key: value,").to_the_same }
97
+ it { should internationalize(":key => value").to_the_same }
98
+
99
+ it { should internationalize("some string,").to('<%= I18n.t("users.new.some_string") %>') }
100
+ it { should internationalize("some string;").to('<%= I18n.t("users.new.some_string") %>') }
101
+ it { should internationalize("things i do").to('<%= I18n.t("users.new.things_i_do") %>') }
102
+ it { should internationalize("if you can").to('<%= I18n.t("users.new.if_you_can") %>') }
103
+ end
104
+
105
+ describe "when a line contains Javascript code" do
106
+ it { should internationalize("var variable").to_the_same }
107
+ it { should internationalize("if (interesting) {").to_the_same }
108
+ it { should internationalize("if (!interesting) {").to_the_same }
109
+ it { should internationalize("return result;").to_the_same }
110
+ end
111
+
112
+ describe "when a line contains CSS code" do
113
+ it { should internationalize("overflow: auto;").to_the_same }
114
+ end
115
+
116
+ describe "when a line contains HTML entities" do
117
+ it { should internationalize("&nbsp;").to_the_same }
118
+ it { should internationalize("<h1>&nbsp;</h1>").to_the_same }
119
+ it { should internationalize('<%= link_to "&nbsp; >".html_safe, next_page_path %>').to_the_same }
120
+ end
121
+
122
+ describe "when a line contains a form method calls with options" do
123
+ it { should internationalize(%( <%= f.email_field :email, :option => true %> )).to_the_same }
124
+ it { should internationalize(%( <%= f.email_field :email, option: true %> )).to_the_same }
125
+ it { should internationalize(%( <h1><%= f.email_field :email, :option => true %></h1> )).to_the_same }
126
+ it { should internationalize(%( <h1><%= f.email_field :email, option: true %></h1> )).to_the_same }
127
+ end
46
128
  end
47
129
 
48
130
  describe "in tag attributes" do
@@ -84,6 +166,13 @@ describe I15R::PatternMatcher do
84
166
  .to(%(<%= submit_tag I18n.t("users.index.create_user", :default => "Create user") %>)) }
85
167
  end
86
168
 
169
+ describe "when the default option is false" do
170
+ let(:pattern_matcher) { I15R::PatternMatcher.new("users.index", :erb, :add_default => false) }
171
+
172
+ it { should internationalize(%(<%= submit_tag "Create user" %>))
173
+ .to(%(<%= submit_tag I18n.t("users.index.create_user") %>)) }
174
+ end
175
+
87
176
  describe "when text has non-ascii characters" do
88
177
  it { should internationalize(%(<p class="highlighted"><%= link_to 'Új felhasználó', new_user_path %>?</p>))
89
178
  .to(%(<p class="highlighted"><%= link_to I18n.t("users.index.Új_felhasználó"), new_user_path %>?</p>)) }
@@ -118,6 +207,12 @@ describe I15R::PatternMatcher do
118
207
  describe "in haml templates" do
119
208
  let(:pattern_matcher) { I15R::PatternMatcher.new("users.show", :haml) }
120
209
 
210
+ describe "no-markup content" do
211
+ it { should internationalize("please visit").to('= I18n.t("users.show.please_visit")') }
212
+ it { should internationalize("12").to_the_same }
213
+ it { should internationalize("12 Monkeys").to('= I18n.t("users.show.12_monkeys")') }
214
+ end
215
+
121
216
  it { should internationalize('#main').to_the_same }
122
217
 
123
218
  it { should internationalize(%(#form_head My account))
@@ -127,12 +222,14 @@ describe I15R::PatternMatcher do
127
222
  .to(%(%p= I18n.t("users.show.please_check_your_inbox_and_click_on_the_activation_link"))) }
128
223
 
129
224
  it { should internationalize("please visit").to('= I18n.t("users.show.please_visit")') }
225
+ it { pending "broken"; should internationalize("apples &amp; oranges").to('= I18n.t("users.show.apples_oranges")') }
130
226
  it { should internationalize("Mañana").to('= I18n.t("users.show.mañana")') }
131
227
  it { should internationalize("C'est ça").to('= I18n.t("users.show.cest_ça")') }
132
228
  it { should internationalize(%(%p Do not close/reload while loading))
133
229
  .to(%(%p= I18n.t("users.show.do_not_close_reload_while_loading"))) }
134
230
  it { should internationalize(%( .field)).to(%( .field)) }
135
231
  it { should internationalize('%p').to_the_same }
232
+ it { pending "broken"; should internationalize('%p #{variable}').to_the_same }
136
233
  it { should internationalize(%(%h2 Resend unlock instructions))
137
234
  .to(%(%h2= I18n.t("users.show.resend_unlock_instructions"))) }
138
235
  it { should internationalize(%(%i (we need your password to confirm your changes)))
@@ -158,6 +255,18 @@ describe I15R::PatternMatcher do
158
255
  .to(%( %h3= I18n.t("users.show.top_scorers", :default => "Top Scorers"))) }
159
256
  end
160
257
 
258
+ describe "when the default option is false" do
259
+ let(:pattern_matcher) { I15R::PatternMatcher.new("users.show", :haml, :add_default => false ) }
260
+ it { should internationalize(%( %h3 Top Scorers))
261
+ .to(%( %h3= I18n.t("users.show.top_scorers"))) }
262
+ end
263
+
264
+ describe "when the I18n function is overriden" do
265
+ let(:pattern_matcher) { I15R::PatternMatcher.new("users.show", :haml, :override_i18n_method => 't', :add_default => true) }
266
+ it { should internationalize(%( %h3 Top Scorers))
267
+ .to(%( %h3= t("users.show.top_scorers", :default => "Top Scorers"))) }
268
+ end
269
+
161
270
  describe "when already evaluated" do
162
271
  it { should internationalize(%(%p= link_to 'New user', new_user_path))
163
272
  .to(%(%p= link_to I18n.t("users.show.new_user"), new_user_path)) }
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i15r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
5
- prerelease:
4
+ version: 0.5.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Balint Erdi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-08 00:00:00.000000000 Z
11
+ date: 2013-09-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: guard
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: guard-rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rb-fsevent
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -96,109 +85,67 @@ description: The internationalizer. Replaces plain text strings in your views an
96
85
  email:
97
86
  - balint.erdi@gmail.com
98
87
  executables:
99
- - !binary |-
100
- aTE1cg==
88
+ - i15r
101
89
  extensions: []
102
90
  extra_rdoc_files: []
103
91
  files:
104
- - !binary |-
105
- LmdpdGlnbm9yZQ==
106
- - !binary |-
107
- LnRyYXZpcy55bWw=
108
- - !binary |-
109
- Q0hBTkdFTE9H
110
- - !binary |-
111
- R2VtZmlsZQ==
112
- - !binary |-
113
- R2VtZmlsZS5sb2Nr
114
- - !binary |-
115
- R3VhcmRmaWxl
116
- - !binary |-
117
- TUlULUxJQ0VOU0U=
118
- - !binary |-
119
- TWFuaWZlc3Q=
120
- - !binary |-
121
- UkVBRE1FLm1hcmtkb3du
122
- - !binary |-
123
- UmFrZWZpbGU=
124
- - !binary |-
125
- YmluL2kxNXI=
126
- - !binary |-
127
- aTE1ci5nZW1zcGVj
128
- - !binary |-
129
- aW5pdC5yYg==
130
- - !binary |-
131
- bGliL2kxNXIucmI=
132
- - !binary |-
133
- bGliL2kxNXIvY29uc29sZV9wcmludGVyLnJi
134
- - !binary |-
135
- bGliL2kxNXIvZmlsZV9yZWFkZXIucmI=
136
- - !binary |-
137
- bGliL2kxNXIvZmlsZV93cml0ZXIucmI=
138
- - !binary |-
139
- bGliL2kxNXIvcGF0dGVybl9tYXRjaGVyLnJi
140
- - !binary |-
141
- bGliL2kxNXIvdmVyc2lvbi5yYg==
142
- - !binary |-
143
- c3BlYy9pMTVyX3NwZWMucmI=
144
- - !binary |-
145
- c3BlYy9wYXR0ZXJuX21hdGNoZXJfc3BlYy5yYg==
146
- - !binary |-
147
- c3BlYy9zcGVjLm9wdHM=
148
- - !binary |-
149
- c3BlYy9zcGVjX2hlbHBlci5yYg==
150
- - !binary |-
151
- c3BlYy9zdXBwb3J0L2ludGVybmF0aW9uYWxpemVfbWF0Y2hlci5yYg==
152
- - !binary |-
153
- c3BlYy9zdXBwb3J0L25ld19mbGlnaHQuaHRtbC5lcmI=
154
- - !binary |-
155
- c3BlYy9zdXBwb3J0L25ld191c2VyLmh0bWwuaGFtbA==
156
- - !binary |-
157
- dGFza3MvaTE1ci5yYWtl
158
- - !binary |-
159
- dG9kb3MubWFya2Rvd24=
92
+ - .gitignore
93
+ - .travis.yml
94
+ - CHANGELOG.md
95
+ - CONTRIBUTING.md
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - Guardfile
99
+ - MIT-LICENSE
100
+ - Manifest
101
+ - README.markdown
102
+ - Rakefile
103
+ - bin/i15r
104
+ - i15r.gemspec
105
+ - init.rb
106
+ - lib/i15r.rb
107
+ - lib/i15r/console_printer.rb
108
+ - lib/i15r/file_reader.rb
109
+ - lib/i15r/file_writer.rb
110
+ - lib/i15r/pattern_matcher.rb
111
+ - lib/i15r/version.rb
112
+ - spec/i15r_spec.rb
113
+ - spec/pattern_matcher_spec.rb
114
+ - spec/spec.opts
115
+ - spec/spec_helper.rb
116
+ - spec/support/internationalize_matcher.rb
117
+ - spec/support/new_flight.html.erb
118
+ - spec/support/new_user.html.haml
119
+ - tasks/i15r.rake
120
+ - todos.markdown
160
121
  homepage: ''
161
122
  licenses: []
123
+ metadata: {}
162
124
  post_install_message:
163
125
  rdoc_options: []
164
126
  require_paths:
165
127
  - lib
166
128
  required_ruby_version: !ruby/object:Gem::Requirement
167
- none: false
168
129
  requirements:
169
- - - ! '>='
130
+ - - '>='
170
131
  - !ruby/object:Gem::Version
171
132
  version: '0'
172
- segments:
173
- - 0
174
- hash: -531769928414317979
175
133
  required_rubygems_version: !ruby/object:Gem::Requirement
176
- none: false
177
134
  requirements:
178
- - - ! '>='
135
+ - - '>='
179
136
  - !ruby/object:Gem::Version
180
137
  version: '0'
181
- segments:
182
- - 0
183
- hash: -531769928414317979
184
138
  requirements: []
185
139
  rubyforge_project:
186
- rubygems_version: 1.8.23
140
+ rubygems_version: 2.0.5
187
141
  signing_key:
188
- specification_version: 3
142
+ specification_version: 4
189
143
  summary: Eases the pain of moving to I18n view templates
190
144
  test_files:
191
- - !binary |-
192
- c3BlYy9pMTVyX3NwZWMucmI=
193
- - !binary |-
194
- c3BlYy9wYXR0ZXJuX21hdGNoZXJfc3BlYy5yYg==
195
- - !binary |-
196
- c3BlYy9zcGVjLm9wdHM=
197
- - !binary |-
198
- c3BlYy9zcGVjX2hlbHBlci5yYg==
199
- - !binary |-
200
- c3BlYy9zdXBwb3J0L2ludGVybmF0aW9uYWxpemVfbWF0Y2hlci5yYg==
201
- - !binary |-
202
- c3BlYy9zdXBwb3J0L25ld19mbGlnaHQuaHRtbC5lcmI=
203
- - !binary |-
204
- c3BlYy9zdXBwb3J0L25ld191c2VyLmh0bWwuaGFtbA==
145
+ - spec/i15r_spec.rb
146
+ - spec/pattern_matcher_spec.rb
147
+ - spec/spec.opts
148
+ - spec/spec_helper.rb
149
+ - spec/support/internationalize_matcher.rb
150
+ - spec/support/new_flight.html.erb
151
+ - spec/support/new_user.html.haml
data/CHANGELOG DELETED
@@ -1,5 +0,0 @@
1
- v0.1.2 More i18n in rails helpers, suppress printing of message strings in test mode, script can run on several files
2
-
3
- v0.1.1 Whitespace issues cleared up.
4
-
5
- v0.1 First version.