diff --git a/lib/translation_io/yaml_conversion.rb b/lib/translation_io/yaml_conversion.rb index 34c9c4f..9c2d775 100644 --- a/lib/translation_io/yaml_conversion.rb +++ b/lib/translation_io/yaml_conversion.rb @@ -28,9 +28,9 @@ def get_flat_translations_for_yaml_file(file_path) def get_flat_translations_for_yaml_data(yaml_data) translations = TranslationIO.yaml_load(yaml_data) - if translations + if translations && translations.values.all? { |value| value.present? } return FlatHash.to_flat_hash(translations) - else # loading an empty file returns false + else # loading an empty file, or file with only the language, returns false return {} end end diff --git a/spec/support/data/commented.en.yml b/spec/support/data/commented.en.yml new file mode 100644 index 0000000..b020394 --- /dev/null +++ b/spec/support/data/commented.en.yml @@ -0,0 +1,4 @@ +en: +# devise: +# confirmations: +# confirmed: "Your email address has been successfully confirmed." diff --git a/spec/support/data/empty.yml b/spec/support/data/empty.yml deleted file mode 100644 index e69de29..0000000 diff --git a/spec/translation/yaml_conversion_spec.rb b/spec/translation/yaml_conversion_spec.rb index ab24e5d..fe2976a 100644 --- a/spec/translation/yaml_conversion_spec.rb +++ b/spec/translation/yaml_conversion_spec.rb @@ -117,6 +117,13 @@ result.should == {} end + + it 'returns an empty Hash if the YAML file is commented (bug fix)' do + yaml_path = 'spec/support/data/commented.en.yml' + result = subject.get_flat_translations_for_yaml_file(yaml_path) + + result.should == {} + end end describe '#get_yaml_data_from_flat_translations' do