i18n-translators-tools 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +229 -0
- data/Rakefile +18 -0
- data/bin/i18n-translate +304 -0
- data/i18n-translators-tools.gemspec +27 -0
- data/lib/i18n-translate.rb +13 -0
- data/lib/i18n/backend/translate.rb +38 -0
- data/lib/i18n/processor.rb +93 -0
- data/lib/i18n/processor/gettext.rb +127 -0
- data/lib/i18n/processor/ruby.rb +41 -0
- data/lib/i18n/processor/yaml.rb +24 -0
- data/lib/i18n/translate.rb +413 -0
- data/test/locale/src/cze.po +32 -0
- data/test/locale/src/cze.rb +32 -0
- data/test/locale/src/cze.yml +22 -0
- data/test/locale/src/default.yml +14 -0
- data/test/tc_translate.rb +166 -0
- metadata +81 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
msgctxt "changed.interpolation"
|
3
|
+
msgid "Interpolated changed text '%{var}'"
|
4
|
+
msgstr "Interpolovaný změněný text '%{var}'"
|
5
|
+
|
6
|
+
msgctxt "changed.plural.one"
|
7
|
+
msgid "Changed plural one text"
|
8
|
+
msgstr "Změněný plurál text"
|
9
|
+
|
10
|
+
msgctxt "changed.plural.other"
|
11
|
+
msgid "Changed plural other texts"
|
12
|
+
msgstr "Změněný plurál textů"
|
13
|
+
|
14
|
+
msgctxt "changed.simple"
|
15
|
+
msgid "Changed simple text"
|
16
|
+
msgstr "Změněný jednoduchý text"
|
17
|
+
|
18
|
+
msgctxt "simple.interpolation"
|
19
|
+
msgid "Interpolated text '%{var}'"
|
20
|
+
msgstr "Interpolovaný text '%{var}'"
|
21
|
+
|
22
|
+
msgctxt "simple.plural.one"
|
23
|
+
msgid "One item"
|
24
|
+
msgstr "Jedna položka"
|
25
|
+
|
26
|
+
msgctxt "simple.plural.other"
|
27
|
+
msgid "Many items"
|
28
|
+
msgstr "Mnoho položek"
|
29
|
+
|
30
|
+
msgctxt "simple.text"
|
31
|
+
msgid "Text to translate"
|
32
|
+
msgstr "Text k přeložení"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
{
|
2
|
+
"cze" => {
|
3
|
+
"changed" => {
|
4
|
+
"interpolation" => {
|
5
|
+
"default" => "Interpolated changed text '%{var}'",
|
6
|
+
"t" => "Interpolovaný změněný text '%{var}'"
|
7
|
+
},
|
8
|
+
"plural" => {
|
9
|
+
"one" => {
|
10
|
+
"default" => "Changed plural one text",
|
11
|
+
"t" => "Změněný plurál text"
|
12
|
+
},
|
13
|
+
"other" => {
|
14
|
+
"default" => "Changed plural other texts",
|
15
|
+
"t" => "Změněný plurál textů"
|
16
|
+
}
|
17
|
+
},
|
18
|
+
"simple" => {
|
19
|
+
"default" => "Changed simple text",
|
20
|
+
"t" => "Změněný jednoduchý text"
|
21
|
+
}
|
22
|
+
},
|
23
|
+
"simple" => {
|
24
|
+
"interpolation" => "Interpolovaný text '%{var}'",
|
25
|
+
"plural" => {
|
26
|
+
"one" => "Jedna položka",
|
27
|
+
"other" => "Mnoho položek"
|
28
|
+
},
|
29
|
+
"text" => "Text k přeložení"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
---
|
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
|
+
changed:
|
10
|
+
simple:
|
11
|
+
default: Changed simple text
|
12
|
+
t: Změněný jednoduchý text
|
13
|
+
interpolation:
|
14
|
+
default: "Interpolated changed text '%{var}'"
|
15
|
+
t: "Interpolovaný změněný text '%{var}'"
|
16
|
+
plural:
|
17
|
+
one:
|
18
|
+
default: Changed plural one text
|
19
|
+
t: Změněný plurál text
|
20
|
+
other:
|
21
|
+
default: Changed plural other texts
|
22
|
+
t: Změněný plurál textů
|
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
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
|
+
changed:
|
10
|
+
simple: This text is newer and changed
|
11
|
+
interpolation: "This interpolated text is newer '%{var}'"
|
12
|
+
plural:
|
13
|
+
one: This text is newer plural one text
|
14
|
+
other: This text is newer plural other text
|
@@ -0,0 +1,166 @@
|
|
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
|
+
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
|
+
|
82
|
+
class TestTranslate < Test::Unit::TestCase
|
83
|
+
def setup
|
84
|
+
@opts = {:locale_dir => $src_dir, :format => 'yml', :default_format => 'yml'}
|
85
|
+
@t = I18n::Translate::Translate.new('cze', @opts)
|
86
|
+
@t.options[:locale_dir] = $trg_dir
|
87
|
+
I18n.load_path << Dir[ "#{$src_dir}/*.yml" ]
|
88
|
+
I18n.reload!
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_0010_initialize
|
92
|
+
assert_not_equal(nil, @t)
|
93
|
+
assert_equal( true, @t.kind_of?(I18n::Translate::Translate) )
|
94
|
+
|
95
|
+
default, cze = load_src
|
96
|
+
assert_equal( default, @t.default )
|
97
|
+
assert_equal( cze, @t.target )
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_0020_merge_simple
|
101
|
+
assert_equal( { "key" => "simple.text",
|
102
|
+
"default" => "Text to translate",
|
103
|
+
"t" => "Text k přeložení",
|
104
|
+
"old_t" => "",
|
105
|
+
"old_default" => "",
|
106
|
+
"comment" => "",
|
107
|
+
"flag" => "ok" }, @t["simple.text"] )
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_0030_merge_changed
|
111
|
+
assert_equal( { "key" => "changed.simple",
|
112
|
+
"default" => "This text is newer and changed",
|
113
|
+
"t" => "",
|
114
|
+
"old_t" => "Změněný jednoduchý text",
|
115
|
+
"old_default" => "Changed simple text",
|
116
|
+
"comment" => "",
|
117
|
+
"flag" => "changed" }, @t["changed.simple"] )
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_0040_assign_merge
|
121
|
+
@t.assign(@t.merge)
|
122
|
+
entry = @t.find("simple.text", @t.target )
|
123
|
+
|
124
|
+
assert( entry.kind_of?(Hash) )
|
125
|
+
assert_equal( { "t" => "Text k přeložení",
|
126
|
+
"old" => "",
|
127
|
+
"default" => "Text to translate",
|
128
|
+
"comment" => "",
|
129
|
+
"flag" => "ok"
|
130
|
+
}, entry )
|
131
|
+
|
132
|
+
entry = @t.find("changed.simple", @t.target )
|
133
|
+
assert_equal( { "t" => "Změněný jednoduchý text",
|
134
|
+
"old" => "Changed simple text",
|
135
|
+
"default" => "This text is newer and changed",
|
136
|
+
"comment" => "",
|
137
|
+
"flag" => "changed",
|
138
|
+
"fuzzy" => true
|
139
|
+
}, entry )
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_0050_strip!
|
143
|
+
@t.strip!
|
144
|
+
entry = @t.find("changed.simple", @t.target )
|
145
|
+
|
146
|
+
assert( entry.kind_of?(String) )
|
147
|
+
assert_equal( "Změněný jednoduchý text", entry )
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_0060_read_ruby
|
151
|
+
trb = I18n::Translate::Translate.new('cze', @opts.merge({:format => 'rb'}))
|
152
|
+
assert(trb.kind_of?(I18n::Translate::Translate))
|
153
|
+
assert_equal(File.join(File.expand_path($src_dir), 'cze.rb'), trb.lang_file)
|
154
|
+
assert_equal(@t.default, trb.default)
|
155
|
+
assert_equal(@t.target, trb.target)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_0070_read_po
|
159
|
+
tpo = I18n::Translate::Translate.new('cze', @opts.merge({:format => 'po'}))
|
160
|
+
assert(tpo.kind_of?(I18n::Translate::Translate))
|
161
|
+
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)
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n-translators-tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
version: "0.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Petr Kovar
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-07-16 00:00:00 +02:00
|
17
|
+
default_executable:
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: |
|
21
|
+
This package brings you useful utility which can help you to handle locale files
|
22
|
+
and translations in your Ruby projects. Read README.md file and run i18n-translate
|
23
|
+
without parameters for more information.
|
24
|
+
|
25
|
+
email: pejuko@gmail.com
|
26
|
+
executables:
|
27
|
+
- i18n-translate
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- bin/i18n-translate
|
34
|
+
- test/tc_translate.rb
|
35
|
+
- test/locale/src/default.yml
|
36
|
+
- test/locale/src/cze.yml
|
37
|
+
- test/locale/src/cze.rb
|
38
|
+
- test/locale/src/cze.po
|
39
|
+
- lib/i18n-translate.rb
|
40
|
+
- lib/i18n/translate.rb
|
41
|
+
- lib/i18n/processor.rb
|
42
|
+
- lib/i18n/processor/yaml.rb
|
43
|
+
- lib/i18n/processor/ruby.rb
|
44
|
+
- lib/i18n/processor/gettext.rb
|
45
|
+
- lib/i18n/backend/translate.rb
|
46
|
+
- README.md
|
47
|
+
- i18n-translators-tools.gemspec
|
48
|
+
- Rakefile
|
49
|
+
has_rdoc: true
|
50
|
+
homepage:
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements:
|
73
|
+
- i18n
|
74
|
+
- ya2yaml
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.3.6
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: I18n transation utility which helps to manage files with locales.
|
80
|
+
test_files: []
|
81
|
+
|