i18n-translators-tools 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
1
+ # -*- coding: utf-8 -*-
2
+ # vi: fenc=utf-8:expandtab:ts=2:sw=2:sts=2
3
+ #
4
+ # @author: Petr Kovar <pejuko@gmail.com>
5
+ #
6
+
7
+ class TestProcessor < Test::Unit::TestCase
8
+
9
+ def test_0010_dont_find_processor
10
+ processor = I18n::Translate::Processor.find_processor("test.abc")
11
+ assert_equal( nil, processor )
12
+ end
13
+
14
+ def test_0010_find_processor_yaml
15
+ # yml
16
+ processor = I18n::Translate::Processor.find_processor("test.yml")
17
+ assert_equal( I18n::Translate::Processor::YAML, processor )
18
+
19
+ # yaml
20
+ processor = I18n::Translate::Processor.find_processor("test.yaml")
21
+ assert_equal( I18n::Translate::Processor::YAML, processor )
22
+ end
23
+
24
+ def test_0010_find_processor_ruby
25
+ processor = I18n::Translate::Processor.find_processor("test.rb")
26
+ assert_equal( I18n::Translate::Processor::Ruby, processor )
27
+ end
28
+
29
+ def test_0010_find_processor_gettext
30
+ # po
31
+ processor = I18n::Translate::Processor.find_processor("test.po")
32
+ assert_equal( I18n::Translate::Processor::Gettext, processor )
33
+
34
+ # pot
35
+ processor = I18n::Translate::Processor.find_processor("test.pot")
36
+ assert_equal( I18n::Translate::Processor::Gettext, processor )
37
+ end
38
+
39
+ def test_0010_find_processor_ts
40
+ processor = I18n::Translate::Processor.find_processor("test.ts")
41
+ assert_equal( I18n::Translate::Processor::TS, processor )
42
+ end
43
+
44
+ def test_0010_find_processor_properties
45
+ processor = I18n::Translate::Processor.find_processor("test.properties")
46
+ assert_equal( I18n::Translate::Processor::Properties, processor )
47
+ end
48
+
49
+ end
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ # vi: fenc=utf-8:expandtab:ts=2:sw=2:sts=2
3
+ #
4
+ # @author: Petr Kovar <pejuko@gmail.com>
5
+ #
6
+
7
+ class TestProcessorGettext < Test::Unit::TestCase
8
+
9
+ def setup
10
+ __prepare(I18n::Translate::Processor::Gettext, "cze.po")
11
+ end
12
+
13
+ include I18n::Test::Processor
14
+
15
+ end
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+ # vi: fenc=utf-8:expandtab:ts=2:sw=2:sts=2
3
+ #
4
+ # @author: Petr Kovar <pejuko@gmail.com>
5
+
6
+
7
+ class TestProcessorProperties < Test::Unit::TestCase
8
+
9
+ def setup
10
+ __prepare(I18n::Translate::Processor::Properties, "cze.properties")
11
+ end
12
+
13
+ include I18n::Test::Processor
14
+
15
+
16
+ def test_0010_read
17
+ data = @src.read
18
+ assert( data.keys.include?('cze') )
19
+ data = data['cze']
20
+ str = "Interpolovaný text '%{var}'"
21
+ #diff(str, data["extended"]["interpolation"])
22
+ assert_equal( str, data["extended"]["interpolation"] )
23
+ end
24
+
25
+ def test_0020_write
26
+ data = @src.read
27
+ @trg.write(data)
28
+ assert( File.exists?(@trg_file) )
29
+ data2 = @trg.read
30
+ diff(data, data2)
31
+ assert_equal(data, data2)
32
+ File.unlink(@trg_file)
33
+ end
34
+
35
+ end
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ # vi: fenc=utf-8:expandtab:ts=2:sw=2:sts=2
3
+ #
4
+ # @author: Petr Kovar <pejuko@gmail.com>
5
+ #
6
+
7
+ class TestProcessorRuby < Test::Unit::TestCase
8
+
9
+ def setup
10
+ __prepare(I18n::Translate::Processor::Ruby, "cze.rb")
11
+ end
12
+
13
+ include I18n::Test::Processor
14
+
15
+ end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ # vi: fenc=utf-8:expandtab:ts=2:sw=2:sts=2
3
+ #
4
+ # @author: Petr Kovar <pejuko@gmail.com>
5
+ #
6
+
7
+ class TestProcessorTS < Test::Unit::TestCase
8
+
9
+ def setup
10
+ __prepare(I18n::Translate::Processor::TS, "cze.ts")
11
+ end
12
+
13
+ include I18n::Test::Processor
14
+
15
+ def test_0030_read_po_to_ts
16
+ t = I18n::Translate::Translate.new('cze', {:locale_dir => $src_dir, :default_format => 'yml', :format => 'yml'})
17
+ file = File.join($src_dir, 'po_to_ts.ts')
18
+ reader = I18n::Translate::Processor::TS.new(file, t)
19
+ data = reader.read
20
+ assert( data.keys.include?('cze') )
21
+ data = data['cze']
22
+ diff($si, data["extended"]["interpolation"])
23
+ assert_equal( $si, data["extended"]["interpolation"] )
24
+ end
25
+
26
+ end
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ # vi: fenc=utf-8:expandtab:ts=2:sw=2:sts=2
3
+ #
4
+ # @author: Petr Kovar <pejuko@gmail.com>
5
+ #
6
+
7
+ class TestProcessorYAML < Test::Unit::TestCase
8
+
9
+ def setup
10
+ __prepare(I18n::Translate::Processor::YAML, "cze.yml")
11
+ end
12
+
13
+ include I18n::Test::Processor
14
+
15
+ end
@@ -3,88 +3,13 @@
3
3
  #
