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,72 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class TranslateTest < Test::Unit::TestCase
|
4
|
+
include I18nTestCaseHelper
|
5
|
+
|
6
|
+
def test_wrappers
|
7
|
+
key = "[1]Hello[/1] [2]World[/2]"
|
8
|
+
translation = "[1]Hallo[/1] [2]die Welt[/2]"
|
9
|
+
add_translation(key, translation)
|
10
|
+
wrappers = []
|
11
|
+
wrappers[0] = '<div i18n_wrapper="1"></div>'
|
12
|
+
wrappers[1] = '<b i18n_wrapper="1"></b>'
|
13
|
+
wrappers[2] = '<i i18n_wrapper="1"><sub></sub></i>'
|
14
|
+
variables = []
|
15
|
+
result = '<b>Hallo</b> <i><sub>die Welt</sub></i>'
|
16
|
+
|
17
|
+
assert_equal(result, I18nTemplate::Translation.translate(key, wrappers, variables))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_variables
|
21
|
+
key = "Hello {user}, {message}."
|
22
|
+
translation = "{message}. Hallo {user}"
|
23
|
+
add_translation(key, translation)
|
24
|
+
|
25
|
+
wrappers = []
|
26
|
+
variables = {
|
27
|
+
'user' => 'Jack',
|
28
|
+
'message' => 'Nice day today'
|
29
|
+
}
|
30
|
+
result = 'Nice day today. Hallo Jack'
|
31
|
+
|
32
|
+
assert_equal(result, I18nTemplate::Translation.translate(key, wrappers, variables))
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def test_translation_wo_brackets
|
37
|
+
key = "[1]Hello[/1] [2]World[/2]"
|
38
|
+
translation = "Hallo die Welt"
|
39
|
+
add_translation(key, translation)
|
40
|
+
wrappers = []
|
41
|
+
wrappers[0] = '<div i18n_wrapper="1"></div>'
|
42
|
+
wrappers[1] = '<b i18n_wrapper="1"></b>'
|
43
|
+
wrappers[2] = '<i i18n_wrapper="1"><sub></sub></i>'
|
44
|
+
variables = []
|
45
|
+
result = 'Hallo die Welt'
|
46
|
+
|
47
|
+
assert_equal(result, I18nTemplate::Translation.translate(key, wrappers, variables))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_translation_wo_braces
|
51
|
+
key = "Hello {user}, {message}."
|
52
|
+
translation = "message. Hallo user"
|
53
|
+
add_translation(key, translation)
|
54
|
+
|
55
|
+
wrappers = []
|
56
|
+
variables = {
|
57
|
+
'user' => 'Jack',
|
58
|
+
'message' => 'Nice day today'
|
59
|
+
}
|
60
|
+
result = 'message. Hallo user'
|
61
|
+
|
62
|
+
assert_equal(result, I18nTemplate::Translation.translate(key, wrappers, variables))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_replace_nl_with_br
|
66
|
+
key = "Introduction.[nl]Hello!"
|
67
|
+
result = "~Introduction.<br />Hello!"
|
68
|
+
|
69
|
+
assert_equal(result, I18nTemplate::Translation.translate(key, [], {}))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n_template
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nikolai Lugovoi
|
9
|
+
- Yaroslav Lazor
|
10
|
+
- Andriy Yanko
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2011-11-30 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: actionpack
|
18
|
+
requirement: &13120880 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.0
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *13120880
|
27
|
+
description: ! '
|
28
|
+
|
29
|
+
I18nTemplate is made to extract phrases and translate templates.
|
30
|
+
|
31
|
+
Currently I18nTemplate can work with (x)html documents.
|
32
|
+
|
33
|
+
Translation is done by modify the original template (on the fly) to be translated
|
34
|
+
on erb execution time.
|
35
|
+
|
36
|
+
'
|
37
|
+
email:
|
38
|
+
- andriy.yanko@gmail.com
|
39
|
+
executables:
|
40
|
+
- i18n_template
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile.rails23_r187
|
46
|
+
- Gemfile.rails30_r193
|
47
|
+
- Gemfile.rails31_r193
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- bin/i18n_template
|
51
|
+
- i18n_template.gemspec
|
52
|
+
- lib/i18n_template.rb
|
53
|
+
- lib/i18n_template/document.rb
|
54
|
+
- lib/i18n_template/extractor.rb
|
55
|
+
- lib/i18n_template/extractor/base.rb
|
56
|
+
- lib/i18n_template/extractor/gettext.rb
|
57
|
+
- lib/i18n_template/extractor/plain.rb
|
58
|
+
- lib/i18n_template/extractor/yaml.rb
|
59
|
+
- lib/i18n_template/handler.rb
|
60
|
+
- lib/i18n_template/node.rb
|
61
|
+
- lib/i18n_template/railtie.rb
|
62
|
+
- lib/i18n_template/runner.rb
|
63
|
+
- lib/i18n_template/runner/base.rb
|
64
|
+
- lib/i18n_template/runner/extract_phrases.rb
|
65
|
+
- lib/i18n_template/tasks.rb
|
66
|
+
- lib/i18n_template/translation.rb
|
67
|
+
- lib/i18n_template/translator.rb
|
68
|
+
- lib/i18n_template/translator/i18n.rb
|
69
|
+
- lib/i18n_template/version.rb
|
70
|
+
- test/abstract_unit.rb
|
71
|
+
- test/document_test.rb
|
72
|
+
- test/fixtures/handling_if_blocks.yml
|
73
|
+
- test/fixtures/ignored_markup.yml
|
74
|
+
- test/fixtures/incorrect_node_markup.yml
|
75
|
+
- test/fixtures/nested_nodes.yml
|
76
|
+
- test/fixtures/nested_wrapped_text.yml
|
77
|
+
- test/fixtures/phrase_fully_ignored.yml
|
78
|
+
- test/fixtures/phrase_with_embed_words_and_scriptlet.yml
|
79
|
+
- test/fixtures/phrase_with_single_char_to_ignore.yml
|
80
|
+
- test/fixtures/replacing_br_with_newline.yml
|
81
|
+
- test/fixtures/skipping_ignored_blocks.yml
|
82
|
+
- test/fixtures/spans_as_phrases.yml
|
83
|
+
- test/fixtures/table.yml
|
84
|
+
- test/fixtures/text_with_braces.yml
|
85
|
+
- test/fixtures/text_with_brackets.yml
|
86
|
+
- test/fixtures/wrapped_key_propagation.yml
|
87
|
+
- test/fixtures/wrapping_eval_blocks.yml
|
88
|
+
- test/fixtures_rendering_test.rb
|
89
|
+
- test/inline_rendering_test.rb
|
90
|
+
- test/support/i18n_test_case_helper.rb
|
91
|
+
- test/templates/_footer.html.erb
|
92
|
+
- test/templates/greeting.html.erb
|
93
|
+
- test/templates/layouts/application.html.erb
|
94
|
+
- test/templates/users/_account.html.erb
|
95
|
+
- test/templates/users/_profile.html.erb
|
96
|
+
- test/templates/users/index.html.erb
|
97
|
+
- test/templates/users/show.html.erb
|
98
|
+
- test/templates_rendering_test.rb
|
99
|
+
- test/translate_test.rb
|
100
|
+
homepage: https://github.com/railsware/i18n_template
|
101
|
+
licenses: []
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project: i18n_template
|
120
|
+
rubygems_version: 1.8.10
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: I18nTemplate is made to extract phrases from html/xhtml/xml documents and
|
124
|
+
translate them on the fly
|
125
|
+
test_files:
|
126
|
+
- test/abstract_unit.rb
|
127
|
+
- test/document_test.rb
|
128
|
+
- test/fixtures/handling_if_blocks.yml
|
129
|
+
- test/fixtures/ignored_markup.yml
|
130
|
+
- test/fixtures/incorrect_node_markup.yml
|
131
|
+
- test/fixtures/nested_nodes.yml
|
132
|
+
- test/fixtures/nested_wrapped_text.yml
|
133
|
+
- test/fixtures/phrase_fully_ignored.yml
|
134
|
+
- test/fixtures/phrase_with_embed_words_and_scriptlet.yml
|
135
|
+
- test/fixtures/phrase_with_single_char_to_ignore.yml
|
136
|
+
- test/fixtures/replacing_br_with_newline.yml
|
137
|
+
- test/fixtures/skipping_ignored_blocks.yml
|
138
|
+
- test/fixtures/spans_as_phrases.yml
|
139
|
+
- test/fixtures/table.yml
|
140
|
+
- test/fixtures/text_with_braces.yml
|
141
|
+
- test/fixtures/text_with_brackets.yml
|
142
|
+
- test/fixtures/wrapped_key_propagation.yml
|
143
|
+
- test/fixtures/wrapping_eval_blocks.yml
|
144
|
+
- test/fixtures_rendering_test.rb
|
145
|
+
- test/inline_rendering_test.rb
|
146
|
+
- test/support/i18n_test_case_helper.rb
|
147
|
+
- test/templates/_footer.html.erb
|
148
|
+
- test/templates/greeting.html.erb
|
149
|
+
- test/templates/layouts/application.html.erb
|
150
|
+
- test/templates/users/_account.html.erb
|
151
|
+
- test/templates/users/_profile.html.erb
|
152
|
+
- test/templates/users/index.html.erb
|
153
|
+
- test/templates/users/show.html.erb
|
154
|
+
- test/templates_rendering_test.rb
|
155
|
+
- test/translate_test.rb
|
156
|
+
has_rdoc:
|