i18n-translators-tools 0.1.1 → 0.2
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.md +72 -22
- data/Rakefile +36 -3
- data/bin/i18n-translate +11 -68
- data/i18n-translators-tools.gemspec +44 -3
- data/lib/i18n-translate.rb +5 -0
- data/lib/i18n/backend/po.rb +20 -0
- data/lib/i18n/backend/properties.rb +19 -0
- data/lib/i18n/backend/translate.rb +2 -2
- data/lib/i18n/backend/ts.rb +19 -0
- data/lib/i18n/processor.rb +56 -1
- data/lib/i18n/processor/gettext.rb +63 -22
- data/lib/i18n/processor/properties.rb +78 -0
- data/lib/i18n/processor/ruby.rb +1 -1
- data/lib/i18n/processor/ts.rb +149 -0
- data/lib/i18n/processor/yaml.rb +2 -2
- data/lib/i18n/translate.rb +84 -69
- data/lib/i18n/translator.rb +76 -0
- data/test/all.rb +89 -0
- data/test/backend.rb +51 -0
- data/test/locale/src/cze.po +26 -0
- data/test/locale/src/cze.rb +24 -2
- data/test/locale/src/cze.yml +24 -6
- data/test/locale/src/deep/cze.yml +4 -0
- data/test/locale/src/deep/default.yml +4 -0
- data/test/locale/src/deep/eng.yml +4 -0
- data/test/locale/src/default.yml +14 -6
- data/test/processor.rb +42 -0
- data/test/tc_backend_po.rb +16 -0
- data/test/tc_backend_properties.rb +16 -0
- data/test/tc_backend_translate.rb +16 -0
- data/test/tc_backend_ts.rb +16 -0
- data/test/tc_i18n-translate.rb +128 -0
- data/test/tc_processor.rb +49 -0
- data/test/tc_processor_gettext.rb +15 -0
- data/test/tc_processor_properties.rb +35 -0
- data/test/tc_processor_ruby.rb +15 -0
- data/test/tc_processor_ts.rb +26 -0
- data/test/tc_processor_yaml.rb +15 -0
- data/test/tc_translate.rb +106 -87
- metadata +88 -19
data/test/backend.rb
ADDED
@@ -0,0 +1,51 @@
|
|
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
|
+
module I18n::Test
|
7
|
+
module Backend
|
8
|
+
def test_0010_I18n_plugin_simple_text
|
9
|
+
assert_equal( "Text k přeložení", I18n.t("simple.text") )
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_0020_I18n_plugin_plural_text
|
13
|
+
assert_equal( "Jedna položka", I18n.t("simple.plural", :count => 1) )
|
14
|
+
assert_equal( "Mnoho položek", I18n.t("simple.plural", :count => 9))
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_0030_I18n_plugin_interpolation
|
18
|
+
assert_equal( "Interpolovaný text 'ahoj'", I18n.t("simple.interpolation", :var => "ahoj"))
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_0040_I18n_plugin_translate_simple
|
22
|
+
assert_equal( "Změněný jednoduchý text", I18n.t("changed.simple"))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_0050_I18n_plugin_translate_plural
|
26
|
+
assert_equal( "Změněný plurál text", I18n.t("changed.plural", :count => 1))
|
27
|
+
assert_equal( "Změněný plurál textů", I18n.t("changed.plural", :count => 9))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_0060_I18n_plugin_translate_interpolation
|
31
|
+
assert_equal( "Interpolovaný změněný text 'ahoj'", I18n.t("changed.interpolation", :var => "ahoj"))
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_0070_I18n_fallback_is_working
|
35
|
+
assert_equal( "This text is only in default", I18n.t("missing.fallback") )
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_0080_new_line
|
39
|
+
assert_equal( "V tomto textu\nje nový řádek.", I18n.t("test.new_line") )
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_0080_quote
|
43
|
+
assert_equal( "Tento text obsahuje \" -- jednu uvozovku.", I18n.t("test.quote") )
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_0080_string_key_without_dots
|
47
|
+
assert_equal( "tady je nějaký text", I18n.t("some text there") )
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/test/locale/src/cze.po
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
msgid ""
|
2
|
+
msgstr ""
|
3
|
+
"Content-Type: text/plain; charset=utf-8\n"
|
4
|
+
"X-Language: cze\n"
|
1
5
|
|
2
6
|
msgctxt "changed.interpolation"
|
3
7
|
msgid "Interpolated changed text '%{var}'"
|
@@ -15,6 +19,15 @@ msgctxt "changed.simple"
|
|
15
19
|
msgid "Changed simple text"
|
16
20
|
msgstr "Změněný jednoduchý text"
|
17
21
|
|
22
|
+
# Comment
|
23
|
+
#. Extracted Comment
|
24
|
+
#: src/test.rb:31
|
25
|
+
#, fuzzy, incomplete
|
26
|
+
#| msgid "Previous untranslated"
|
27
|
+
msgctxt "extended.interpolation"
|
28
|
+
msgid "Interpolated text '%{var}'"
|
29
|
+
msgstr "Interpolovaný text '%{var}'"
|
30
|
+
|
18
31
|
msgctxt "simple.interpolation"
|
19
32
|
msgid "Interpolated text '%{var}'"
|
20
33
|
msgstr "Interpolovaný text '%{var}'"
|
@@ -30,3 +43,16 @@ msgstr "Mnoho položek"
|
|
30
43
|
msgctxt "simple.text"
|
31
44
|
msgid "Text to translate"
|
32
45
|
msgstr "Text k přeložení"
|
46
|
+
|
47
|
+
msgctxt "test.new_line"
|
48
|
+
msgid "In this text\n"
|
49
|
+
"is a new line."
|
50
|
+
msgstr "V tomto textu\n"
|
51
|
+
"je nový řádek."
|
52
|
+
|
53
|
+
msgctxt "test.quote"
|
54
|
+
msgid "This text contains \" -- one quote."
|
55
|
+
msgstr "Tento text obsahuje \" -- jednu uvozovku."
|
56
|
+
|
57
|
+
msgid "some text there"
|
58
|
+
msgstr "tady je nějaký text"
|
data/test/locale/src/cze.rb
CHANGED
@@ -20,6 +20,20 @@
|
|
20
20
|
"t" => "Změněný jednoduchý text"
|
21
21
|
}
|
22
22
|
},
|
23
|
+
"extended" => {
|
24
|
+
"interpolation" => {
|
25
|
+
"comment" => "Comment",
|
26
|
+
"extracted_comment" => "Extracted Comment",
|
27
|
+
"reference" => "src/test.rb:31",
|
28
|
+
"file" => "src/test.rb",
|
29
|
+
"line" => "31",
|
30
|
+
"old_default" => "Previous untranslated",
|
31
|
+
"default" => "Interpolated text '%{var}'",
|
32
|
+
"translation" => "Interpolovaný text '%{var}'",
|
33
|
+
"fuzzy" => true,
|
34
|
+
"flag" => "incomplete"
|
35
|
+
}
|
36
|
+
},
|
23
37
|
"simple" => {
|
24
38
|
"interpolation" => "Interpolovaný text '%{var}'",
|
25
39
|
"plural" => {
|
@@ -27,6 +41,14 @@
|
|
27
41
|
"other" => "Mnoho položek"
|
28
42
|
},
|
29
43
|
"text" => "Text k přeložení"
|
30
|
-
}
|
44
|
+
},
|
45
|
+
"test" => {
|
46
|
+
"new_line" => {
|
47
|
+
"default" => "In this text\nis a new line.",
|
48
|
+
"translation" => "V tomto textu\nje nový řádek."
|
49
|
+
},
|
50
|
+
"quote" => "Tento text obsahuje \" -- jednu uvozovku."
|
51
|
+
},
|
52
|
+
"some text there" => "tady je nějaký text"
|
31
53
|
}
|
32
|
-
}
|
54
|
+
}
|
data/test/locale/src/cze.yml
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
---
|
2
2
|
cze:
|
3
|
-
simple:
|
4
|
-
text: Text k přeložení
|
5
|
-
interpolation: "Interpolovaný text '%{var}'"
|
6
|
-
plural:
|
7
|
-
one: Jedna položka
|
8
|
-
other: Mnoho položek
|
9
3
|
changed:
|
10
4
|
simple:
|
11
5
|
default: Changed simple text
|
@@ -20,3 +14,27 @@ cze:
|
|
20
14
|
other:
|
21
15
|
default: Changed plural other texts
|
22
16
|
t: Změněný plurál textů
|
17
|
+
extended:
|
18
|
+
interpolation:
|
19
|
+
comment: Comment
|
20
|
+
extracted_comment: Extracted Comment
|
21
|
+
reference: "src/test.rb:31"
|
22
|
+
file: "src/test.rb"
|
23
|
+
line: "31"
|
24
|
+
old_default: Previous untranslated
|
25
|
+
default: "Interpolated text '%{var}'"
|
26
|
+
translation: "Interpolovaný text '%{var}'"
|
27
|
+
fuzzy: true
|
28
|
+
flag: incomplete
|
29
|
+
simple:
|
30
|
+
text: Text k přeložení
|
31
|
+
interpolation: "Interpolovaný text '%{var}'"
|
32
|
+
plural:
|
33
|
+
one: Jedna položka
|
34
|
+
other: Mnoho položek
|
35
|
+
test:
|
36
|
+
new_line:
|
37
|
+
default: "In this text\nis a new line."
|
38
|
+
translation: "V tomto textu\nje nový řádek."
|
39
|
+
quote: "Tento text obsahuje \" -- jednu uvozovku."
|
40
|
+
"some text there": "tady je nějaký text"
|
data/test/locale/src/default.yml
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
---
|
2
2
|
default:
|
3
|
-
simple:
|
4
|
-
text: Text to translate
|
5
|
-
interpolation: "Interpolated text '%{var}'"
|
6
|
-
plural:
|
7
|
-
one: One item
|
8
|
-
other: Many items
|
9
3
|
changed:
|
10
4
|
simple: This text is newer and changed
|
11
5
|
interpolation: "This interpolated text is newer '%{var}'"
|
12
6
|
plural:
|
13
7
|
one: This text is newer plural one text
|
14
8
|
other: This text is newer plural other text
|
9
|
+
extended:
|
10
|
+
interpolation: "Interpolated text '%{var}'"
|
11
|
+
missing:
|
12
|
+
fallback: "This text is only in default"
|
13
|
+
simple:
|
14
|
+
text: Text to translate
|
15
|
+
interpolation: "Interpolated text '%{var}'"
|
16
|
+
plural:
|
17
|
+
one: One item
|
18
|
+
other: Many items
|
19
|
+
test:
|
20
|
+
new_line: "In this text\nis a new line."
|
21
|
+
quote: "This text contains \" -- one quote."
|
22
|
+
"some text there": "some text there"
|
data/test/processor.rb
ADDED
@@ -0,0 +1,42 @@
|
|
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
|
+
module I18n::Test
|
7
|
+
|
8
|
+
module Processor
|
9
|
+
|
10
|
+
def __prepare(processor, file)
|
11
|
+
# prepare object with correct data from yaml
|
12
|
+
@tr = I18n::Translate::Translate.new('cze', {:locale_dir => $src_dir, :default_format => 'yml', :format => 'yml'})
|
13
|
+
@tr.assign(@tr.target)
|
14
|
+
|
15
|
+
# prepare reader and writer
|
16
|
+
@src_file = File.join($src_dir, file)
|
17
|
+
@trg_file = File.join($trg_dir, file)
|
18
|
+
@src = processor.new(@src_file, @tr)
|
19
|
+
@trg = processor.new(@trg_file, @tr)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_0010_read
|
23
|
+
data = @src.read
|
24
|
+
assert( data.keys.include?('cze') )
|
25
|
+
data = data['cze']
|
26
|
+
diff($si, data["extended"]["interpolation"])
|
27
|
+
assert_equal( $si, data["extended"]["interpolation"] )
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_0020_write
|
31
|
+
data = @src.read
|
32
|
+
@trg.write(data)
|
33
|
+
assert( File.exists?(@trg_file) )
|
34
|
+
data2 = @trg.read
|
35
|
+
diff(data['cze'],data2['cze'])
|
36
|
+
assert_equal(data, data2)
|
37
|
+
File.unlink(@trg_file)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
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 TestBackendPO < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
I18n.load_path = Dir[ "#{$src_dir}/default.yml", "#{$src_dir}/cze.po" ]
|
11
|
+
I18n.reload!
|
12
|
+
end
|
13
|
+
|
14
|
+
include I18n::Test::Backend
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
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 TestBackendProperties < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
I18n.load_path = Dir[ "#{$src_dir}/default.yml", "#{$src_dir}/cze.properties" ]
|
11
|
+
I18n.reload!
|
12
|
+
end
|
13
|
+
|
14
|
+
include I18n::Test::Backend
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
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 TestBackendTranslate < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
I18n.load_path = Dir[ "#{$src_dir}/default.yml", "#{$src_dir}/cze.yml" ]
|
11
|
+
I18n.reload!
|
12
|
+
end
|
13
|
+
|
14
|
+
include I18n::Test::Backend
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
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 TestBackendTS < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
I18n.load_path = Dir[ "#{$src_dir}/default.yml", "#{$src_dir}/cze.ts" ]
|
11
|
+
I18n.reload!
|
12
|
+
end
|
13
|
+
|
14
|
+
include I18n::Test::Backend
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,128 @@
|
|
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
|
+
# this test is testing bin/i18n-translate utility
|
8
|
+
# all writing is done through pipe
|
9
|
+
# and results are checked from file
|
10
|
+
class TestI18nTranslateTool < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@src_file = File.join($src_dir, "cze.yml")
|
14
|
+
@trg_file = File.join($trg_dir, "cze.yml")
|
15
|
+
@default_src = File.join($src_dir, "default.yml")
|
16
|
+
@default_trg = File.join($trg_dir, "default.yml")
|
17
|
+
@bin = File.expand_path( File.join($current_dir, "../bin/i18n-translate") )
|
18
|
+
FileUtils.cp(@src_file, @trg_file)
|
19
|
+
FileUtils.cp(@default_src, @default_trg)
|
20
|
+
@tr = I18n::Translate::Translate.new('cze', :locale_dir => $trg_dir, :format => "yml")
|
21
|
+
@io = IO.popen("#{@bin} translate -l cze --locale_dir=#{$trg_dir} -f yml", "r+")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_0010_translate_first_entry
|
25
|
+
str = "Tento interpolovaný text je novější '%{var}'"
|
26
|
+
@io.puts("t\n")
|
27
|
+
@io.puts(str)
|
28
|
+
@io.puts("q")
|
29
|
+
@io.close
|
30
|
+
t = I18n::Translate::Translate.new('cze', :locale_dir => $trg_dir, :format => "yml")
|
31
|
+
assert_not_equal(t.target, @tr.target)
|
32
|
+
assert_equal( str, t.target["changed"]["interpolation"]["translation"] )
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_0010_translate_first_entry
|
36
|
+
str = "Tento interpolovaný text je novější '%{var}'"
|
37
|
+
@io.puts("t\n")
|
38
|
+
@io.puts(str)
|
39
|
+
@io.puts("q")
|
40
|
+
@io.close
|
41
|
+
t = I18n::Translate::Translate.new('cze', :locale_dir => $trg_dir, :format => "yml")
|
42
|
+
assert_not_equal(t.target, @tr.target)
|
43
|
+
assert_equal( str, t.target["changed"]["interpolation"]["translation"] )
|
44
|
+
assert_equal( "ok", t.target["changed"]["interpolation"]["flag"] )
|
45
|
+
|
46
|
+
File.unlink(@trg_file)
|
47
|
+
File.unlink(@default_trg)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_0020_translate_first_entry_flag
|
51
|
+
str = "Tento interpolovaný text je novější '%{var}'"
|
52
|
+
@io.puts("t\n")
|
53
|
+
@io.puts(str)
|
54
|
+
@io.puts("f")
|
55
|
+
@io.puts("i")
|
56
|
+
@io.puts("q")
|
57
|
+
@io.close
|
58
|
+
t = I18n::Translate::Translate.new('cze', :locale_dir => $trg_dir, :format => "yml")
|
59
|
+
assert_not_equal(t.target, @tr.target)
|
60
|
+
assert_equal( str, t.target["changed"]["interpolation"]["translation"] )
|
61
|
+
assert_equal( "incomplete", t.target["changed"]["interpolation"]["flag"] )
|
62
|
+
|
63
|
+
File.unlink(@trg_file)
|
64
|
+
File.unlink(@default_trg)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_0030_translate_first_entry_comment
|
68
|
+
str = "Nějaký komentář"
|
69
|
+
@io.puts("c\n")
|
70
|
+
@io.puts(str)
|
71
|
+
@io.puts("q")
|
72
|
+
@io.close
|
73
|
+
t = I18n::Translate::Translate.new('cze', :locale_dir => $trg_dir, :format => "yml")
|
74
|
+
assert_not_equal(t.target, @tr.target)
|
75
|
+
assert_equal( str, t.target["changed"]["interpolation"]["comment"] )
|
76
|
+
assert_equal( "changed", t.target["changed"]["interpolation"]["flag"] )
|
77
|
+
|
78
|
+
File.unlink(@trg_file)
|
79
|
+
File.unlink(@default_trg)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_0030_translate_first_entry_save_and_then_exit
|
83
|
+
str = "Nějaký komentář"
|
84
|
+
@io.puts("c\n")
|
85
|
+
@io.puts(str)
|
86
|
+
@io.puts("s")
|
87
|
+
@io.puts("x")
|
88
|
+
@io.close
|
89
|
+
t = I18n::Translate::Translate.new('cze', :locale_dir => $trg_dir, :format => "yml")
|
90
|
+
assert_not_equal(t.target, @tr.target)
|
91
|
+
assert_equal( str, t.target["changed"]["interpolation"]["comment"] )
|
92
|
+
assert_equal( "changed", t.target["changed"]["interpolation"]["flag"] )
|
93
|
+
|
94
|
+
File.unlink(@trg_file)
|
95
|
+
File.unlink(@default_trg)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_0040_translate_quit_without_saving
|
99
|
+
str = "Tento interpolovaný text je novější '%{var}'"
|
100
|
+
@io.puts("t\n")
|
101
|
+
@io.puts(str)
|
102
|
+
@io.puts("x")
|
103
|
+
@io.close
|
104
|
+
t = I18n::Translate::Translate.new('cze', :locale_dir => $trg_dir, :format => "yml")
|
105
|
+
assert_equal(t.target, @tr.target)
|
106
|
+
assert_not_equal( str, t.target["changed"]["interpolation"]["translation"] )
|
107
|
+
|
108
|
+
File.unlink(@trg_file)
|
109
|
+
File.unlink(@default_trg)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_0050_next_and_translate
|
113
|
+
str = "Tento text jen novější množné číslo"
|
114
|
+
@io.puts("n")
|
115
|
+
@io.puts("t\n")
|
116
|
+
@io.puts(str)
|
117
|
+
@io.puts("q")
|
118
|
+
@io.close
|
119
|
+
t = I18n::Translate::Translate.new('cze', :locale_dir => $trg_dir, :format => "yml")
|
120
|
+
assert_not_equal(t.target, @tr.target)
|
121
|
+
assert_equal( str, t.target["changed"]["plural"]["one"]["translation"] )
|
122
|
+
assert_equal( "ok", t.target["changed"]["plural"]["one"]["flag"] )
|
123
|
+
|
124
|
+
File.unlink(@trg_file)
|
125
|
+
File.unlink(@default_trg)
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|