4
4
  # @author: Petr Kovar <pejuko@gmail.com>
5
5
  #
6
- require 'test/unit'
7
- require 'rubygems'
8
- require 'yaml'
9
-
10
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), ".."))
11
- require 'lib/i18n-translate'
12
-
13
-
14
-
15
- $current_dir = File.expand_path(File.dirname(__FILE__))
16
- $src_dir = File.join($current_dir, 'locale/src')
17
- $trg_dir = File.join($current_dir, 'locale/trg')
18
-
19
-
20
- def load_yml(default, cze)
21
- [YAML.load(File.read(default))["default"], YAML.load(File.read(cze))["cze"]]
22
- end
23
-
24
- def load_src
25
- load_yml("#{$src_dir}/default.yml", "#{$src_dir}/cze.yml")
26
- end
27
-
28
- def load_trg
29
- load_yml("#{$trg_dir}/default.yml", "#{$trg_dir}/cze.yml")
30
- end
31
-
32
- def load_src_trg
33
- res = {}
34
- res[:src] = load_src
35
- res[:trg] = load_trg
36
- res
37
- end
38
-
39
-
40
- I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
41
- I18n::Backend::Simple.send(:include, I18n::Backend::Translate)
42
- I18n.default_locale = 'default'
43
- I18n.locale = 'cze'
44
-
45
-
46
- class TestTranslatorPlugin < Test::Unit::TestCase
47
-
48
- def setup
49
- I18n.load_path << Dir[ "#{$src_dir}/*.yml" ]
50
- I18n.reload!
51
- end
52
-
53
- def test_0010_I18n_plugin_simple_text
54
- assert_equal( "Text k přeložení", I18n.t("simple.text") )
55
- end
56
-
57
- def test_0020_I18n_plugin_plural_text
58
- assert_equal( "Jedna položka", I18n.t("simple.plural", :count => 1) )
59
- assert_equal( "Mnoho položek", I18n.t("simple.plural", :count => 9))
60
- end
61
-
62
- def test_0030_I18n_plugin_interpolation
63
- assert_equal( "Interpolovaný text 'ahoj'", I18n.t("simple.interpolation", :var => "ahoj"))
64
- end
65
-
66
- def test_0040_I18n_plugin_translate_simple
67
- assert_equal( "Změněný jednoduchý text", I18n.t("changed.simple"))
68
- end
69
-
70
- def test_0050_I18n_plugin_translate_plural
71
- assert_equal( "Změněný plurál text", I18n.t("changed.plural", :count => 1))
72
- assert_equal( "Změněný plurál textů", I18n.t("changed.plural", :count => 9))
73
- end
74
-
75
- def test_0060_I18n_plugin_translate_interpolation
76
- assert_equal( "Interpolovaný změněný text 'ahoj'", I18n.t("changed.interpolation", :var => "ahoj"))
77
- end
78
-
79
- end
80
-
81
6
 
82
7
  class TestTranslate < Test::Unit::TestCase
83
8
  def setup
84
9
  @opts = {:locale_dir => $src_dir, :format => 'yml', :default_format => 'yml'}
85
10
  @t = I18n::Translate::Translate.new('cze', @opts)
86
11
  @t.options[:locale_dir] = $trg_dir
87
- I18n.load_path << Dir[ "#{$src_dir}/*.yml" ]
12
+ I18n.load_path = Dir[ "#{$src_dir}/*.yml" ]
88
13
  I18n.reload!
89
14
  end
90
15
 
