ready_for_i18n 0.2.4 → 0.2.6
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 +1 -1
- data/lib/base_extractor.rb +5 -1
- data/lib/label_extractor.rb +1 -1
- data/lib/locale_dictionary.rb +1 -1
- data/ready_for_i18n.gemspec +2 -2
- data/test/output/en.yml +1 -0
- data/test/test_locale_dictionary.rb +2 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/lib/base_extractor.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module ReadyForI18N
|
2
2
|
module BaseExtractor
|
3
|
+
VALUE_PATTERN = /\w+/
|
3
4
|
def initialize(erb_source, erb_target = nil)
|
4
5
|
@erb_source = erb_source
|
5
6
|
@erb_target = erb_target
|
@@ -10,7 +11,7 @@ module ReadyForI18N
|
|
10
11
|
File.open(@erb_source).each do |line|
|
11
12
|
unless skip_line?(line)
|
12
13
|
values_in_line(line).each do |e|
|
13
|
-
if
|
14
|
+
if can_replace?(e)
|
14
15
|
yield(to_key(e),to_value(e)) if block_given?
|
15
16
|
replace_line(line,e)
|
16
17
|
end
|
@@ -24,5 +25,8 @@ module ReadyForI18N
|
|
24
25
|
result = to_value(s).scan(/\w+/).join('_').downcase
|
25
26
|
key_prefix ? "#{key_prefix}_#{result}" : result
|
26
27
|
end
|
28
|
+
def can_replace?(e)
|
29
|
+
e.scan(VALUE_PATTERN).length > 0
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
data/lib/label_extractor.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module ReadyForI18N
|
2
2
|
class LabelExtractor
|
3
|
-
LABEL_IN_HELPER_PATTERN = %w{label_tag link_to field_set_tag}.map{|h| /#{h}[\s\w_]*('|")([\w ]*)(\1)/ }
|
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
5
|
include ReadyForI18N::BaseExtractor
|
6
6
|
|
data/lib/locale_dictionary.rb
CHANGED
@@ -12,7 +12,7 @@ module ReadyForI18N
|
|
12
12
|
file = File.join(path,"#{@locale}.yml")
|
13
13
|
File.open(file,'w+') do |f|
|
14
14
|
f.puts "#{@locale}:"
|
15
|
-
@hash.keys.sort{|a,b|a.to_s<=>b.to_s}.each { |k| f.puts " #{k}:
|
15
|
+
@hash.keys.sort{|a,b|a.to_s<=>b.to_s}.each { |k| f.puts " #{k}: #{@hash[k].dump}" }
|
16
16
|
end
|
17
17
|
file
|
18
18
|
end
|
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.6"
|
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-17}
|
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)
|
data/test/output/en.yml
CHANGED
@@ -7,10 +7,12 @@ class TestLocaleDictionary < Test::Unit::TestCase
|
|
7
7
|
dict['login_key'] = 'Login:'
|
8
8
|
dict['label'] = 'OK'
|
9
9
|
dict['text'] = 'Please Confirm:'
|
10
|
+
dict['with_quote'] = 'It is my "Label"'
|
10
11
|
dict.write_to target_path
|
11
12
|
|
12
13
|
result = YAML.load_file File.join(target_path,'en.yml')
|
13
14
|
assert_equal('Login:', result['en']['login_key'])
|
15
|
+
assert_equal("It is my \"Label\"", result['en']['with_quote'])
|
14
16
|
end
|
15
17
|
|
16
18
|
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.6
|
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-17 00:00:00 +08:00
|
13
13
|
default_executable: ready_for_i18n
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|