Class: ModpackLocalizer::QuestGiver::Performer
- Inherits:
-
Object
- Object
- ModpackLocalizer::QuestGiver::Performer
- Defined in:
- lib/modpack_localizer/quest_giver/performer.rb
Overview
Quest GiverのJSONファイルの翻訳を実行するクラス
Constant Summary collapse
- MAX_RETRIES =
8- BASE_DELAY =
5- MAX_SLEEP =
256
Instance Method Summary collapse
- #initialize(output_logs: true, except_words: [], language: "Japanese", display_help: true) ⇒ ModpackLocalizer::QuestGiver::Performer constructor
-
#perform(file_path, loggable: true) ⇒ void
Quest GiverのJSONファイルを翻訳して出力する.
-
#perform_directory(dir_path: "quest_giver", loggable: true) ⇒ void
ディレクトリ内のJSONファイルを翻訳して出力する.
-
#validate_path(path) ⇒ void
ファイルの存在性のバリデーション.
Constructor Details
#initialize(output_logs: true, except_words: [], language: "Japanese", display_help: true) ⇒ ModpackLocalizer::QuestGiver::Performer
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/modpack_localizer/quest_giver/performer.rb', line 23 def initialize(output_logs: true, except_words: [], language: "Japanese", display_help: true) TranslationAPI.configure do |config| config.output_logs = output_logs config.language = language.downcase config.except_words = except_words config.provider = ENV["PROVIDER"]&.to_sym || :openai config.custom_prompt = "Never translate property access. Example: obj.property.child" end @reader, @writer, @progress_bar, @loggable = nil ModpackLocalizer.help if display_help end |
Instance Method Details
#perform(file_path, loggable: true) ⇒ void
This method returns an undefined value.
Quest GiverのJSONファイルを翻訳して出力する
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/modpack_localizer/quest_giver/performer.rb', line 42 def perform(file_path, loggable: true) @loggable = loggable file_path = File.(file_path) validate_path(file_path) @reader = ModpackLocalizer::QuestGiver::Reader.new @writer = ModpackLocalizer::QuestGiver::Writer.new(file_path) results = @reader.extract_all(file_path) (file_path, results.length) if @loggable results.each do |result| result[:text] = retryable_translate(result[:text]) @writer.overwrites(result) @progress_bar.increment if @loggable end puts "Quest translation completed!" end |
#perform_directory(dir_path: "quest_giver", loggable: true) ⇒ void
This method returns an undefined value.
ディレクトリ内のJSONファイルを翻訳して出力する
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/modpack_localizer/quest_giver/performer.rb', line 66 def perform_directory(dir_path: "quest_giver", loggable: true) puts "Performing directory: #{dir_path}" unless loggable dir_path = File.(dir_path) validate_path(dir_path) json_files = Dir.glob("#{dir_path}/**/*.json") if json_files.empty? puts "JSON files not found in: #{dir_path}" return end json_files.each { |file_path| perform(file_path, loggable: loggable) } end |
#validate_path(path) ⇒ void
This method returns an undefined value.
ファイルの存在性のバリデーション
84 85 86 87 |
# File 'lib/modpack_localizer/quest_giver/performer.rb', line 84 def validate_path(path) path = File.(path) raise ModpackLocalizer::PathNotFoundError.new(path) unless File.exist?(path) end |