air18n 0.1.55 → 0.1.56

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/lib/air18n.rb CHANGED
@@ -16,10 +16,6 @@ module Air18n
16
16
 
17
17
  def self.included(base)
18
18
  base.class_eval do
19
- # Currencies that correspond to users who want distance unit to be
20
- # miles.
21
- self.const_set(:MILES_CURRENCIES, ['USD', 'GBP'])
22
-
23
19
  class << self
24
20
  extend ActiveSupport::Memoizable
25
21
 
@@ -50,10 +46,6 @@ module Air18n
50
46
  @currency = 'USD'
51
47
  attr_reader :currency
52
48
 
53
- # Distance unit, 'MI' or 'KM'.
54
- @distance_unit = 'KM'
55
- attr_reader :distance_unit
56
-
57
49
  # Cache used to store translation data from the database.
58
50
  attr_accessor :cache
59
51
 
@@ -57,6 +57,20 @@ module Air18n
57
57
  ret
58
58
  end
59
59
 
60
+ # Returns whether or not imperial lengths are appropriate under
61
+ # I18n.full_locale and I18n.tld_country.
62
+ def uses_imperial_lengths?
63
+ uses_imperial_lengths_in_locale_and_country(I18n.full_locale, I18n.tld_country)
64
+ end
65
+
66
+ # Returns whether or not imperial lengths are appropriate for given locale
67
+ # and country.
68
+ # Logic is: true in the US and UK when language is English, and false
69
+ # otherwise.
70
+ def uses_imperial_lengths_in_locale_and_country?(locale, country)
71
+ language_from_locale(locale) == :en && [:US, :GB].include?(country)
72
+ end
73
+
60
74
  # Like ActionView::Helpers::TextHelper#pluralize, except requires that
61
75
  # 'count' be a real number, not a string.
62
76
  #
@@ -278,7 +292,6 @@ module Air18n
278
292
 
279
293
  def currency=(c)
280
294
  @currency = c
281
- @distance_unit = self::MILES_CURRENCIES.include?(c) ? "MI" : "KM"
282
295
  end
283
296
 
284
297
  # Parses a date using the current locale setting.
@@ -1,3 +1,3 @@
1
1
  module Air18n
2
- VERSION = "0.1.55"
2
+ VERSION = "0.1.56"
3
3
  end
@@ -44,6 +44,13 @@ describe Air18n do
44
44
  end
45
45
  end
46
46
 
47
+ context 'uses_imperial_lengths?' do
48
+ I18n.uses_imperial_lengths_in_locale_and_country?(:en, :US).should == true
49
+ I18n.uses_imperial_lengths_in_locale_and_country?(:en, :GB).should == true
50
+ I18n.uses_imperial_lengths_in_locale_and_country?(:en, :AU).should == false
51
+ I18n.uses_imperial_lengths_in_locale_and_country?(:fr, :US).should == false
52
+ end
53
+
47
54
  context 'Keeping track of default routes context' do
48
55
  it 'should start with blank routes context' do
49
56
  I18n.translate('default route, key 1', :default => 'value 1', :locale => :en)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: air18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.55
4
+ version: 0.1.56
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-01-23 00:00:00.000000000 Z
16
+ date: 2013-01-28 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: i18n