Skip to content

Commit

Permalink
Better bugfix for empty YAML files (only the language prefix)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHoste committed Feb 9, 2024
1 parent 5b33dcd commit 832762e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run(params)
TranslationIO.info file_path, 2, 2
file_translations = TranslationIO.yaml_load(File.read(file_path))

unless file_translations.blank?
if file_translations.present? && file_translations.values.all? { |value| value.present? }
all_translations = all_translations.deep_merge(file_translations)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def run(params)
TranslationIO.info file_path, 2, 2
file_translations = TranslationIO.yaml_load(File.read(file_path))

unless file_translations.blank?
if file_translations.present? && file_translations.values.all? { |value| value.present? }
all_translations = all_translations.deep_merge(file_translations)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/translation_io/yaml_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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 && translations.values.all? { |value| value.present? }
if translations.present? && translations.values.all? { |value| value.present? }
return FlatHash.to_flat_hash(translations)
else # loading an empty file, or file with only the language, returns false
return {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@
EOS
end

File.open('tmp/config/locales/fr.yml', 'wb') do |file|
File.open("tmp/config/locales/empty.en.yml", 'wb') do |file|
file.write <<-EOS
---
en:
EOS
end

File.open('tmp/config/locales/fr.yml', 'wb') do |file|
file.write <<-EOS
---
fr:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
EOS
end

File.open("#{yaml_locales_path}/empty.en.yml", 'wb') do |file|
file.write <<-EOS
---
en:
EOS
end

source_locale = 'en'
yaml_file_paths = Dir["#{yaml_locales_path}/*.yml"]

Expand Down

0 comments on commit 832762e

Please sign in to comment.