i18n_template 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile.rails23_r187 +8 -0
- data/Gemfile.rails30_r193 +8 -0
- data/Gemfile.rails31_r193 +8 -0
- data/README.md +250 -0
- data/Rakefile +1 -0
- data/bin/i18n_template +5 -0
- data/i18n_template.gemspec +26 -0
- data/lib/i18n_template.rb +28 -0
- data/lib/i18n_template/document.rb +460 -0
- data/lib/i18n_template/extractor.rb +4 -0
- data/lib/i18n_template/extractor/base.rb +44 -0
- data/lib/i18n_template/extractor/gettext.rb +127 -0
- data/lib/i18n_template/extractor/plain.rb +43 -0
- data/lib/i18n_template/extractor/yaml.rb +53 -0
- data/lib/i18n_template/handler.rb +61 -0
- data/lib/i18n_template/node.rb +74 -0
- data/lib/i18n_template/railtie.rb +7 -0
- data/lib/i18n_template/runner.rb +61 -0
- data/lib/i18n_template/runner/base.rb +11 -0
- data/lib/i18n_template/runner/extract_phrases.rb +70 -0
- data/lib/i18n_template/tasks.rb +2 -0
- data/lib/i18n_template/translation.rb +62 -0
- data/lib/i18n_template/translator.rb +5 -0
- data/lib/i18n_template/translator/i18n.rb +24 -0
- data/lib/i18n_template/version.rb +3 -0
- data/test/abstract_unit.rb +11 -0
- data/test/document_test.rb +316 -0
- data/test/fixtures/handling_if_blocks.yml +23 -0
- data/test/fixtures/ignored_markup.yml +15 -0
- data/test/fixtures/incorrect_node_markup.yml +17 -0
- data/test/fixtures/nested_nodes.yml +16 -0
- data/test/fixtures/nested_wrapped_text.yml +15 -0
- data/test/fixtures/phrase_fully_ignored.yml +14 -0
- data/test/fixtures/phrase_with_embed_words_and_scriptlet.yml +17 -0
- data/test/fixtures/phrase_with_single_char_to_ignore.yml +19 -0
- data/test/fixtures/replacing_br_with_newline.yml +15 -0
- data/test/fixtures/skipping_ignored_blocks.yml +15 -0
- data/test/fixtures/spans_as_phrases.yml +18 -0
- data/test/fixtures/table.yml +35 -0
- data/test/fixtures/text_with_braces.yml +17 -0
- data/test/fixtures/text_with_brackets.yml +17 -0
- data/test/fixtures/wrapped_key_propagation.yml +15 -0
- data/test/fixtures/wrapping_eval_blocks.yml +17 -0
- data/test/fixtures_rendering_test.rb +46 -0
- data/test/inline_rendering_test.rb +27 -0
- data/test/support/i18n_test_case_helper.rb +12 -0
- data/test/templates/_footer.html.erb +3 -0
- data/test/templates/greeting.html.erb +1 -0
- data/test/templates/layouts/application.html.erb +5 -0
- data/test/templates/users/_account.html.erb +3 -0
- data/test/templates/users/_profile.html.erb +6 -0
- data/test/templates/users/index.html.erb +5 -0
- data/test/templates/users/show.html.erb +4 -0
- data/test/templates_rendering_test.rb +81 -0
- data/test/translate_test.rb +72 -0
- metadata +156 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
template: |
|
2
|
+
<div>
|
3
|
+
<%- if total_price -%>
|
4
|
+
<div>Total price: <span><%= total_price %></span></div>
|
5
|
+
<%- else -%>
|
6
|
+
<div>Total price: N/A</div>
|
7
|
+
<%- end -%>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
assigns: {}
|
11
|
+
|
12
|
+
locals:
|
13
|
+
:total_price:
|
14
|
+
|
15
|
+
phrases:
|
16
|
+
- 'Total price: [1]{total price}[/1]'
|
17
|
+
- 'Total price: N/A'
|
18
|
+
|
19
|
+
translations:
|
20
|
+
- 'Игого: [1]{total price}[/1]'
|
21
|
+
- 'Игого: ХЗ'
|
22
|
+
|
23
|
+
rendered: "<div>\n <div>Игого: ХЗ</div>\n</div>\n"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
template: |
|
2
|
+
<div><span><span i18n="p">Welcome!</span></span> <span i18n="i">We are glad to meet you here</span></div>
|
3
|
+
|
4
|
+
assigns: {}
|
5
|
+
|
6
|
+
locals: {}
|
7
|
+
|
8
|
+
phrases:
|
9
|
+
- 'Welcome!'
|
10
|
+
|
11
|
+
translations:
|
12
|
+
- 'Бобро пожаловаться!'
|
13
|
+
|
14
|
+
rendered: |
|
15
|
+
<div><span><span>Бобро пожаловаться!</span></span> <span>We are glad to meet you here</span></div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
template: |
|
2
|
+
<div id="level1">Hello, <%= user_name %>! <div id="level2">Welcome to our site</div></div>
|
3
|
+
|
4
|
+
assigns: {}
|
5
|
+
|
6
|
+
locals:
|
7
|
+
:user_name: joe@site.com
|
8
|
+
|
9
|
+
phrases:
|
10
|
+
- 'Hello, {user name}! [1]Welcome to our site[/1]'
|
11
|
+
- 'Welcome to our site'
|
12
|
+
|
13
|
+
translations:
|
14
|
+
- 'Кревед, joe@site.com! [1]Рады видеть вас на вашем сайте[/1]'
|
15
|
+
|
16
|
+
rendered: |
|
17
|
+
<div id="level1">Кревед, joe@site.com! Рады видеть вас на вашем сайте</div>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
template: |
|
2
|
+
<div><span>This is <span>Wrong</span> <%= message %> </span> markup</div>
|
3
|
+
|
4
|
+
assigns: {}
|
5
|
+
|
6
|
+
locals:
|
7
|
+
:message: html
|
8
|
+
|
9
|
+
phrases:
|
10
|
+
- 'NNODE[1]This is {message} [/1] markup'
|
11
|
+
|
12
|
+
translations:
|
13
|
+
- 'NNODE[1]Это {message} [/1] разметка'
|
14
|
+
|
15
|
+
rendered: |
|
16
|
+
<div>NNODE<span><span>Это html </span></span> разметка</div>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
template: |
|
2
|
+
<div><span><span>Welcome!</span></span> We are glad to meet you here</div>
|
3
|
+
|
4
|
+
assigns: {}
|
5
|
+
|
6
|
+
locals: {}
|
7
|
+
|
8
|
+
phrases:
|
9
|
+
- '[1]Welcome![/1] We are glad to meet you here'
|
10
|
+
|
11
|
+
translations:
|
12
|
+
- '[1]Бобро пожаловаться![/1] Век бы вас не видать'
|
13
|
+
|
14
|
+
rendered: |
|
15
|
+
<div><span><span>Бобро пожаловаться!</span></span> Век бы вас не видать</div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
template: |
|
2
|
+
<p>Welcome <em>mister</em> <%= name %> from <%= from %> into <em>the city</em></p>
|
3
|
+
|
4
|
+
assigns: {}
|
5
|
+
|
6
|
+
locals:
|
7
|
+
:name: Vasia Pupkin
|
8
|
+
:from: Gonduras
|
9
|
+
|
10
|
+
phrases:
|
11
|
+
- 'Welcome [1]mister[/1] {name} from {from} into [2]the city[/2]'
|
12
|
+
|
13
|
+
translations:
|
14
|
+
- 'Willkommen [1]Herr[/1] {name} aus {from} in [2]der Stadt[/2]'
|
15
|
+
|
16
|
+
rendered: |
|
17
|
+
<p>Willkommen <em>Herr</em> Vasia Pupkin aus Gonduras in <em>der Stadt</em></p>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
template: |
|
2
|
+
<td class="text">
|
3
|
+
<label for="merchant_address1"><i18n>Address 1</i18n> <span class="rA" i18n="i">*</span></label>
|
4
|
+
</td>
|
5
|
+
|
6
|
+
assigns: {}
|
7
|
+
|
8
|
+
locals: {}
|
9
|
+
|
10
|
+
phrases:
|
11
|
+
- 'Address 1'
|
12
|
+
|
13
|
+
translations:
|
14
|
+
- 'Адрессо одно'
|
15
|
+
|
16
|
+
rendered: |
|
17
|
+
<td class="text">
|
18
|
+
<label for="merchant_address1">Адрессо одно <span class="rA">*</span></label>
|
19
|
+
</td>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
template: |
|
2
|
+
<label for="merchant_address1">Address 1<br/>(required)</label>
|
3
|
+
|
4
|
+
assigns: {}
|
5
|
+
|
6
|
+
locals: {}
|
7
|
+
|
8
|
+
phrases:
|
9
|
+
- 'Address 1[nl](required)'
|
10
|
+
|
11
|
+
translations:
|
12
|
+
- 'Адрессо одно[nl](обязательно)'
|
13
|
+
|
14
|
+
rendered: |
|
15
|
+
<label for="merchant_address1">Адрессо одно<br />(обязательно)</label>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
template: |
|
2
|
+
<div><span><span>Welcome!</span></span></div> <script>alert("Hello!")</script>
|
3
|
+
|
4
|
+
assigns: {}
|
5
|
+
|
6
|
+
locals: {}
|
7
|
+
|
8
|
+
phrases:
|
9
|
+
- 'Welcome!'
|
10
|
+
|
11
|
+
translations:
|
12
|
+
- 'Бобро пожаловаться!'
|
13
|
+
|
14
|
+
rendered: |
|
15
|
+
<div><span><span>Бобро пожаловаться!</span></span></div> <script>alert("Hello!")</script>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
template: |
|
3
|
+
<div><span><span i18n="p">Welcome!</span></span> <span i18n="p">We are glad to meet you here</span></div>
|
4
|
+
|
5
|
+
assigns: {}
|
6
|
+
|
7
|
+
locals: {}
|
8
|
+
|
9
|
+
phrases:
|
10
|
+
- 'Welcome!'
|
11
|
+
- 'We are glad to meet you here'
|
12
|
+
|
13
|
+
translations:
|
14
|
+
- 'Бобро пожаловаться!'
|
15
|
+
- 'Век бы вас не видать'
|
16
|
+
|
17
|
+
rendered: |
|
18
|
+
<div><span><span>Бобро пожаловаться!</span></span> <span>Век бы вас не видать</span></div>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
template: |
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>First Name</th><td><%= first_name %></td>
|
6
|
+
</tr>
|
7
|
+
<tr>
|
8
|
+
<th>Last Name</th><td><%= last_name %></td>
|
9
|
+
</tr>
|
10
|
+
</table>
|
11
|
+
|
12
|
+
assigns: {}
|
13
|
+
|
14
|
+
locals:
|
15
|
+
:first_name: Jack
|
16
|
+
:last_name: Daniels
|
17
|
+
|
18
|
+
phrases:
|
19
|
+
- 'First Name'
|
20
|
+
- 'Last Name'
|
21
|
+
|
22
|
+
translations:
|
23
|
+
- '[1]Name[/1]'
|
24
|
+
- '[1]Nachname[/1]'
|
25
|
+
|
26
|
+
rendered: |
|
27
|
+
<table>
|
28
|
+
<tr>
|
29
|
+
<th>Name</th><td>Jack</td>
|
30
|
+
</tr>
|
31
|
+
<tr>
|
32
|
+
<th>Nachname</th><td>Daniels</td>
|
33
|
+
</tr>
|
34
|
+
</table>
|
35
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
template: |
|
2
|
+
<div>hello #{user}</div>
|
3
|
+
<span i18n="i">today is #{day}</span>
|
4
|
+
|
5
|
+
assigns: {}
|
6
|
+
|
7
|
+
locals: {}
|
8
|
+
|
9
|
+
phrases:
|
10
|
+
- "hello [ns][lcb]user[rcb]"
|
11
|
+
|
12
|
+
translations:
|
13
|
+
- "hallo [ns][lcb]benutzer[rcb]"
|
14
|
+
|
15
|
+
rendered: |
|
16
|
+
<div>hallo #{benutzer}</div>
|
17
|
+
<span>today is #{day}</span>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
template: |
|
2
|
+
<div>hello [1]user[/1]</div>
|
3
|
+
<span i18n="i">today is [1]day[/1]</span>
|
4
|
+
|
5
|
+
assigns: {}
|
6
|
+
|
7
|
+
locals: {}
|
8
|
+
|
9
|
+
phrases:
|
10
|
+
- "hello [lsb]1[rsb]user[lsb]/1[rsb]"
|
11
|
+
|
12
|
+
translations:
|
13
|
+
- "hallo [lsb]1[rsb]benutzer[lsb]/1[rsb]"
|
14
|
+
|
15
|
+
rendered: |
|
16
|
+
<div>hallo [1]benutzer[/1]</div>
|
17
|
+
<span>today is [1]day[/1]</span>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
template: |
|
3
|
+
<div>Total price: <span><%= total_price %></span></div>
|
4
|
+
|
5
|
+
assigns: {}
|
6
|
+
|
7
|
+
locals:
|
8
|
+
:total_price: $10.99
|
9
|
+
|
10
|
+
phrases:
|
11
|
+
- 'Total price: [1]{total price}[/1]'
|
12
|
+
|
13
|
+
translations:
|
14
|
+
- 'Игого: [1]{total price}[/1]'
|
15
|
+
|
16
|
+
rendered: |
|
17
|
+
<div>Игого: <span>$10.99</span></div>
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class FixturesRenderingTest < ActionView::TestCase
|
5
|
+
include I18nTestCaseHelper
|
6
|
+
|
7
|
+
FIXTURES = Dir['test/fixtures/*.yml'].sort.map { |file_name|
|
8
|
+
name = File.basename(file_name, '.yml')
|
9
|
+
begin
|
10
|
+
data = YAML.load_file(file_name)
|
11
|
+
rescue => e
|
12
|
+
puts "Error occurs in fixture: #{file_name}"
|
13
|
+
raise e
|
14
|
+
end
|
15
|
+
[ name, data ]
|
16
|
+
}
|
17
|
+
|
18
|
+
FIXTURES.each do |name, data|
|
19
|
+
define_method("test_#{name}") do
|
20
|
+
%w(template assigns locals phrases translations rendered).each do |key|
|
21
|
+
data[key] or raise ArgumentError, "Please specify '#{key}' key"
|
22
|
+
end
|
23
|
+
|
24
|
+
data['assigns'].each do |key, val|
|
25
|
+
instance_variable_set("@#{key}", val)
|
26
|
+
end
|
27
|
+
|
28
|
+
data['phrases'].size.times do |i|
|
29
|
+
add_translation(data['phrases'][i], data['translations'][i])
|
30
|
+
end
|
31
|
+
|
32
|
+
document = I18nTemplate::Document.new(data['template'])
|
33
|
+
document.preprocess!
|
34
|
+
assert_equal(data['phrases'], document.phrases)
|
35
|
+
|
36
|
+
render({
|
37
|
+
:inline => data['template'],
|
38
|
+
:locals => data['locals'],
|
39
|
+
:type => :erb
|
40
|
+
})
|
41
|
+
|
42
|
+
assert_equal(data['rendered'], rendered)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'abstract_unit'
|
3
|
+
|
4
|
+
class InlineRenderingTest < ActionView::TestCase
|
5
|
+
include I18nTestCaseHelper
|
6
|
+
|
7
|
+
def test_assigns
|
8
|
+
template = '<div>Comments count: <%= @post.comments.count %></div>'
|
9
|
+
|
10
|
+
add_translation 'Comments count: {post comments count}',
|
11
|
+
'Anzahl die Kommentare: {post comments count}'
|
12
|
+
|
13
|
+
@post = Object.new
|
14
|
+
@post.instance_eval do
|
15
|
+
def comments
|
16
|
+
%w(one two three)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
result = '<div>Anzahl die Kommentare: 3</div>'
|
21
|
+
|
22
|
+
render :inline => template, :type => :erb
|
23
|
+
|
24
|
+
assert_equal(result, rendered)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<h2>Hello <%= @user_name %>, <%= message %></h2>
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'abstract_unit'
|
3
|
+
|
4
|
+
class TemplatesRenderingTest < ActionView::TestCase
|
5
|
+
include I18nTestCaseHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
ActionController::Base.view_paths = ['test/templates']
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_partial_rendering_wo_translations
|
12
|
+
@current_year = 2011
|
13
|
+
|
14
|
+
render :partial=> 'footer'
|
15
|
+
|
16
|
+
assert_equal(<<-DATA, rendered)
|
17
|
+
<div>~Copyright 2011. All rights reserved.</div>
|
18
|
+
DATA
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_file_rendering
|
22
|
+
@user_name = 'Jack Daniels'
|
23
|
+
|
24
|
+
add_translation 'Hello {user name}, {message}',
|
25
|
+
'Привет {user name}, {message}'
|
26
|
+
|
27
|
+
render :file => 'greeting', :locals => {
|
28
|
+
:message => "Nice day today!"
|
29
|
+
}
|
30
|
+
|
31
|
+
assert_equal(<<-DATA, rendered)
|
32
|
+
<h2>Привет Jack Daniels, Nice day today!</h2>
|
33
|
+
DATA
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_file_with_layout_rendering
|
37
|
+
@user_names = %w(bob alice)
|
38
|
+
|
39
|
+
render :file => 'users/index', :layout => 'layouts/application'
|
40
|
+
|
41
|
+
assert_equal(<<-DATA, rendered)
|
42
|
+
<html>
|
43
|
+
<body>
|
44
|
+
<ul>
|
45
|
+
<li>bob</li>
|
46
|
+
<li>alice</li>
|
47
|
+
</ul>
|
48
|
+
|
49
|
+
</body>
|
50
|
+
</html>
|
51
|
+
DATA
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_file_with_partials_rendering
|
55
|
+
add_translation '[1]Email[/1]: {account email}',
|
56
|
+
'[1]Мыло[/1]: {account email}'
|
57
|
+
|
58
|
+
add_translation '[1]First name[/1]: {profile first name}',
|
59
|
+
'[1]Имя[/1]: {profile first name}'
|
60
|
+
|
61
|
+
add_translation '[1]Last name[/1]: {profile last name}',
|
62
|
+
'[1]Фамилия[/1]: {profile last name}'
|
63
|
+
|
64
|
+
@account = { :email => 'jack@daniels.com' }
|
65
|
+
@profile = { :first_name => 'Jack', :last_name => 'Daniels' }
|
66
|
+
|
67
|
+
render :file => 'users/show'
|
68
|
+
|
69
|
+
assert_equal(<<-DATA, rendered)
|
70
|
+
<div>
|
71
|
+
<div><strong>Мыло</strong>: jack@daniels.com</div>
|
72
|
+
|
73
|
+
<p><strong>Имя</strong>: Jack</p>
|
74
|
+
<p><strong>Фамилия</strong>: Daniels</p>
|
75
|
+
|
76
|
+
</div>
|
77
|
+
DATA
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|