Skip to content

Commit

Permalink
Updating territories to new global locale format
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron committed Jan 12, 2013
1 parent 63a1285 commit 22865b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/twitter_cldr.rb
Expand Up @@ -80,8 +80,8 @@ def with_locale(locale)
end

def register_locale_fallback(proc_or_locale)
case proc_or_locale.class.to_s
when "Symbol", "String", "Proc"
case proc_or_locale
when Symbol, String, Proc
locale_fallbacks << proc_or_locale
else
raise "A locale fallback must be of type String, Symbol, or Proc."
Expand Down
8 changes: 4 additions & 4 deletions lib/twitter_cldr/shared/territories.rb
Expand Up @@ -10,7 +10,7 @@ module Territories
class << self

def all
all_for(TwitterCldr.get_locale)
all_for(TwitterCldr.locale)
end

def all_for(code)
Expand All @@ -20,15 +20,15 @@ def all_for(code)
end

def from_territory_code(territory_code)
from_territory_code_for_locale(territory_code, TwitterCldr.get_locale)
from_territory_code_for_locale(territory_code, TwitterCldr.locale)
end

# Returns how to say a given territory in a given locale.
#
# This method does not work for three-digit United Nation "area
# codes" (UN M.49; for example, 014 for Eastern Africa and 419 for Latin
# America).
def from_territory_code_for_locale(territory_code, locale = TwitterCldr.get_locale)
def from_territory_code_for_locale(territory_code, locale = TwitterCldr.locale)
get_resource(locale)[:territories][TwitterCldr::Utils::Territories.normalize_territory_code(territory_code)]
rescue
nil
Expand All @@ -39,7 +39,7 @@ def from_territory_code_for_locale(territory_code, locale = TwitterCldr.get_loca
# This method does not work for three-digit United Nation "area
# codes" (UN M.49; for example, 014 for Eastern Africa and 419 for Latin
# America).
def translate_territory(territory_name, source_locale = :en, dest_locale = TwitterCldr.get_locale)
def translate_territory(territory_name, source_locale = :en, dest_locale = TwitterCldr.locale)
territory_code, _ = get_resource(source_locale)[:territories].find do |_, other_territory_name|
other_territory_name.downcase == territory_name.downcase
end
Expand Down
8 changes: 4 additions & 4 deletions spec/shared/territories_spec.rb
Expand Up @@ -32,14 +32,14 @@
Territories.translate_territory("RUSSIA", :en, :es).should match_normalized("Rusia")
end

it "defaults the destination language to English (or whatever FastGettext.locale is)" do
it "defaults the destination language to English (or whatever the global locale is)" do
Territories.translate_territory("Rusia", :es).should match_normalized("Russia")
Territories.translate_territory("Россия", :ru).should match_normalized("Russia")
end

it "defaults source and destination language to English if not given" do
Territories.translate_territory("Russia").should match_normalized("Russia")
FastGettext.locale = :es
TwitterCldr.locale = :es
Territories.translate_territory("Russia").should match_normalized("Rusia")
end

Expand Down Expand Up @@ -73,7 +73,7 @@
it "should return the language in the default locale for the given locale code" do
Territories.from_territory_code(:ES).should match_normalized("Spain")
Territories.from_territory_code(:RU).should match_normalized("Russia")
FastGettext.locale = :es
TwitterCldr.locale = :es
Territories.from_territory_code(:ES).should match_normalized("España")
end
end
Expand All @@ -98,7 +98,7 @@
territories[:ru].should match_normalized("Russia")
territories[:de].should match_normalized("Germany")

FastGettext.locale = :es
TwitterCldr.locale = :es
territories = Territories.all
territories.should be_a(Hash)
territories[:ru].should match_normalized("Rusia")
Expand Down

0 comments on commit 22865b9

Please sign in to comment.