Class: ModpackLocalizer::QuestGiver::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/modpack_localizer/quest_giver/writer.rb

Overview

Quest GiverのJSONファイルに翻訳済みテキストを書き戻すクラス

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ ModpackLocalizer::QuestGiver::Writer

Parameters:

  • file_path (String)

    ファイルのパス



9
10
11
12
# File 'lib/modpack_localizer/quest_giver/writer.rb', line 9

def initialize(file_path)
  @input_file_path = file_path
  @output_file_path = file_path.gsub("quest_giver/", "output/quest_giver/")
end

Instance Method Details

#overwrites(translated_content) ⇒ void

This method returns an undefined value.

翻訳済みテキストでJSONを上書きする

Parameters:

  • translated_content (Hash)

    翻訳済みの内容



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/modpack_localizer/quest_giver/writer.rb', line 18

def overwrites(translated_content)
  FileUtils.mkdir_p(File.dirname(@output_file_path))

  json = JSON.parse(File.read(first_overwrite? ? @input_file_path : @output_file_path))
  keys = translated_content[:path].split(".")
  dig_and_set(json, keys, translated_content[:text])

  File.open(@output_file_path, "w") do |file|
    file.puts JSON.pretty_generate(json)
  end
end