@@ -100,8 +25,8 @@ class TestTranslate < Test::Unit::TestCase
100
25
  def test_0020_merge_simple
101
26
  assert_equal( { "key" => "simple.text",
102
27
  "default" => "Text to translate",
103
- "t" => "Text k přeložení",
104
- "old_t" => "",
28
+ "translation" => "Text k přeložení",
29
+ "old_translation" => "",
105
30
  "old_default" => "",
106
31
  "comment" => "",
107
32
  "flag" => "ok" }, @t["simple.text"] )
@@ -110,8 +35,8 @@ class TestTranslate < Test::Unit::TestCase
110
35
  def test_0030_merge_changed
111
36
  assert_equal( { "key" => "changed.simple",
112
37
  "default" => "This text is newer and changed",
113
- "t" => "",
114
- "old_t" => "Změněný jednoduchý text",
38
+ "translation" => "",
39
+ "old_translation" => "Změněný jednoduchý text",
115
40
  "old_default" => "Changed simple text",
116
41
  "comment" => "",
117
42
  "flag" => "changed" }, @t["changed.simple"] )
@@ -122,18 +47,15 @@ class TestTranslate < Test::Unit::TestCase
122
47
  entry = @t.find("simple.text", @t.target )
123
48
 
124
49
  assert( entry.kind_of?(Hash) )
