From 0639629ebb38505016c0ce47f2c22649cbdb7dca Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Thu, 28 Mar 2024 11:59:01 +0900 Subject: [PATCH] Allow CSV files for glossary --- src/deepl/app.cr | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/deepl/app.cr b/src/deepl/app.cr index 6cadcb0..a81c049 100644 --- a/src/deepl/app.cr +++ b/src/deepl/app.cr @@ -72,6 +72,9 @@ module DeepL end def set_glossary_id_from_name + return unless option.glossary_id.nil? + return if option.glossary_name.nil? + glossary_name = option.glossary_name translator = DeepL::Translator.new glossary_list = translator.glossary_list @@ -162,12 +165,27 @@ module DeepL def create_glossary # FIXME check TSV file format + + entry_format = "tsv" + + # A corner case still not handled: + # Standard input is CSV file format + + if option.glossary_name.nil? && ARGV.size == 1 + name = ARGV[0] + entry_format = File.extname(name).sub(".", "").downcase + name = File.basename(name, File.extname(name)) + option.glossary_name = name + end option.input_text = ARGF.gets_to_end translator = DeepL::Translator.new translator.create_glossary( - option.glossary_name, option.source_lang, option.target_lang, - option.input_text + name: option.glossary_name, + source_lang: option.source_lang, + target_lang: option.target_lang, + entries: option.input_text, + entry_format: entry_format ) end