genki-merb_babel 0.1.1.0 → 0.1.1.1
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/m_i18n.rb +16 -7
- data/lib/merb_babel.rb +3 -3
- metadata +1 -1
data/Rakefile
CHANGED
data/lib/merb_babel/m_i18n.rb
CHANGED
@@ -1,30 +1,39 @@
|
|
1
1
|
module MI18n
|
2
2
|
|
3
3
|
def self.lookup(options)
|
4
|
-
|
4
|
+
keys = [options[:keys].map{|key| key.to_s}].flatten
|
5
5
|
language = options[:language]
|
6
6
|
country = options[:country]
|
7
|
+
|
7
8
|
raise ArgumentError, "You need to pass a language reference" unless language
|
8
|
-
raise ArgumentError, "You need to pass a localization key"
|
9
|
-
raise ArgumentError,
|
9
|
+
raise ArgumentError, "You need to pass a localization key" if keys.empty?
|
10
|
+
raise ArgumentError,
|
11
|
+
"language: #{language} not found" unless ML10n.localizations[language]
|
10
12
|
|
11
13
|
full_location = nil
|
12
|
-
full_location = lookup_with_full_locale(
|
14
|
+
full_location = lookup_with_full_locale(keys, language, country) if country
|
13
15
|
|
14
16
|
if full_location
|
15
17
|
return full_location
|
16
18
|
else
|
17
|
-
return
|
19
|
+
return lookup_with_language(keys, language) || keys.last
|
18
20
|
end
|
19
21
|
end
|
22
|
+
|
23
|
+
def self.lookup_with_language(keys, language)
|
24
|
+
lookup_with_hash(keys, ML10n.localizations[language])
|
25
|
+
end
|
20
26
|
|
21
|
-
def self.lookup_with_full_locale(
|
27
|
+
def self.lookup_with_full_locale(keys, language, country)
|
22
28
|
if ML10n.localizations.has_key?(language)
|
23
29
|
ML10n.localizations[language].has_key?(country) ?
|
24
|
-
ML10n.localizations[language][country]
|
30
|
+
lookup_with_hash(keys, ML10n.localizations[language][country]) : nil
|
25
31
|
else
|
26
32
|
nil
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
36
|
+
def self.lookup_with_hash(keys, l_hash)
|
37
|
+
keys.inject(l_hash){|h,k| h[k] rescue nil}
|
38
|
+
end
|
30
39
|
end
|
data/lib/merb_babel.rb
CHANGED
@@ -21,11 +21,11 @@ if defined?(Merb::Plugins)
|
|
21
21
|
module GlobalHelpers
|
22
22
|
|
23
23
|
# Used to translate words using localizations
|
24
|
-
def babelize(
|
24
|
+
def babelize(*args)
|
25
25
|
begin
|
26
|
-
options = args.
|
26
|
+
options = args.pop if args.last.kind_of?(Hash)
|
27
27
|
options ||= {}
|
28
|
-
options.merge!(:
|
28
|
+
options.merge!(:keys => args)
|
29
29
|
options.merge!(:language => language) unless options.has_key?(:language)
|
30
30
|
options.merge!(:country => country) unless options.has_key?(:country)
|
31
31
|
MI18n.lookup(options)
|