125
- assert_equal( { "t" => "Text k přeložení",
126
- "old" => "",
50
+ assert_equal( { "translation" => "Text k přeložení",
127
51
  "default" => "Text to translate",
128
- "comment" => "",
129
52
  "flag" => "ok"
130
53
  }, entry )
131
54
 
132
55
  entry = @t.find("changed.simple", @t.target )
133
- assert_equal( { "t" => "Změněný jednoduchý text",
134
- "old" => "Changed simple text",
56
+ assert_equal( { "translation" => "Změněný jednoduchý text",
57
+ "old_default" => "Changed simple text",
135
58
  "default" => "This text is newer and changed",
136
- "comment" => "",
137
59
  "flag" => "changed",
138
60
  "fuzzy" => true
139
61
  }, entry )
@@ -159,7 +81,104 @@ class TestTranslate < Test::Unit::TestCase
159
81
  tpo = I18n::Translate::Translate.new('cze', @opts.merge({:format => 'po'}))
160
82
  assert(tpo.kind_of?(I18n::Translate::Translate))
161
83
  assert_equal(File.join(File.expand_path($src_dir), 'cze.po'), tpo.lang_file)
162
- assert_equal(["changed.interpolation.default", "changed.interpolation.t", "changed.plural.one.default", "changed.plural.one.t", "changed.plural.other.default", "changed.plural.other.t", "changed.simple.default", "changed.simple.t", "simple.interpolation.default", "simple.interpolation.t", "simple.plural.one.default", "simple.plural.one.t", "simple.plural.other.default", "simple.plural.other.t", "simple.text.default", "simple.text.t"], I18n::Translate.hash_to_keys(tpo.target, ".").sort)
84
+ assert_equal(@t.target.keys.sort, tpo.target.keys.sort)
85
+ assert_equal($si, tpo.target["extended"]["interpolation"])
86
+ end
87
+
88
+ def test_0080_convert
89
+ t = I18n::Translate::Translate.new('cze', @opts.merge({:format => 'yml'}))
90
+ t.options[:locale_dir] = $trg_dir
91
+ t.options[:format] = 'po'
92
+ t.export!
93
+ trg_file = File.join($trg_dir, "cze.po")
94
+ assert( File.exists?(trg_file) )
95
+ t2 = I18n::Translate::Translate.new('cze', @opts.merge({:format => 'po'}))
96
+ assert_equal( t.target["extended"]["interpolation"], t2.target["extended"]["interpolation"] )
97
+ File.unlink(trg_file)
98
+ end
99
+
100
+ end
101
+
102
+
103
+
104
+ class TestTranslateTools < Test::Unit::TestCase
105
+
106
+ def setup
107
+ @hash = {}
108
+ end
109
+
110
+ def test_0010_scan_list_files
111
+ locales = I18n::Translate.scan(:locale_dir => $src_dir).map{ |x| x =~ /\/([^\/]+)$/; $1 }.sort
112
+ assert_equal( %w(cze.po cze.properties cze.rb cze.ts cze.yml po_to_ts.ts).sort, locales )
113
+ end
114
+
115
+ def test_0011_scan_list_files_format
116
+ locales = I18n::Translate.scan(:locale_dir => $src_dir, :format => 'yml').map{ |x| x =~ /\/([^\/]+)$/; $1 }.sort
117
+ assert_equal( %w(cze.yml).sort, locales )
118
+ end
119
+
120
+ def test_0012_scan_list_files_exclude
121
+ locales = I18n::Translate.scan(:locale_dir => $src_dir, :exclude => ['yml']).map{ |x| x =~ /\/([^\/]+)$/; $1 }.sort
122
+ assert_equal( %w(cze.po cze.properties cze.rb cze.ts po_to_ts.ts).sort, locales )
123
+ end
124
+
125
+ def test_0013_scan_list_deep
126
+ locales = I18n::Translate.scan(:locale_dir => $src_dir, :deep => true).map{ |x| x =~ /\/([^\/]+)$/; $1 }.sort
127
+ assert_equal( %w(cze.po cze.properties cze.rb cze.ts cze.yml cze.yml eng.yml po_to_ts.ts).sort, locales )
128
+ end
129
+
130
+ def test_0013_scan_list_deep_exclude
131
+ locales = I18n::Translate.scan(:locale_dir => $src_dir, :deep => true, :exclude => ['cze']).map{ |x| x =~ /\/([^\/]+)$/; $1 }.sort
132
+ assert_equal( %w(eng.yml po_to_ts.ts).sort, locales )
133
+ end
134
+
135
+ def test_0020_scan_block
136
+ I18n::Translate.scan(:locale_dir => $src_dir, :default_format => 'yml') do |tr|
137
+ entry = tr.find("simple.text")
138
+ str = "Text k přeložení"
139
+ if entry.kind_of?(String)
140
+ assert_equal( str, entry )
141
+ else
142
+ assert_equal( str, entry["translation"] )
143
+ end
144
+ end
145
+ end
146
+
147
+ def test_0030_set_bad_separator
148
+ I18n::Translate.set("a.b.c", "Value", @hash, "|")
149
+ assert_equal( {"a.b.c" => "Value"}, @hash )
150
+ end
151
+
152
+ def test_0040_set
153
+ I18n::Translate.set("a.b.c", "Value", @hash)
154
+ assert_equal( {"a" => {"b" => {"c" => "Value"}}}, @hash )
155
+
156
+ I18n::Translate.set("a.b.d", "Value 2", @hash)
157
+ assert_equal( {"a" => {"b" => {"c" => "Value", "d" => "Value 2"}}}, @hash )
158
+ end
159
+
160
+ def test_0050_find_in_empty_hash
161
+ entry = I18n::Translate.find("a.b.c", @hash)
162
+ assert_equal( nil, entry )
163
+ end
164
+
165
+ def test_0050_find
166
+ I18n::Translate.set("a.b.c", "Value", @hash)
167
+ I18n::Translate.set("a.b.d", "Value 2", @hash)
168
+ entry = I18n::Translate.find("a.b.c", @hash)
169
+ assert_equal( "Value" , entry )
170
+ end
171
+
172
+ def test_0060_hash_to_keys_empty_hash
173
+ keys = I18n::Translate.hash_to_keys(@hash)
174
+ assert_equal( [], keys )
175
+ end
176
+
177
+ def test_0060_hash_to_keys_empty_hash
178
+ I18n::Translate.set("a.b.c", "Value", @hash)
179
+ I18n::Translate.set("a.b.d", "Value 2", @hash)
180
+ keys = I18n::Translate.hash_to_keys(@hash)
181
+ assert_equal( %w(a.b.c a.b.d), keys )
163
182
  end
164
183
 
165
184
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-translators-tools
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 15
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: "0.2"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Petr Kovar
@@ -14,16 +14,18 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-17 00:00:00 +02:00
17
+ date: 2010-07-27 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: i18n
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
28
+ hash: 13
27
29
  segments:
28
30
  - 0
29
31
  - 4
@@ -35,9 +37,11 @@ dependencies:
35
37
  name: ya2yaml
36
38
  prerelease: false
37
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
38
41
  requirements:
39
42
  - - ">="
40
43
  - !ruby/object:Gem::Version
44
+ hash: 3
41
45
  segments:
42
46
  - 0
43
47
  version: "0"
@@ -46,6 +50,7 @@ dependencies:
46
50
  description: |
47
51
  This package brings you useful utility which can help you to handle locale files
48
52
  and translations in your Ruby projects. Offers also built-in simple console editor.
53
+ Supported formats are YAML, Ruby, Gettext po, QT Linguist TS and Java Properties.
49
54
  Read README.md file and run i18n-translate without parameters for more information.
50
55
 
51
56
  email: pejuko@gmail.com
@@ -57,48 +62,112 @@ extra_rdoc_files: []
57
62
 
58
63
  files:
59
64
  - bin/i18n-translate
60
- - test/tc_translate.rb
61
- - test/locale/src/default.yml
62
- - test/locale/src/cze.yml
63
- - test/locale/src/cze.rb
64
- - test/locale/src/cze.po
65
- - lib/i18n-translate.rb
66
- - lib/i18n/translate.rb
67
- - lib/i18n/processor.rb
68
- - lib/i18n/processor/yaml.rb
69
- - lib/i18n/processor/ruby.rb
70
- - lib/i18n/processor/gettext.rb
71
- - lib/i18n/backend/translate.rb
72
65
  - README.md
73
66
  - i18n-translators-tools.gemspec
74
67
  - Rakefile
68
+ - lib/i18n/translator.rb
69
+ - lib/i18n/backend/po.rb
70
+ - lib/i18n/backend/properties.rb
71
+ - lib/i18n/backend/ts.rb
72
+ - lib/i18n/backend/translate.rb
73
+ - lib/i18n/processor/properties.rb
74
+ - lib/i18n/processor/ts.rb
75
+ - lib/i18n/processor/ruby.rb
76
+ - lib/i18n/processor/yaml.rb
77
+ - lib/i18n/processor/gettext.rb
78
+ - lib/i18n/translate.rb
79
+ - lib/i18n/processor.rb
80
+ - lib/i18n-translate.rb
81
+ - test/tc_processor_properties.rb
82
+ - test/tc_processor.rb
83
+ - test/locale/src/cze.rb
84
+ - test/backend.rb
85
+ - test/tc_i18n-translate.rb
86
+ - test/tc_backend_ts.rb
87
+ - test/tc_processor_yaml.rb
88
+ - test/tc_processor_ruby.rb
89
+ - test/all.rb
90
+ - test/tc_backend_po.rb
91
+ - test/tc_processor_gettext.rb
92
+ - test/tc_backend_translate.rb
93
+ - test/tc_processor_ts.rb
94
+ - test/processor.rb
95
+ - test/tc_backend_properties.rb
96
+ - test/tc_translate.rb
97
+ - test/locale/src/cze.yml
98
+ - test/locale/src/default.yml
99
+ - test/locale/src/deep/cze.yml
100
+ - test/locale/src/deep/eng.yml
101
+ - test/locale/src/deep/default.yml
102
+ - test/locale/src/cze.po
75
103
  has_rdoc: true
76
- homepage:
104
+ homepage: http://github.com/pejuko/i18n-translators-tools
77
105
  licenses: []
78
106
 
79
- post_install_message:
107
+ post_install_message: |
108
+ =======================================================================
109
+
110
+ I18N TRANSLATORS TOOLS
111
+
112
+ -----------------------------------------------------------------------
113
+
114
+ Supported formats:
115
+ * yml
116
+ * rb
117
+ * ts
118
+ * po
119
+ * properties
120
+
121
+ Backends:
122
+ * Extended format. i18n-translators-tools bring extended format
123
+ I18n::Backend::Simple.send(:include, I18n::Backend::Translator)
124
+ * Gettext po
125
+ I18n::Backend::Simple.send(:include, I18n::Backend::PO)
126
+ * QT Linguist TS
127
+ I18n::Backend::Simple.send(:include, I18n::Backend::TS)
128
+ * Java Properties files
129
+ I18n::Backend::Simple.send(:include, I18n::Backend::Properties)
130
+
131
+ Functions:
132
+ * merge
133
+ * convert
134
+ * translate (built-in simple console translator)
135
+ * statistics
136
+
137
+ For more information read README.md and CHANGELOG.md
138
+
139
+ -----------------------------------------------------------------------
140
+
141
+ http://github.com/pejuko/i18n-translators-tools
142
+
143
+ =======================================================================
144
+
80
145
  rdoc_options: []
81
146
 
82
147
  require_paths:
83
148
  - lib
84
149
  required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
85
151
  requirements:
86
152
  - - ">="
87
153
  - !ruby/object:Gem::Version
154
+ hash: 3
88
155
  segments:
89
156
  - 0
90
157
  version: "0"
91
158
  required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
92
160
  requirements:
93
161
  - - ">="
94
162
  - !ruby/object:Gem::Version
163
+ hash: 3
95
164
  segments:
96
165
  - 0
97
166
  version: "0"
98
167
  requirements: []
99
168
 
100
169
  rubyforge_project:
101
- rubygems_version: 1.3.6
170
+ rubygems_version: 1.3.7
102
171
  signing_key:
103
172
  specification_version: 3
104
173
  summary: I18n transation utility which helps to manage files with locales.