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 CHANGED
@@ -5,7 +5,7 @@ require 'merb-core'
5
5
  require 'merb-core/tasks/merb'
6
6
 
7
7
  GEM_NAME = "merb_babel"
8
- GEM_VERSION = "0.1.1.0"
8
+ GEM_VERSION = "0.1.1.1"
9
9
  AUTHOR = "Matt Aimonetti"
10
10
  EMAIL = "mattaimonetti@gmail.com"
11
11
  HOMEPAGE = "http://github.com/mattetti/merb_babel/"
@@ -1,30 +1,39 @@
1
1
  module MI18n
2
2
 
3
3
  def self.lookup(options)
4
- key = options[:key].to_s
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" unless key
9
- raise ArgumentError, "language: #{language} not found" unless ML10n.localizations[language]
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(key, language, country) if country
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 ML10n.localizations[language][key] || key
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(key, language, country)
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][key.to_s] : nil
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(key, *args)
24
+ def babelize(*args)
25
25
  begin
26
- options = args.first
26
+ options = args.pop if args.last.kind_of?(Hash)
27
27
  options ||= {}
28
- options.merge!(:key => key)
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genki-merb_babel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.0
4
+ version: 0.1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Aimonetti