Skip to content

Commit

Permalink
Merge pull request #316 from ifad/bugfix/166-force-english-when-langu…
Browse files Browse the repository at this point in the history
…age-is-nil

Force language to English when it is nil
  • Loading branch information
tagliala authored Sep 27, 2024
2 parents b5e4b3b + dfccd72 commit f83f89f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
10 changes: 6 additions & 4 deletions lib/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def initialize(storage_dir: C_.storage_directory, logger: Logger.new(C_.conversi
# @param version [String] the file version
# @param filename [String] the name of the file to convert
# @param action [String] the conversion to perform
# @param language [String] the file's language. Forced to `en` if `nil`
# @return the converted file name
def convert(doc_key, version, filename, action)
def convert(doc_key, version, filename, action, language = nil)
language ||= 'en'
doc = Document.load @storage_dir, doc_key
ignore, orig_content = doc.get_file(version, filename)
language = 'en' # TODO: add to spec and upload
new_content = convert_file action, orig_content, language
# TODO: handling for variant formats with the same extension
# probably by adding format info before suffix
Expand All @@ -37,9 +38,10 @@ def convert(doc_key, version, filename, action)
# Converts the supplied content. Nothing gets saved.
# @param action [String] the conversion to perform
# @param orig_content [String] the body of the file to convert
# @param language [String] the file's language
# @param language [String] the file's language. Forced to `en` if `nil`
# @return [String] the converted file body
def convert_file(action, orig_content, language = 'en')
def convert_file(action, orig_content, language = nil)
language ||= 'en'
Heathen::Converter.new(logger: @logger).convert(action, orig_content, language)
rescue Heathen::TaskNotFound => e
raise InvalidAction.new(e.message)
Expand Down
5 changes: 3 additions & 2 deletions lib/heathen/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def initialize(logger: Logger.new(nil))
# Converts the given document according to the action requested.
# @param action [String] the conversion action to perform
# @param content [String] the document body to be converted
# @param language [String] the document language (defaults to 'en')
# @param language [String] the file's language. Forced to `en` if `nil`
# @return [String] the converted document body
def convert(action, content, language = 'en')
def convert(action, content, language = nil)
language ||= 'en'
job = Job.new action, content, language
processor = Heathen::Processor.new job: job, logger: @logger
begin
Expand Down
6 changes: 3 additions & 3 deletions lib/heathen/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class Job
# Constructs a new job
# @param action [String] the action to be performed
# @param content [String] the file body
# @param language [String] the file's language
# @param language [String] the file's language. Forced to `en` if `nil`
# @param sandbox_dir [String] sandbox directory for temporary files
def initialize(action, content, language = 'en', sandbox_dir = nil)
def initialize(action, content, language = nil, sandbox_dir = nil)
@action = action
@language = language
@language = language || 'en'
@original_content = content
@original_mime_type = content.mime_type
self.content = @original_content
Expand Down
5 changes: 3 additions & 2 deletions lib/legacy_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ def initialize(storage_dir = C_.storage_directory)
# Converts the given file and stores it in the legacy directory
# @param action [String] the conversion to perform
# @param orig_content [String] the body of the file to convert
# @param language [String] the file's language
# @param language [String] the file's language. Forced to `en` if `nil`
# @return [String] the path to the converted file
def convert_file(action, orig_content, language = 'en')
def convert_file(action, orig_content, language = nil)
language ||= 'en'
content = Heathen::Converter.new.convert(action, orig_content, language)
filename = Digest::SHA2.hexdigest content
store_file filename, content
Expand Down

0 comments on commit f83f89f

Please sign in to comment.