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 +20 -20
- data/TODO.rdoc +6 -0
- data/VERSION.yml +1 -1
- data/gettext_i18n.gemspec +2 -1
- data/lib/globalize/backend/gettext.rb +1 -1
- data/lib/rails/extend.rb +27 -2
- data/test/gettext_i18n_test.rb +22 -4
- data/test/locales/pl.yml +1 -0
- metadata +2 -1
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-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
data/VERSION.yml
CHANGED
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.
|
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',
|
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.
|
7
|
-
|
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
|
data/test/gettext_i18n_test.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
64
|
+
results = []
|
49
65
|
I18n.locale = :pl
|
50
66
|
|
51
67
|
assert begin
|
52
|
-
|
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",
|
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
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.
|
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
|