Class: ModpackLocalizer::SNBT::Performer
- Inherits:
-
Object
- Object
- ModpackLocalizer::SNBT::Performer
- Defined in:
- lib/modpack_localizer/snbt/performer.rb
Overview
.snbtの翻訳を実行するクラス
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::SNBT::Performer constructor
-
#perform(file_path, loggable: true) ⇒ void
.snbtファイルを翻訳して出力する.
-
#perform_directory(dir_path: "quests", loggable: true) ⇒ void
ディレクトリ内の.snbtファイルを翻訳して出力する.
-
#validate_path(path) ⇒ void
ファイルの存在性のバリデーション.
Constructor Details
#initialize(output_logs: true, except_words: [], language: "Japanese", display_help: true) ⇒ ModpackLocalizer::SNBT::Performer
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/modpack_localizer/snbt/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.
.snbtファイルを翻訳して出力する
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/modpack_localizer/snbt/performer.rb', line 42 def perform(file_path, loggable: true) @loggable = loggable file_path = File.(file_path) validate_path(file_path) @reader, @writer = ModpackLocalizer::SNBT::Reader.new(file_path), ModpackLocalizer::SNBT::Writer.new(file_path) results = @reader.extract_all.flatten (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: "quests", loggable: true) ⇒ void
This method returns an undefined value.
ディレクトリ内の.snbtファイルを翻訳して出力する
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/modpack_localizer/snbt/performer.rb', line 65 def perform_directory(dir_path: "quests", loggable: true) puts "Performing directory: #{dir_path}" unless loggable dir_path = File.(dir_path) validate_path(dir_path) # **でサブディレクトリも含めて取得 snbt_files = Dir.glob("#{dir_path}/**/*.snbt") if snbt_files.empty? puts "SNBT files not found in: #{dir_path}" return end snbt_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/snbt/performer.rb', line 84 def validate_path(path) path = File.(path) raise ModpackLocalizer::PathNotFoundError.new(path) unless File.exist?(path) end |