Skip to content

Commit

Permalink
Fix language alpha3 util
Browse files Browse the repository at this point in the history
The documentation was misleading. Also rename to `language_alpha3` for
uniformity
  • Loading branch information
tagliala committed Sep 19, 2024
1 parent d47bb76 commit 1dd2ea7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/heathen/processor_methods/tesseract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def tesseract(format: nil)
expect_mime_type 'image/tiff'

# Lookup the ISO 639-2 (alpha-3) language object required by Tesseract
lang_alpha3 = Colore::Utils.lang_alpha3(job.language)
raise InvalidLanguageInStep.new(job.language) if lang_alpha3.nil?
language_alpha3 = Colore::Utils.language_alpha3(job.language)
raise InvalidLanguageInStep.new(job.language) if language_alpha3.nil?

target_file = temp_file_name
executioner.execute(
Colore::C_.tesseract_path,
job.content_file,
target_file,
'-l', lang_alpha3,
'-l', language_alpha3,
format
)
raise ConversionFailed.new(executioner.last_messages) if executioner.last_exit_status != 0
Expand Down
10 changes: 5 additions & 5 deletions lib/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def self.symbolize_keys(obj)
end
end

# Converts an ISO 639-1 (alpha-2) language code to its corresponding ISO 639-2 (alpha-3) code.
# Converts a language code to its corresponding ISO 639-2 (alpha-3) code.
#
# @param [String] lang_alpha2 The ISO 639-1 (alpha-2) language code.
# @return [String] The ISO 639-2 (alpha-3) language code, or `nil` if the alpha-2 code is not found.
def self.lang_alpha3(lang_alpha2)
ISO_639.find(lang_alpha2)&.alpha3
# @param [String] language The ISO 639-1 (alpha-2) or ISO 639-2 (alpha-3) language code.
# @return [String] The ISO 639-2 (alpha-3) language code, or `nil` if the code is not found.
def self.language_alpha3(language)
ISO_639.find(language)&.alpha3
end
end
end
4 changes: 2 additions & 2 deletions spec/lib/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
end
end

describe '.lang_alpha3' do
subject { described_class.lang_alpha3(language) }
describe '.language_alpha3' do
subject { described_class.language_alpha3(language) }

let(:language) { 'en' }

Expand Down

0 comments on commit 1dd2ea7

Please sign in to comment.