genki-merb_babel 0.1.2.1 → 0.1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/merb_babel.rb +2 -2
- data/lib/merb_babel/m_i18n.rb +3 -0
- data/lib/merb_babel/m_l10n.rb +4 -3
- data/spec/m_i18n_spec.rb +8 -0
- metadata +1 -1
data/Rakefile
CHANGED
data/lib/merb_babel.rb
CHANGED
data/lib/merb_babel/m_i18n.rb
CHANGED
@@ -7,6 +7,9 @@ module MI18n
|
|
7
7
|
|
8
8
|
raise ArgumentError, "You need to pass a language reference" unless language
|
9
9
|
raise ArgumentError, "You need to pass a localization key" if keys.empty?
|
10
|
+
unless ML10n.localizations[language]
|
11
|
+
language = Merb::Plugins.config[:merb_babel][:default_language]
|
12
|
+
end
|
10
13
|
raise ArgumentError,
|
11
14
|
"language: #{language} not found" unless ML10n.localizations[language]
|
12
15
|
|
data/lib/merb_babel/m_l10n.rb
CHANGED
@@ -106,7 +106,10 @@ module ML10n
|
|
106
106
|
table_for = proc do |table_name, key, default|
|
107
107
|
keys = ["DateFormat", table_name]
|
108
108
|
table = MI18n.lookup(options.merge(:keys => keys)) || {}
|
109
|
-
table
|
109
|
+
case table
|
110
|
+
when Hash, Array; table[key] || default
|
111
|
+
else default
|
112
|
+
end
|
110
113
|
end
|
111
114
|
format = format.to_s.dup
|
112
115
|
format.gsub!(/%a/) do
|
@@ -146,7 +149,5 @@ module ML10n
|
|
146
149
|
end
|
147
150
|
end
|
148
151
|
end
|
149
|
-
|
150
152
|
end
|
151
|
-
|
152
153
|
end
|
data/spec/m_i18n_spec.rb
CHANGED
@@ -53,6 +53,7 @@ describe '#babelize' do
|
|
53
53
|
it "should translate with domain" do
|
54
54
|
@c.t(:night, :greetings, :language => 'en').should == 'Good evening'
|
55
55
|
@c.t(:night, :greetings, :language => 'ja').should == 'こんばんわ'
|
56
|
+
@c.t(:night, :greetings, :language => 'tlh').should == 'Good evening'
|
56
57
|
end
|
57
58
|
|
58
59
|
it "should localize date" do
|
@@ -72,8 +73,15 @@ describe '#babelize' do
|
|
72
73
|
time = Time.now
|
73
74
|
if time.hour < 12
|
74
75
|
@c.t("%p", time, :language => "ja").should == "午前"
|
76
|
+
@c.t("%p", time, :language => "en").should == "AM"
|
75
77
|
else
|
76
78
|
@c.t("%p", time, :language => "ja").should == "午後"
|
79
|
+
@c.t("%p", time, :language => "en").should == "PM"
|
77
80
|
end
|
78
81
|
end
|
82
|
+
|
83
|
+
it "should localize time by using default yml if correct one is lacking" do
|
84
|
+
date = Date.new(2009,1,1)
|
85
|
+
@c.t("%B", date, :language => 'tlh').should == "January"
|
86
|
+
end
|
79
87
|
end
|