Class: ModpackLocalizer::SNBT::Performer
- Inherits:
-
Object
- Object
- ModpackLocalizer::SNBT::Performer
- Defined in:
- lib/modpack_localizer/snbt/performer.rb
Overview
.snbtの翻訳を実行するクラス JpTranslatorFromGptを使用して翻訳を行う
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
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/modpack_localizer/snbt/performer.rb', line 17 def initialize(output_logs: true, except_words: [], language: "Japanese", display_help: true) @translator = JpTranslatorFromGpt::Translator.new( output_logs: output_logs, except_words: except_words, exchange_language: language ) @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ファイルを翻訳して出力する
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/modpack_localizer/snbt/performer.rb', line 33 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] = @translator.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ファイルを翻訳して出力する
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/modpack_localizer/snbt/performer.rb', line 56 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.
ファイルの存在性のバリデーション
75 76 77 78 |
# File 'lib/modpack_localizer/snbt/performer.rb', line 75 def validate_path(path) path = File.(path) raise ModpackLocalizer::PathNotFoundError.new(path) unless File.exist?(path) end |