ready_for_i18n 0.2.7 → 0.2.8
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/README.textile +57 -0
- data/VERSION +1 -1
- data/bin/ready_for_i18n +10 -4
- data/lib/erb_helper_extractor.rb +2 -2
- data/lib/{base_extractor.rb → extractor_base.rb} +11 -1
- data/lib/html_attr_extractor.rb +3 -0
- data/lib/html_text_extractor.rb +10 -3
- data/lib/i18n_generator.rb +7 -1
- data/lib/locale_dictionary.rb +19 -3
- data/lib/ready_for_i18n.rb +1 -1
- data/ready_for_i18n.gemspec +7 -7
- data/test/fixtures/index.html.erb +6 -0
- data/test/output/label.html.erb +6 -0
- data/test/test_erb_helper_extractor.rb +1 -0
- data/test/test_extractor_base.rb +40 -0
- data/test/test_html_text_extractor.rb +10 -1
- data/test/test_locale_dictionary.rb +17 -6
- metadata +7 -7
- data/README.rdoc +0 -51
- data/test/test_base_extractor.rb +0 -20
data/README.textile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
h1. ready_for_i18n
|
2
|
+
|
3
|
+
Ready_for_i18n is handy tool helping you in the first step of getting your local Rails project ready for I18N.
|
4
|
+
|
5
|
+
It will automatically extract hard-coded text from your ERB view file,
|
6
|
+
then choose a proper key and replace them with the I18n.translate method.
|
7
|
+
|
8
|
+
Currently three extractors are available:
|
9
|
+
|
10
|
+
|Extractor|From|To|
|
11
|
+
|HtmlTextExtractor|@<b>Hello</b>@|@<b><%=t(:text_hello)%></b>@|
|
12
|
+
|HtmlAttrExtractor|@<input type="submit" value="Back"/>@|@<input type="submit" value="<%=t(:label_back)"/>@|
|
13
|
+
|ErbHelperExtractor|@link_to('Login'...)@|@link_to (t(:login))@|
|
14
|
+
|
15
|
+
|
16
|
+
Introduction Blog at: "Get your application ready for I18N":http://zigzag.github.com/2009/12/17/get-your-local-rails-application-ready-for-i18n.html
|
17
|
+
|
18
|
+
h2. Installation:
|
19
|
+
|
20
|
+
bq. gem install ready_for_i18n
|
21
|
+
|
22
|
+
Hosed at "http://www.gemcutter.org/gems/ready_for_i18n":http://www.gemcutter.org/gems/ready_for_i18n
|
23
|
+
|
24
|
+
h2. Basic Command Line Usage:
|
25
|
+
|
26
|
+
bq. @ready_for_i18n <path_to_ERB_source_files> [target path]@
|
27
|
+
|
28
|
+
Your erb files in source path will be transformed(i18n_ready) and copy to target file path.
|
29
|
+
If the target path is missing, then ready_for_i18n will do a Dry run and only generate the locale file.
|
30
|
+
|
31
|
+
A locale file will be output to STDOUT, which you can redirect to file like
|
32
|
+
|
33
|
+
bq. @ready_for_i18n <path_to_ERB_source_files> [target path] > /temp/en.yml@
|
34
|
+
|
35
|
+
Using the following options:
|
36
|
+
|
37
|
+
| |@--locale [LOCALE]@|@Generating for the specified locale (default locale 'en')@|
|
38
|
+
| |@--ext [EXTENSION]@|@The file extension name of your views(default '.html.erb')@|
|
39
|
+
|
40
|
+
h2. Warning
|
41
|
+
|
42
|
+
* This tool is used based on the most "conventional" way of HTML and ERB. But I can not guarantee all the text will be extracted correctly. Create an issue in this github project page if you found some thing miss.
|
43
|
+
* Only tested when the local language is English. Other languages support is in the TODO list.
|
44
|
+
|
45
|
+
h2. Note on Patches/Pull Requests
|
46
|
+
|
47
|
+
* Fork the project.
|
48
|
+
* Make your feature addition or bug fix.
|
49
|
+
* Add tests for it. This is important so I don't break it in a
|
50
|
+
future version unintentionally.
|
51
|
+
* Commit, do not mess with rakefile, version, or history.
|
52
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
53
|
+
* Send me a pull request. Bonus points for topic branches.
|
54
|
+
|
55
|
+
h2. Copyright
|
56
|
+
|
57
|
+
Copyright (c) 2009 zigzag. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.8
|
data/bin/ready_for_i18n
CHANGED
@@ -11,11 +11,13 @@ It will automatically extract hard-coded text from your ERB view file,
|
|
11
11
|
then choose a proper key and replace them with the I18n.translate method.
|
12
12
|
|
13
13
|
Basic Command Line Usage:
|
14
|
-
ready_for_i18n <
|
15
|
-
|
16
|
-
# Your erb files in source path will be transformed(i18n_ready)
|
17
|
-
# and copy to target file path,together with a locale file 'en.yml'.
|
14
|
+
ready_for_i18n <path_to_ERB_source_files> [target path]
|
18
15
|
|
16
|
+
# Your erb files in source path will be transformed(i18n_ready) and copy to target file path.
|
17
|
+
# If the target path is missing, then ready_for_i18n will do a Dry run and only generate the locale file.
|
18
|
+
# A locale file will be output to STDOUT, which you can redirect to file like
|
19
|
+
# ready_for_i18n <path_to_ERB_source_files> [target path] > /temp/en.yml
|
20
|
+
|
19
21
|
# using the following options:
|
20
22
|
|
21
23
|
HELP
|
@@ -34,6 +36,10 @@ opts = OptionParser.new do |opts|
|
|
34
36
|
opts.on("--ext [EXTENSION]", "The file extension name of your views(default '.html.erb')") do |extension|
|
35
37
|
options['extension'] = extension unless extension.nil?
|
36
38
|
end
|
39
|
+
|
40
|
+
opts.on("--dot","Generate a structured dictionary file and support `Lazy` Lookup of Rails > 2.3 ") do |dot|
|
41
|
+
options['dot'] = true
|
42
|
+
end
|
37
43
|
|
38
44
|
end
|
39
45
|
|
data/lib/erb_helper_extractor.rb
CHANGED
@@ -2,7 +2,7 @@ module ReadyForI18N
|
|
2
2
|
class ErbHelperExtractor
|
3
3
|
LABEL_IN_HELPER_PATTERN = %w{label_tag link_to field_set_tag submit_tag button_to}.map{|h| /#{h}[\s\w_]*('|")([\w ]*)(\1)/ }
|
4
4
|
|
5
|
-
include ReadyForI18N::
|
5
|
+
include ReadyForI18N::ExtractorBase
|
6
6
|
|
7
7
|
protected
|
8
8
|
def values_in_line(line)
|
@@ -15,7 +15,7 @@ module ReadyForI18N
|
|
15
15
|
s.strip[1..-2]
|
16
16
|
end
|
17
17
|
def replace_line(line,e)
|
18
|
-
line.gsub!(e,
|
18
|
+
line.gsub!(e,t_method(e))
|
19
19
|
end
|
20
20
|
def key_prefix
|
21
21
|
'label'
|
@@ -1,8 +1,14 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
|
3
3
|
module ReadyForI18N
|
4
|
-
module
|
4
|
+
module ExtractorBase
|
5
5
|
VALUE_PATTERN = /\w+/
|
6
|
+
def self.use_dot(on_off)
|
7
|
+
@use_dot = on_off
|
8
|
+
end
|
9
|
+
def self.use_dot?
|
10
|
+
@use_dot
|
11
|
+
end
|
6
12
|
def extract(input)
|
7
13
|
buffer = StringIO.new
|
8
14
|
input.each do |line|
|
@@ -25,5 +31,9 @@ module ReadyForI18N
|
|
25
31
|
def can_replace?(e)
|
26
32
|
e.scan(VALUE_PATTERN).length > 0
|
27
33
|
end
|
34
|
+
def t_method(val,wrap=false)
|
35
|
+
m = ExtractorBase.use_dot? ? "t('.#{to_key(val)}')" : "t(:#{to_key(val)})"
|
36
|
+
wrap ? "<%=#{m}%>" : m
|
37
|
+
end
|
28
38
|
end
|
29
39
|
end
|
data/lib/html_attr_extractor.rb
CHANGED
data/lib/html_text_extractor.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module ReadyForI18N
|
2
2
|
class HtmlTextExtractor
|
3
3
|
SKIP_TAGS = [[/<script/i,/<\/script>/i],[/<%/,/%>/],[/<style/i,/\/style>/i]]
|
4
|
-
SKIP_INLINE_TAG = [/<%(.*?)%>/,/<(.*?)
|
4
|
+
SKIP_INLINE_TAG = [/<%(.*?)%>/,/<(.*?)>/,/<(.*)$/,/^(.*)>/,/ /]
|
5
5
|
SEPERATOR = '_@@@_'
|
6
6
|
|
7
|
-
include ReadyForI18N::
|
7
|
+
include ReadyForI18N::ExtractorBase
|
8
8
|
|
9
9
|
protected
|
10
10
|
def values_in_line(line)
|
@@ -28,7 +28,14 @@ module ReadyForI18N
|
|
28
28
|
s.strip
|
29
29
|
end
|
30
30
|
def replace_line(line,e)
|
31
|
-
line.
|
31
|
+
repeat = line.scan(e).size
|
32
|
+
replaced = t_method(e,true)
|
33
|
+
return line if repeat == 0
|
34
|
+
return line.sub!(e,replaced) if repeat == 1
|
35
|
+
if repeat > 1
|
36
|
+
line.gsub!(/>\s*#{e}\s*</,">#{replaced}<")
|
37
|
+
line.gsub!(/>\s*#{e}/,">#{replaced}")
|
38
|
+
end
|
32
39
|
end
|
33
40
|
def key_prefix
|
34
41
|
'text'
|
data/lib/i18n_generator.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module ReadyForI18N
|
2
2
|
class I18nGenerator
|
3
3
|
EXTRACTORS = [ErbHelperExtractor,HtmlTextExtractor,HtmlAttrExtractor]
|
4
|
+
PATH_PATTERN = /\/views\/(.*)/
|
5
|
+
|
4
6
|
def self.excute(opt)
|
5
7
|
@src_path = opt['source']
|
6
8
|
@target_path = opt['destination']
|
@@ -9,10 +11,14 @@ module ReadyForI18N
|
|
9
11
|
end
|
10
12
|
@locale = opt['locale']
|
11
13
|
@ext = opt['extension'] || '.html.erb'
|
14
|
+
|
15
|
+
ReadyForI18N::ExtractorBase.use_dot(true) if opt['dot']
|
16
|
+
|
12
17
|
dict = ReadyForI18N::LocaleDictionary.new(@locale)
|
13
18
|
Dir.glob(File.join(@src_path,"**#{File::SEPARATOR}*#{@ext}")).each do |f|
|
19
|
+
path = f.match(PATH_PATTERN)[1].gsub(/#{@ext}$/,'').split '/' if opt['dot'] && f =~ PATH_PATTERN
|
14
20
|
result = EXTRACTORS.inject(File.read(f)) do |buffer,extractor|
|
15
|
-
extractor.new.extract(buffer){|k,v| dict
|
21
|
+
extractor.new.extract(buffer){|k,v| dict.push(k,v,path)}
|
16
22
|
end
|
17
23
|
write_target_file(f,result) if @target_path
|
18
24
|
end
|
data/lib/locale_dictionary.rb
CHANGED
@@ -4,12 +4,28 @@ module ReadyForI18N
|
|
4
4
|
@locale = locale || 'en'
|
5
5
|
@hash = {}
|
6
6
|
end
|
7
|
-
def
|
8
|
-
|
7
|
+
def push(key,value,path = nil)
|
8
|
+
h = @hash
|
9
|
+
path.each{|p| h[p] ||= {}; h = h[p] } if path
|
10
|
+
h[key] = value
|
9
11
|
end
|
10
12
|
def write_to(out)
|
11
13
|
out.puts "#{@locale}:"
|
12
|
-
|
14
|
+
write_out_hash(out,@hash,1)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def write_out_hash(out,hash,intent)
|
19
|
+
hash.keys.sort{|a,b|a.to_s<=>b.to_s}.each do |k|
|
20
|
+
key_with_indent = "#{' '*intent}#{k}:"
|
21
|
+
val = hash[k]
|
22
|
+
if (val.is_a? Hash)
|
23
|
+
out.puts(key_with_indent)
|
24
|
+
write_out_hash(out, val, intent + 1)
|
25
|
+
else
|
26
|
+
out.puts("#{key_with_indent} #{val.dump}" )
|
27
|
+
end
|
28
|
+
end
|
13
29
|
end
|
14
30
|
end
|
15
31
|
end
|
data/lib/ready_for_i18n.rb
CHANGED
data/ready_for_i18n.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ready_for_i18n}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["zigzag"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-25}
|
13
13
|
s.default_executable = %q{ready_for_i18n}
|
14
14
|
s.description = %q{ ready_for_i18n will help you extract visible hard-coded text from your ERB view files,
|
15
15
|
then choose a proper key and replace them with the I18n.translate method like t(:login)
|
@@ -18,18 +18,18 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = ["ready_for_i18n"]
|
19
19
|
s.extra_rdoc_files = [
|
20
20
|
"LICENSE",
|
21
|
-
"README.
|
21
|
+
"README.textile"
|
22
22
|
]
|
23
23
|
s.files = [
|
24
24
|
".document",
|
25
25
|
".gitignore",
|
26
26
|
"LICENSE",
|
27
|
-
"README.
|
27
|
+
"README.textile",
|
28
28
|
"Rakefile",
|
29
29
|
"VERSION",
|
30
30
|
"bin/ready_for_i18n",
|
31
|
-
"lib/base_extractor.rb",
|
32
31
|
"lib/erb_helper_extractor.rb",
|
32
|
+
"lib/extractor_base.rb",
|
33
33
|
"lib/html_attr_extractor.rb",
|
34
34
|
"lib/html_text_extractor.rb",
|
35
35
|
"lib/i18n_generator.rb",
|
@@ -42,8 +42,8 @@ Gem::Specification.new do |s|
|
|
42
42
|
"test/output/en.yml",
|
43
43
|
"test/output/label.html.erb",
|
44
44
|
"test/output/text.html.erb",
|
45
|
-
"test/test_base_extractor.rb",
|
46
45
|
"test/test_erb_helper_extractor.rb",
|
46
|
+
"test/test_extractor_base.rb",
|
47
47
|
"test/test_html_attr_extractor.rb",
|
48
48
|
"test/test_html_text_extractor.rb",
|
49
49
|
"test/test_locale_dictionary.rb"
|
@@ -55,8 +55,8 @@ Gem::Specification.new do |s|
|
|
55
55
|
s.summary = %q{ready_for_i18n is a tool helping for the very first step of transfering your local Rails project to an i18n one.}
|
56
56
|
s.test_files = [
|
57
57
|
"test/helper.rb",
|
58
|
-
"test/test_base_extractor.rb",
|
59
58
|
"test/test_erb_helper_extractor.rb",
|
59
|
+
"test/test_extractor_base.rb",
|
60
60
|
"test/test_html_attr_extractor.rb",
|
61
61
|
"test/test_html_text_extractor.rb",
|
62
62
|
"test/test_locale_dictionary.rb"
|
@@ -1,3 +1,6 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
1
4
|
<table width="100%">
|
2
5
|
<tr>
|
3
6
|
<td valign="top">
|
@@ -78,6 +81,8 @@
|
|
78
81
|
</tr>
|
79
82
|
</table>
|
80
83
|
|
84
|
+
<button id="select_right_all" onclick="SelectBox.move_all('from', 'to');return false;">select all »</button><br><br>
|
85
|
+
|
81
86
|
<%= link_to "export",
|
82
87
|
url_for(:controller => 'api/rules', :action => 'index', :language => @profile.language, :profile => @profile.name,
|
83
88
|
:plugins => @plugins.join(','),
|
@@ -87,3 +92,4 @@
|
|
87
92
|
|
88
93
|
<%= link_to_remote 'Add Event', {:url => { :controller => 'events', :action => "new", :rid => params['rid'] },
|
89
94
|
:update => "event_form"}, {:class => 'action'} %>
|
95
|
+
|
data/test/output/label.html.erb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
1
4
|
<table width="100%">
|
2
5
|
<tr>
|
3
6
|
<td valign="top">
|
@@ -78,6 +81,8 @@
|
|
78
81
|
</tr>
|
79
82
|
</table>
|
80
83
|
|
84
|
+
<button id="select_right_all" onclick="SelectBox.move_all('from', 'to');return false;">select all »</button><br><br>
|
85
|
+
|
81
86
|
<%= link_to t(:label_export),
|
82
87
|
url_for(:controller => 'api/rules', :action => 'index', :language => @profile.language, :profile => @profile.name,
|
83
88
|
:plugins => @plugins.join(','),
|
@@ -87,3 +92,4 @@
|
|
87
92
|
|
88
93
|
<%= link_to_remote t(:label_add_event), {:url => { :controller => 'events', :action => "new", :rid => params['rid'] },
|
89
94
|
:update => "event_form"}, {:class => 'action'} %>
|
95
|
+
|
@@ -18,6 +18,7 @@ class TestErbHelperExtractor < Test::Unit::TestCase
|
|
18
18
|
expected = %w{edit delete select export cancel add_event}
|
19
19
|
expected.each do |e|
|
20
20
|
assert(File.read(target).include?("t(:label_#{e})"), "should found t method with symbol")
|
21
|
+
assert(!File.read(target).include?("<%=t(:label_#{e})%>"), "should Not found t method wrapped.")
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestExtractorBase < Test::Unit::TestCase
|
4
|
+
should "find a proper key for a given text/label" do
|
5
|
+
c = Object.new
|
6
|
+
def c.key_prefix; nil;end
|
7
|
+
def c.to_value(s); s ;end
|
8
|
+
c.extend ReadyForI18N::ExtractorBase
|
9
|
+
assert_equal('confirm_password', c.to_key('Confirm password:'))
|
10
|
+
end
|
11
|
+
|
12
|
+
should "work fine with prefix" do
|
13
|
+
c = Object.new
|
14
|
+
def c.key_prefix; 'label' ;end
|
15
|
+
def c.to_value(s); s ;end
|
16
|
+
c.extend ReadyForI18N::ExtractorBase
|
17
|
+
assert_equal('label_login', c.to_key('Login:'))
|
18
|
+
end
|
19
|
+
|
20
|
+
should "t_method should use symbol when no use dot" do
|
21
|
+
ReadyForI18N::ExtractorBase.use_dot(false)
|
22
|
+
c = Object.new
|
23
|
+
def c.key_prefix; 'label' ;end
|
24
|
+
def c.to_value(s); s ;end
|
25
|
+
c.extend ReadyForI18N::ExtractorBase
|
26
|
+
assert_equal("t(:label_login)", c.t_method('Login:'))
|
27
|
+
assert_equal("<%=t(:label_login)%>", c.t_method('Login:',true))
|
28
|
+
end
|
29
|
+
|
30
|
+
should "t_method should start with a dot when use dot" do
|
31
|
+
ReadyForI18N::ExtractorBase.use_dot(true)
|
32
|
+
c = Object.new
|
33
|
+
def c.key_prefix; 'label' ;end
|
34
|
+
def c.to_value(s); s ;end
|
35
|
+
c.extend ReadyForI18N::ExtractorBase
|
36
|
+
assert_equal("t('.label_login')", c.t_method('Login:'))
|
37
|
+
assert_equal("<%=t('.label_login')%>", c.t_method('Login:',true))
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -3,7 +3,7 @@ require 'helper'
|
|
3
3
|
class TestHtmlTextExtractor < Test::Unit::TestCase
|
4
4
|
should "extract the text that need i18n from the erb view file" do
|
5
5
|
f = File.join(File.dirname(__FILE__),'fixtures','index.html.erb')
|
6
|
-
expected = %w{Users Login Name Groups Operations Login: Name: Password: Export} << 'Confirm password:'
|
6
|
+
expected = %w{Users Login Name Groups Operations Login: Name: Password: Export} << 'Confirm password:' << 'select all »'
|
7
7
|
result = []
|
8
8
|
ReadyForI18N::HtmlTextExtractor.new.extract(File.read(f)){|k,v| result << v}
|
9
9
|
assert_same_elements(expected,result)
|
@@ -17,4 +17,13 @@ class TestHtmlTextExtractor < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
should "replace the text only needed" do
|
21
|
+
input = "<span id='Replace Me'>Replace Me</span>"
|
22
|
+
output = ReadyForI18N::HtmlTextExtractor.new.extract input
|
23
|
+
assert_equal("<span id='Replace Me'><%=t(:text_replace_me)%></span>", output)
|
24
|
+
|
25
|
+
input = "<span id='Replace Me'>Replace Me"
|
26
|
+
output = ReadyForI18N::HtmlTextExtractor.new.extract input
|
27
|
+
assert_equal("<span id='Replace Me'><%=t(:text_replace_me)%>", output)
|
28
|
+
end
|
20
29
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'stringio'
|
2
3
|
|
3
4
|
class TestLocaleDictionary < Test::Unit::TestCase
|
4
5
|
should "save the result hash to yaml file" do
|
5
6
|
locale_file = File.join(File.dirname(__FILE__),'output','en.yml')
|
6
7
|
|
7
8
|
dict = ReadyForI18N::LocaleDictionary.new
|
8
|
-
dict
|
9
|
-
dict
|
10
|
-
dict
|
11
|
-
dict
|
9
|
+
dict.push 'login_key','Login:'
|
10
|
+
dict.push 'label','OK'
|
11
|
+
dict.push 'text','Please Confirm:'
|
12
|
+
dict.push 'with_quote','It is my "Label"'
|
12
13
|
File.open(locale_file,'w+') {|f| dict.write_to f}
|
13
14
|
|
14
15
|
result = YAML.load_file locale_file
|
@@ -18,8 +19,18 @@ class TestLocaleDictionary < Test::Unit::TestCase
|
|
18
19
|
|
19
20
|
should "output to STDOUT when write to is nil" do
|
20
21
|
dict = ReadyForI18N::LocaleDictionary.new
|
21
|
-
dict
|
22
|
-
|
22
|
+
dict.push 'label','OK'
|
23
|
+
out = StringIO.new
|
24
|
+
dict.write_to out
|
25
|
+
assert_equal("en:\n label: \"OK\"\n", out.string)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "should intent output when path is given" do
|
29
|
+
dict = ReadyForI18N::LocaleDictionary.new
|
30
|
+
dict.push 'label','OK',['my_view']
|
31
|
+
out = StringIO.new
|
32
|
+
dict.write_to out
|
33
|
+
assert_equal("en:\n my_view:\n label: \"OK\"\n", out.string)
|
23
34
|
end
|
24
35
|
|
25
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ready_for_i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zigzag
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-25 00:00:00 +08:00
|
13
13
|
default_executable: ready_for_i18n
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,17 +30,17 @@ extensions: []
|
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
32
32
|
- LICENSE
|
33
|
-
- README.
|
33
|
+
- README.textile
|
34
34
|
files:
|
35
35
|
- .document
|
36
36
|
- .gitignore
|
37
37
|
- LICENSE
|
38
|
-
- README.
|
38
|
+
- README.textile
|
39
39
|
- Rakefile
|
40
40
|
- VERSION
|
41
41
|
- bin/ready_for_i18n
|
42
|
-
- lib/base_extractor.rb
|
43
42
|
- lib/erb_helper_extractor.rb
|
43
|
+
- lib/extractor_base.rb
|
44
44
|
- lib/html_attr_extractor.rb
|
45
45
|
- lib/html_text_extractor.rb
|
46
46
|
- lib/i18n_generator.rb
|
@@ -53,8 +53,8 @@ files:
|
|
53
53
|
- test/output/en.yml
|
54
54
|
- test/output/label.html.erb
|
55
55
|
- test/output/text.html.erb
|
56
|
-
- test/test_base_extractor.rb
|
57
56
|
- test/test_erb_helper_extractor.rb
|
57
|
+
- test/test_extractor_base.rb
|
58
58
|
- test/test_html_attr_extractor.rb
|
59
59
|
- test/test_html_text_extractor.rb
|
60
60
|
- test/test_locale_dictionary.rb
|
@@ -88,8 +88,8 @@ specification_version: 3
|
|
88
88
|
summary: ready_for_i18n is a tool helping for the very first step of transfering your local Rails project to an i18n one.
|
89
89
|
test_files:
|
90
90
|
- test/helper.rb
|
91
|
-
- test/test_base_extractor.rb
|
92
91
|
- test/test_erb_helper_extractor.rb
|
92
|
+
- test/test_extractor_base.rb
|
93
93
|
- test/test_html_attr_extractor.rb
|
94
94
|
- test/test_html_text_extractor.rb
|
95
95
|
- test/test_locale_dictionary.rb
|
data/README.rdoc
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
= ready_for_i18n
|
2
|
-
|
3
|
-
Ready_for_i18n is handy tool helping you in the first step of getting your local Rails project ready for I18N.
|
4
|
-
|
5
|
-
It will automatically extract hard-coded text from your ERB view file,
|
6
|
-
then choose a proper key and replace them with the I18n.translate method.
|
7
|
-
|
8
|
-
Currently three extractors are available:
|
9
|
-
|
10
|
-
* HtmlTextExtractor will scan all HTML text nodes in you view files, like <b>Hello</b> then replace it with <b><%=t(:text_hello)%></b>.
|
11
|
-
* HtmlAttrExtractor will scan all visible HTML attribute in you view files, like <input type="submit" value="Back"> then replace it with <input type="submit" value="<%=t(:label_back)">.
|
12
|
-
* ErbHelperExtractor will scan all the text in helper methods like link_to('Login'...) and replace with link_to (t(:login)).
|
13
|
-
|
14
|
-
Introduction Blog at: http://zigzag.github.com/2009/12/17/get-your-local-rails-application-ready-for-i18n.html
|
15
|
-
|
16
|
-
== Installation:
|
17
|
-
gem install ready_for_i18n
|
18
|
-
|
19
|
-
Hosed at http://www.gemcutter.org/gems/ready_for_i18n
|
20
|
-
|
21
|
-
== Basic Command Line Usage:
|
22
|
-
ready_for_i18n <path to ERB source files> [target path]
|
23
|
-
|
24
|
-
Your erb files in source path will be transformed(i18n_ready) and copy to target file path.
|
25
|
-
If target path is missing, then ready_for_i18n will do a Dry run and only generated the locale file.
|
26
|
-
|
27
|
-
A locale file will be output to STDOUT,which you can redirect to file like
|
28
|
-
ready_for_i18n <path to ERB source files> [target path] > /temp/en.yml
|
29
|
-
|
30
|
-
Using the following options:
|
31
|
-
--locale [LOCALE] Generating for the specified locale (default locale 'en')
|
32
|
-
--ext [EXTENSION] The file extension name of your views(default '.html.erb')
|
33
|
-
|
34
|
-
== Warning
|
35
|
-
* This tool is used based on the most "conventional" way of HTML and ERB. But I can not guarantee all the text will be extracted correctly.Create an issue in this github project page if you found some thing miss.
|
36
|
-
|
37
|
-
* Only tested when the local language is English. Other languages support is in the TODO list.
|
38
|
-
|
39
|
-
== Note on Patches/Pull Requests
|
40
|
-
|
41
|
-
* Fork the project.
|
42
|
-
* Make your feature addition or bug fix.
|
43
|
-
* Add tests for it. This is important so I don't break it in a
|
44
|
-
future version unintentionally.
|
45
|
-
* Commit, do not mess with rakefile, version, or history.
|
46
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
47
|
-
* Send me a pull request. Bonus points for topic branches.
|
48
|
-
|
49
|
-
== Copyright
|
50
|
-
|
51
|
-
Copyright (c) 2009 zigzag. See LICENSE for details.
|
data/test/test_base_extractor.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestBaseExtractor < Test::Unit::TestCase
|
4
|
-
should "find a proper key for a given text/label" do
|
5
|
-
c = Object.new
|
6
|
-
def c.key_prefix; nil;end
|
7
|
-
def c.to_value(s); s ;end
|
8
|
-
c.extend ReadyForI18N::BaseExtractor
|
9
|
-
assert_equal('confirm_password', c.to_key('Confirm password:'))
|
10
|
-
end
|
11
|
-
|
12
|
-
should "work fine with prefix" do
|
13
|
-
c = Object.new
|
14
|
-
def c.key_prefix; 'label' ;end
|
15
|
-
def c.to_value(s); s ;end
|
16
|
-
c.extend ReadyForI18N::BaseExtractor
|
17
|
-
assert_equal('label_login', c.to_key('Login:'))
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|