Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix a bug where empty locale files would prevent access to the base d…

…ata.
  • Loading branch information...
commit 7136b73d9d73a0e58adf950bcf746b339ce755a3 1 parent cfa1852
@jim authored
View
3  CHANGELOG.md
@@ -5,7 +5,8 @@
* Fix the name of Lima (goddamnhippie)
* Add south Sudan Swedish translation (barsoom)
* Add Russian translations of Russian Federation (Envek)
-* Fix a regression in the localization of Taiwan from the 1.0 rewrite
+* Fix a regression in the localization of Taiwan from the 1.0 rewrite.
+* Fix a bug where empty locale files would prevent access to the base data.
### 1.0.0 (April 20, 2013)
* Updated version numbering and pushed 1.0.0pre to v1.0.0.
View
11 lib/carmen/utils.rb
@@ -2,8 +2,11 @@ module Carmen
module Utils
# Merge an array of hashes deeply.
#
- # When a conflict occurs and either the old value or the new value don't
- # respond_to? :merge, the new value is used.
+ # When a conflict occurs:
+ # - if both the old value and the new value respond_to? :merge, they
+ # are recursively passed to deep_merge_hash and the result used.
+ # - if either doesn't respond_to? :merge, then the new value is used if
+ # it is not nil. If the new value is nil, the old value is used.
#
# Returns a meged hash.
def self.deep_hash_merge(hashes)
@@ -14,7 +17,7 @@ def self.deep_hash_merge(hashes)
if old_value.respond_to?(:merge) && new_value.respond_to?(:merge)
deep_hash_merge([old_value, new_value])
else
- new_value
+ new_value || old_value
end
}
}
@@ -23,7 +26,7 @@ def self.deep_hash_merge(hashes)
# Merge arrays of hashes using the specified keys.
#
# If two hashes have the same value for a key, they are merged together.
- # Otherwise, a new hash is appened to the array.
+ # Otherwise, a new hash is appended to the array.
#
# Matching arrays uses the keys in the order they are provided.
#
View
17 spec/carmen/i18n_spec.rb
@@ -79,4 +79,21 @@
end
end
+ describe 'overlaying empty files onto a locale' do
+ before do
+ @i18n.append_locale_path(carmen_spec_overlay_locale_path)
+ @i18n.locale = 'de'
+ end
+
+ after do
+ @i18n.locale = Carmen::I18n::Simple::DEFAULT_LOCALE
+ @i18n.reset!
+ end
+
+ it 'still has access to the base locale data' do
+ @i18n.t('world.eu.official_name').must_equal('Das großartige Staat von Eurasia')
+ end
+
+ end
+
end
View
12 spec/carmen/utils_spec.rb
@@ -23,5 +23,17 @@
merged.must_equal(expected)
end
+end
+
+describe 'Utils.deep_hash_merge' do
+
+ it 'merges hashes' do
+ first = { 'a' => 'old', 'b' => 'old', 'c' => 'old' }
+ second = { 'a' => nil, 'b' => 'new', 'd' => 'new' }
+
+ expected = { 'a' => 'old', 'b' => 'new', 'c' => 'old', 'd' => 'new' }
+
+ Carmen::Utils.deep_hash_merge([first, second]).must_equal(expected)
+ end
end
View
3  spec_data/overlay/locale/de/world.yml
@@ -0,0 +1,3 @@
+---
+de:
+ world:
Please sign in to comment.
Something went wrong with that request. Please try again.