Skip to content

Commit

Permalink
store files directly in config/locales directory without subdirecto…
Browse files Browse the repository at this point in the history
…ries
  • Loading branch information
danielvysotskyi committed Jul 5, 2024
1 parent 6f62a5f commit d6a8673
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions lib/localize_ruby_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ def replace_translation_files(data)

def extract_entries(temp_file)
Zip::File.open(temp_file).each do |entry_file|
full_path_to_save = File.join(LocalizeRubyClient.config.locales_dir_path, entry_file.name)
directory_path = File.dirname(full_path_to_save)
FileUtils.mkdir_p(directory_path) unless File.directory?(directory_path)
# Use only the base name of the entry file to store it in the target directory
file_name = File.basename(entry_file.name)
full_path_to_save = File.join(LocalizeRubyClient.config.locales_dir_path, file_name)

# option { true } allows to replace file if it already exists
# Ensure the target directory exists
unless File.directory?(LocalizeRubyClient.config.locales_dir_path)
FileUtils.mkdir_p(LocalizeRubyClient.config.locales_dir_path)
end

# Extract the file to the target directory, replacing existing files if necessary
entry_file.extract(full_path_to_save) { true }
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/localize_ruby_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@

subject.update_translations

expect(File.exist?("#{described_class.config.locales_dir_path}/en/simple_form.en.yml")).to be true
expect(File.exist?("#{described_class.config.locales_dir_path}/fr/simple_form.fr.yml")).to be true
expect(File.exist?("#{described_class.config.locales_dir_path}/simple_form.en.yml")).to be true
expect(File.exist?("#{described_class.config.locales_dir_path}/simple_form.fr.yml")).to be true
end
end
end
Expand Down

0 comments on commit d6a8673

Please sign in to comment.