kriss-gettext_i18n 0.2.0 → 0.2.1

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.rdoc CHANGED
@@ -2,37 +2,37 @@ Extended Globalize2 which is acting like gettext translations.
2
2
 
3
3
  == Installation
4
4
 
5
- sudo gem install kriss-gettext_like_i18n --source=http://gems.github.com/
5
+ sudo gem install kriss-gettext_i18n --source=http://gems.github.com/
6
6
 
7
7
  == Usage
8
8
 
9
9
  in controllers...
10
10
 
11
- class FooController < ApplicationController
12
- def bar
13
- render :text => _('Wonderfull i18n notice!')
14
- end
15
- end
11
+ class FooController < ApplicationController
12
+ def bar
13
+ render :text => _('Wonderfull i18n notice!')
14
+ end
15
+ end
16
16
 
17
17
  in models...
18
18
 
19
- class Bar < ActiveRecord::Base
20
- def foo(condition)
21
- if condition
22
- return "Some translated string".t
23
- else
24
- return :"some.key.for.translation".t
25
- end
26
- end
27
- end
19
+ class Bar < ActiveRecord::Base
20
+ def foo(condition)
21
+ if condition
22
+ return "Some translated string".t
23
+ else
24
+ return :"some.key.for.translation".t
25
+ end
26
+ end
27
+ end
28
28
 
29
29
  in views...
30
30
 
31
- <div id="foo">
32
- <%=_ 'Translated message' %> or <%= 'Other translated message'.t %><br />
33
- <%=_ 'Great translated string with {{parameter}}, :parameter => 'gettext like i18n' %><br />
34
- <%= link_to _('Get it now!'), 'http://github.com/kriss/gettext_like_i18n/' %>
35
- </div>
31
+ <div id="foo">
32
+ <%=_ 'Translated message' %> or <%= 'Other translated message'.t %><br />
33
+ <%=_ 'Great translated string with {{parameter}}, :parameter => 'gettext like i18n' %><br />
34
+ <%= link_to _('Get it now!'), 'http://github.com/kriss/gettext_like_i18n/' %>
35
+ </div>
36
36
 
37
37
  == Translations
38
38
 
data/TODO.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ == TODO
2
+ * Tests for Rails controllers and views
3
+
4
+ == PLANS FOR FUTURE
5
+ * Database integrated backend
6
+ * Interface for translators
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 2
3
- :patch: 0
3
+ :patch: 1
4
4
  :major: 0
data/gettext_i18n.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'gettext_i18n'
3
- s.version = '0.2.0'
3
+ s.version = '0.2.1'
4
4
  s.date = '2009-09-25'
5
5
 
6
6
  s.summary = "Extended Globalize2 which is acting like gettext translations"
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  'MIT-LICENSE',
20
20
  'README.rdoc',
21
21
  'CHANGELOG.rdoc',
22
+ 'TODO.rdoc',
22
23
  'VERSION.yml',
23
24
  'gettext_i18n.gemspec',
24
25
  'init.rb',
@@ -15,7 +15,7 @@ module Globalize
15
15
  begin
16
16
  translate locale, key.to_sym, options
17
17
  rescue I18n::MissingTranslationData
18
- return key
18
+ interpolate locale, key, options
19
19
  end
20
20
  else
21
21
  translate locale, key, options
data/lib/rails/extend.rb CHANGED
@@ -3,5 +3,30 @@ class ActiveRecord::Base
3
3
  include I18n::Gettext::Singleton
4
4
  end
5
5
 
6
- ActionController::Translation.send(:extend, I18n::Gettext)
7
- ActionView::Helpers::TranslationHelper.send(:extend, I18n::Gettext)
6
+ ActionController::Translation.module_eval do
7
+ extend I18n::Gettext
8
+ end
9
+
10
+ # Extending with I18n::Gettext is not working for translation helper
11
+ # so we have to declare gettext methods here. Methods overwritten by
12
+ # Globalize2 also have to be restored.
13
+ ActionView::Helpers::TranslationHelper.module_eval do
14
+ def gettext(key, options={})
15
+ I18n.gettext(key, options)
16
+ end
17
+ alias :_ :gettext
18
+
19
+ def translate(key, options = {})
20
+ options[:raise] = true
21
+ I18n.translate(scope_key_by_partial(key), options)
22
+ rescue I18n::MissingTranslationData => e
23
+ keys = I18n.send(:normalize_translation_keys, e.locale, e.key, e.options[:scope])
24
+ content_tag('span', keys.join(', '), :class => 'translation_missing')
25
+ end
26
+ alias :t :translate
27
+
28
+ def localize(*args)
29
+ I18n.localize *args
30
+ end
31
+ alias :l :localize
32
+ end
@@ -31,7 +31,19 @@ class GettextI18nTest < Test::Unit::TestCase
31
31
 
32
32
  should "fallback translation to :root language" do
33
33
  I18n.locale = :en
34
- #assert_equal "It's work!", I18n.gettext("Translation fallback")
34
+ assert_equal "It's work!", I18n.gettext("Translation fallback")
35
+ end
36
+ end
37
+
38
+ context "Translate with options" do
39
+ should "display specified parameter in result" do
40
+ I18n.locale = :pl
41
+ assert_equal "Witaj John!", I18n.gettext("Hello {{who}}!", :who => "John")
42
+ end
43
+
44
+ should "display specified parameter when translation was not found" do
45
+ I18n.locale = :en
46
+ assert_equal "Hello Bill!", I18n.gettext("Hello {{who}}!", :who => "Bill")
35
47
  end
36
48
  end
37
49
 
@@ -43,19 +55,25 @@ class GettextI18nTest < Test::Unit::TestCase
43
55
  def self.test
44
56
  gettext('Test translation')
45
57
  end
58
+
59
+ def self.test2
60
+ gettext("Hello {{who}}!", :who => "John")
61
+ end
46
62
  end
47
63
 
48
- result = nil
64
+ results = []
49
65
  I18n.locale = :pl
50
66
 
51
67
  assert begin
52
- result = SampleFoo.test
68
+ results << SampleFoo.test
69
+ results << SampleFoo.test2
53
70
  true
54
71
  rescue
55
72
  false
56
73
  end
57
74
 
58
- assert_equal "Testowa translacja", result
75
+ assert_equal "Testowa translacja", results.first
76
+ assert_equal "Witaj John!", results.last
59
77
  end
60
78
 
61
79
  should "allow to use gettext methods in extended class and it singleton" do
data/test/locales/pl.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  pl:
2
2
  "Translation with mistake": "Poprawne tlumaczenie"
3
3
  "Test translation": "Testowa translacja"
4
+ "Hello {{who}}!": Witaj {{who}}!
4
5
  key_to_translate: "Sukces!"
5
6
  nested:
6
7
  translation: "Sukces!"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kriss-gettext_i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kriss Kowalik
@@ -27,6 +27,7 @@ files:
27
27
  - MIT-LICENSE
28
28
  - README.rdoc
29
29
  - CHANGELOG.rdoc
30
+ - TODO.rdoc
30
31
  - VERSION.yml
31
32
  - gettext_i18n.gemspec
32
33
  - init.rb