Skip to content

Commit

Permalink
Fix bug when YAML is commented and only the language key is present
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHoste committed Feb 9, 2024
1 parent c12d760 commit 31faa13
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/translation_io/yaml_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/support/data/commented.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
# devise:
# confirmations:
# confirmed: "Your email address has been successfully confirmed."
Empty file removed spec/support/data/empty.yml
Empty file.
7 changes: 7 additions & 0 deletions spec/translation/yaml_conversion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 31faa13

Please sign in to comment.