i18n-translators-tools 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,7 @@ spec = Gem::Specification.new do |s|
13
13
  s.email = "pejuko@gmail.com"
14
14
  s.authors = ["Petr Kovar"]
15
15
  s.name = 'i18n-translators-tools'
16
- s.version = '0.2'
16
+ s.version = '0.2.1'
17
17
  s.date = '2010-07-27'
18
18
  s.add_dependency('i18n', '>= 0.4.1')
19
19
  s.add_dependency('ya2yaml')
@@ -51,6 +51,10 @@ Functions:
51
51
  * translate (built-in simple console translator)
52
52
  * statistics
53
53
 
54
+ v0.2.1
55
+ * fix: I18n::Backend::Translate now returns nil if translation is empty string
56
+ (this allows fallbacks)
57
+
54
58
  For more information read README.md and CHANGELOG.md
55
59
 
56
60
  -----------------------------------------------------------------------
@@ -19,10 +19,13 @@ module I18n
19
19
  # the simple and the Translator's
20
20
  def translate(locale, key, options = {})
21
21
  result = super(locale, key, options)
22
+ return nil if result.kind_of?(String) and result.empty?
22
23
  return result unless result.kind_of?(Hash)
23
24
  return nil unless result[:t] or result[:translation]
24
25
 
25
26
  tr = result[:translation] || result[:t]
27
+ return nil if tr.to_s.empty?
28
+
26
29
  values = options.except(*I18n::Backend::Base::RESERVED_KEYS)
27
30
 
28
31
  tr = resolve(locale, key, tr, options)
@@ -35,15 +35,19 @@ module I18n::Test
35
35
  assert_equal( "This text is only in default", I18n.t("missing.fallback") )
36
36
  end
37
37
 
38
- def test_0080_new_line
38
+ def test_0080_I18n_fallback_empty_string
39
+ assert_equal( "Empty string", I18n.t("missing.empty") )
40
+ end
41
+
42
+ def test_0090_new_line
39
43
  assert_equal( "V tomto textu\nje nový řádek.", I18n.t("test.new_line") )
40
44
  end
41
45
 
42
- def test_0080_quote
46
+ def test_0100_quote
43
47
  assert_equal( "Tento text obsahuje \" -- jednu uvozovku.", I18n.t("test.quote") )
44
48
  end
45
49
 
46
- def test_0080_string_key_without_dots
50
+ def test_0110_string_key_without_dots
47
51
  assert_equal( "tady je nějaký text", I18n.t("some text there") )
48
52
  end
49
53
 
@@ -28,6 +28,10 @@ msgctxt "extended.interpolation"
28
28
  msgid "Interpolated text '%{var}'"
29
29
  msgstr "Interpolovaný text '%{var}'"
30
30
 
31
+ msgctxt "missing.empty"
32
+ msgid "Empty string"
33
+ msgstr ""
34
+
31
35
  msgctxt "simple.interpolation"
32
36
  msgid "Interpolated text '%{var}'"
33
37
  msgstr "Interpolovaný text '%{var}'"
@@ -34,6 +34,7 @@
34
34
  "flag" => "incomplete"
35
35
  }
36
36
  },
37
+ "missing" => { "empty" => "" },
37
38
  "simple" => {
38
39
  "interpolation" => "Interpolovaný text '%{var}'",
39
40
  "plural" => {
@@ -26,6 +26,8 @@ cze:
26
26
  translation: "Interpolovaný text '%{var}'"
27
27
  fuzzy: true
28
28
  flag: incomplete
29
+ missing:
30
+ empty: ""
29
31
  simple:
30
32
  text: Text k přeložení
31
33
  interpolation: "Interpolovaný text '%{var}'"
@@ -10,6 +10,7 @@ default:
10
10
  interpolation: "Interpolated text '%{var}'"
11
11
  missing:
12
12
  fallback: "This text is only in default"
13
+ empty: "Empty string"
13
14
  simple:
14
15
  text: Text to translate
15
16
  interpolation: "Interpolated text '%{var}'"
@@ -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 TestBackendDefaultRuby < Test::Unit::TestCase
8
+
9
+ def setup
10
+ I18n.load_path = Dir[ "#{$src_dir}/default.yml", "#{$src_dir}/cze.rb" ]
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 TestBackendDefaultYAML < 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
@@ -74,6 +74,7 @@ class TestTranslate < Test::Unit::TestCase
74
74
  assert(trb.kind_of?(I18n::Translate::Translate))
75
75
  assert_equal(File.join(File.expand_path($src_dir), 'cze.rb'), trb.lang_file)
76
76
  assert_equal(@t.default, trb.default)
77
+ diff(@t.target, trb.target)
77
78
  assert_equal(@t.target, trb.target)
78
79
  end
79
80
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-translators-tools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- version: "0.2"
9
+ - 1
10
+ version: 0.2.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Petr Kovar
@@ -89,9 +90,11 @@ files:
89
90
  - test/all.rb
90
91
  - test/tc_backend_po.rb
91
92
  - test/tc_processor_gettext.rb
93
+ - test/tc_backend_ruby.rb
92
94
  - test/tc_backend_translate.rb
93
95
  - test/tc_processor_ts.rb
94
96
  - test/processor.rb
97
+ - test/tc_backend_yaml.rb
95
98
  - test/tc_backend_properties.rb
96
99
  - test/tc_translate.rb
97
100
  - test/locale/src/cze.yml
@@ -134,6 +137,10 @@ post_install_message: |
134
137
  * translate (built-in simple console translator)
135
138
  * statistics
136
139
 
140
+ v0.2.1
141
+ * fix: I18n::Backend::Translate now returns nil if translation is empty string
142
+ (this allows fallbacks)
143
+
137
144
  For more information read README.md and CHANGELOG.md
138
145
 
139
146
  -----------------------------------------------------------------------