From 78419d697f2dc85396aec519d0c3d1581d6040ba Mon Sep 17 00:00:00 2001 From: Eliran Turgeman Date: Sun, 5 Aug 2012 15:32:44 +0300 Subject: [PATCH] handles duplicate locales caused in case the i18n returns symbols --- lib/copycopter_client/i18n_backend.rb | 2 +- spec/copycopter_client/i18n_backend_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/copycopter_client/i18n_backend.rb b/lib/copycopter_client/i18n_backend.rb index 048a89b..9d8811d 100644 --- a/lib/copycopter_client/i18n_backend.rb +++ b/lib/copycopter_client/i18n_backend.rb @@ -34,7 +34,7 @@ def translate(locale, key, options = {}) # Returns locales availabile for this Copycopter project. # @return [Array] available locales def available_locales - cached_locales = cache.keys.map { |key| key.split('.').first } + cached_locales = cache.keys.map { |key| key.split('.').first.to_sym } (cached_locales + super).uniq.map { |locale| locale.to_sym } end diff --git a/spec/copycopter_client/i18n_backend_spec.rb b/spec/copycopter_client/i18n_backend_spec.rb index 33d6a15..79da142 100644 --- a/spec/copycopter_client/i18n_backend_spec.rb +++ b/spec/copycopter_client/i18n_backend_spec.rb @@ -50,6 +50,14 @@ def build_backend subject.available_locales.should =~ [:en, :es, :fr] end + it "handles symbol locales from i18n gem" do + YAML.stubs(:load_file => { :en => { 'key' => 'value' } }) + I18n.stubs(:load_path => ["test.yml"]) + + cache['en.key'] = '' + + subject.available_locales.should =~ [:en] + end it "queues missing keys with default" do default = 'default value'