Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- ==============================================================================
- ■ Localization Tool (Holy87)
- version 1.0.1
- User difficulty: ★
- License: CC-BY. Everyone can distribute this script and use in their free
- and commercial games. Credit required.
- ==============================================================================
- This script automatically localize a completed project, creating a specific
- language file.
- ==============================================================================
- ■ Compatibility
- Requires the localization script.
- ==============================================================================
- ■ Installation & Instructions
- ● Install this script under Materials and Localization script and before the Main.
- ● Make sure to have created the Localization folder in the project root.
- ● MAKE A BACKUP COPY. The tool will modify definitely ALL the dialogues, so
- be sure to have a copy of the project in case something will be wrong.
- ● Start the game in TEST mode, then in the title screen press LEFT+ESC.
- Select a language in which will be created the localization file (if
- there aren't select other, then you can configure the header manually
- later).
- ● At the end of the operation, the language file will be created.
- ● IMPORTANT: Just the conversion end, close RPG Maker WITHOUT saving
- (otherwise the changes will be overriden), then reopen the project.
- ■ What the tool does
- ● Creates a language file in Localization folder, with proper header and strings
- ● Fetches all the database and writes all the heroes, classes, skills, items,
- weapons, armors, enemies and states informations
- gli eroi, classi, skill, oggetti, armi, armature, nemici e stati
- ● Searches in all maps, battles and common events all the dialogues and, when
- it finds them, it creates the string with the key inside the file and
- EDITS the dialog with the created string key.
- ● Writes the map names also.
- ■ What not does the tool
- ● Traduction. There's no traduction, once created the localization, you
- must translate every string of the file for the other languages.
- ● Create a localization for script strings. I'm sorry, but this is a job
- that you must do manually.
- ==============================================================================
- =end
- module LocalizationOptions
- #--------------------------------------------------------------------------
- # * Languages of the menu. It's just a convenience to create languages already
- # with the header configured. The Other command creates the language file,
- # but you must edit the header manually.
- #--------------------------------------------------------------------------
- LANGUAGES = {
- #ID #short #complete name
- 1033 => ["en", "English"], #english-united states
- 1040 => ["it", "Italiano"], #traditional italian
- 1036 => ["fr", "Français"], #french
- 1031 => ["de", "Deutsch"], #german
- 1034 => ["es", "Español"], #spanish
- 1030 => ["da", "Danske"], #danish
- 1026 => ["bg-BG" "Belgian"], #belgian
- 1027 => ["ca-ES" "Català"], #catalan
- 1041 => ["jp", "日本 - 日本語"], #japanese
- 1042 => ["ko", "한국의"], #korean
- 1049 => ["ru", "Pусский"], #russian
- 2055 => ["de-BG", "Deutsch - Schweizer"], #german-swiss
- 4103 => ["de-LU", "Deutsch - Luxemburg"], #german-luxemburg
- 2057 => ["en-UL", "English - UK"], #english-united kingdom
- 3081 => ["en-AU", "English - Australia"], #english-australian
- 4105 => ["en-CA", "English - Canada"], #english-canadian
- 5129 => ["en-NZ", "English - New Zeland"],#english-new zeland
- 2058 => ["es-MX", "Español - México"], #spanish-mexico
- 11274 => ["es-AR", "Español - Cile"], #spanish-cile
- 2060 => ["fr-BE", "Français - Belgique"], #french-belgium
- 4108 => ["fr-CH", "Français - Suisse"], #french-swiss
- 2064 => ["it-CH", "Italiano - Svizzera"], #italian-swiss
- 0 => ["na", "Other"], #other language to configure manually
- }
- #--------------------------------------------------------------------------
- # * Vocables
- #--------------------------------------------------------------------------
- VOCABS = {
- :start => "Start the conversion",
- :select=> "Language select",
- :exit => "Exit",
- :wait => "File creation %s done...",
- :done => "Language creation completed.",
- }
- #--------------------------------------------------------------------------
- # * The string keys that will be generated.
- #--------------------------------------------------------------------------
- STRING = "Map[%03d] Ev[%03d] Page %02d Line %d"
- CHOICE = "Map[%03d] Ev[%03d] Page %02d Line %d - %d"
- BATTLE = "Troop[%03d] Page %02d Line %d"
- BATTLC = "Troop[%03d] Page %02d Line %d - %d"
- COMMON = "C. Ev[%03d] Line %d"
- COMMOC = "C. Ev[%03d] Line %d - %d"
- MAPNAM = "Map[%03d] Name"
- #--------------------------- END OF THE SCRIPT ------------------------------
- #--------------------------------------------------------------------------
- # * Returns the proper vocab
- #--------------------------------------------------------------------------
- def vocab(vocab_id)
- return VOCABS[vocab_id]
- end
- end
- #==============================================================================
- # ** Scene_Localization
- #------------------------------------------------------------------------------
- # Scene for localization tool
- #==============================================================================
- class Scene_Localization < Scene_MenuBase
- include LocalizationOptions
- #--------------------------------------------------------------------------
- # * start
- #--------------------------------------------------------------------------
- def start
- super
- create_localization_window
- create_language_window
- create_popup_window
- end
- #--------------------------------------------------------------------------
- # * localization window creation
- #--------------------------------------------------------------------------
- def create_localization_window
- @localization_window = Window_LocalizationInfo.new
- @localization_window.set_handler(:start, method(:open_language))
- @localization_window.set_handler(:cancel, method(:return_scene))
- @localization_window.activate
- end
- #--------------------------------------------------------------------------
- # * language list windows creation
- #--------------------------------------------------------------------------
- def create_language_window
- x = @localization_window.x
- @language_window = Window_LanguageList.new(x, 0, 250, Graphics.height)
- @language_window.set_handler(:ok, method(:start_creation))
- @language_window.set_handler(:cancel, method(:open_localization))
- end
- #--------------------------------------------------------------------------
- # * popup window creation
- #--------------------------------------------------------------------------
- def create_popup_window
- @popup_window = Window_ToolPpup.new
- @popup_window.set_pressure_method(method(:process_done))
- end
- #--------------------------------------------------------------------------
- # * start creation
- #--------------------------------------------------------------------------
- def start_creation
- @language_window.openness = 0
- @popup_window.visible = true
- @popup_window.set_text(vocab(:wait))
- Graphics.update
- localization_tool = Loc_Tool.new(@language_window.item)
- localization_tool.start_creating
- @popup_window.activate
- @popup_window.set_text(sprintf(vocab(:done), localization_tool.file_name))
- end
- #--------------------------------------------------------------------------
- # * language selection process
- #--------------------------------------------------------------------------
- def open_language
- @localization_window.close
- @language_window.open
- @language_window.activate
- end
- #--------------------------------------------------------------------------
- # * localization process (back)
- #--------------------------------------------------------------------------
- def open_localization
- @language_window.close
- @localization_window.open
- @localization_window.activate
- end
- #--------------------------------------------------------------------------
- # * localization done
- #--------------------------------------------------------------------------
- def process_done
- @popup_window.visible = false
- @popup_window.deactivate
- @localization_window.open
- @localization_window.activate
- end
- end
- #==============================================================================
- # ** Window_LocalizationInfo
- #------------------------------------------------------------------------------
- # window for localization commands
- #==============================================================================
- class Window_LocalizationInfo < Window_Command
- include LocalizationOptions
- #--------------------------------------------------------------------------
- # * initialize
- #--------------------------------------------------------------------------
- def initialize
- super(0, 0)
- update_placement
- self.openness = 0
- open
- end
- #--------------------------------------------------------------------------
- # * Get Window Width
- #--------------------------------------------------------------------------
- def window_width
- return 250
- end
- #--------------------------------------------------------------------------
- # * Update Window Position
- #--------------------------------------------------------------------------
- def update_placement
- self.x = (Graphics.width - width) / 2
- self.y = (Graphics.height * 1.6 - height) / 2
- end
- #--------------------------------------------------------------------------
- # * Create Command List
- #--------------------------------------------------------------------------
- def make_command_list
- add_command(vocab(:start), :start)
- add_command(vocab(:exit), :cancel)
- end
- end
- #==============================================================================
- # ** Window_LanguageList
- #------------------------------------------------------------------------------
- # Shows the list of avaiable language for this tool
- #==============================================================================
- class Window_LanguageList < Window_Selectable
- include LocalizationOptions
- #--------------------------------------------------------------------------
- # * Object initialization
- #--------------------------------------------------------------------------
- def initialize(x, y, width, height)
- super
- make_language_list
- create_contents
- refresh
- self.index = 0
- self.openness = 0
- end
- #--------------------------------------------------------------------------
- # * Make language list
- #--------------------------------------------------------------------------
- def make_language_list
- @data = get_languages(LANGUAGES)
- end
- #--------------------------------------------------------------------------
- # * Get Number of Items
- #--------------------------------------------------------------------------
- def item_max
- @data ? @data.size : 0
- end
- #--------------------------------------------------------------------------
- # * draw_item
- # index: indice dell
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- if item
- rect = item_rect(index)
- rect.width -= 4
- draw_text(rect, item.name)
- end
- end
- #--------------------------------------------------------------------------
- # * Selected item
- #--------------------------------------------------------------------------
- def item
- return @data[@index]
- end
- #--------------------------------------------------------------------------
- # * Get all languages
- #--------------------------------------------------------------------------
- def get_languages(hash)
- ary = []
- hash.each_pair do |a, b|
- ary.push(Language.new(a, b[0], b[1]))
- end
- return ary
- end
- end
- #==============================================================================
- # ** Window_ToolPpup
- #------------------------------------------------------------------------------
- # Window that appears when the localization is finished
- #==============================================================================
- class Window_ToolPpup < Window_Base
- #--------------------------------------------------------------------------
- # * Object initialization
- #--------------------------------------------------------------------------
- def initialize
- super(0,0,0,line_height + standard_padding*2)
- deactivate
- self.visible = false
- end
- #--------------------------------------------------------------------------
- # * Set new text
- # text = new text
- #--------------------------------------------------------------------------
- def set_text(text)
- width = text_size(text).width + self.padding*2
- self.width = width
- x = (Graphics.width - width)/2
- y = (Graphics.height - height)/2
- @text = text
- refresh
- end
- #--------------------------------------------------------------------------
- # * set the method launched when pressing :C
- #--------------------------------------------------------------------------
- def set_pressure_method(mth)
- @method = mth
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- create_contents
- return if @text.nil?
- draw_text(0,0,contents_width, line_height, @text)
- end
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- super
- check_pressure if self.active == true
- end
- #--------------------------------------------------------------------------
- # * Pressure check
- #--------------------------------------------------------------------------
- def check_pressure
- return unless @method
- @method.call if Input.trigger?(:C) or Input.trigger?(:B)
- end
- end
- #==============================================================================
- # ** Loc_Tool
- #------------------------------------------------------------------------------
- # Localization class that parses all the game and creates the file.
- #==============================================================================
- class Loc_Tool
- include LocalizationOptions
- #--------------------------------------------------------------------------
- # * Object initialization
- # language: language object
- #--------------------------------------------------------------------------
- def initialize(language)
- @id = language.id
- @short = language.short
- @name = language.name
- end
- #--------------------------------------------------------------------------
- # * Returns the language file name
- #--------------------------------------------------------------------------
- def file_name
- H87Localization.language_folder+"/#{@short}.ini"
- end
- #--------------------------------------------------------------------------
- # * Creation process
- #--------------------------------------------------------------------------
- def start_creating
- File.open(file_name,"w") do |file|
- file.write(header)
- file.write(actors)
- file.write(classes)
- file.write(skills)
- file.write(items)
- file.write(weapons)
- file.write(armors)
- file.write(enemies)
- file.write(states)
- file.write(terms)
- file.write(dialogs)
- end
- end
- #--------------------------------------------------------------------------
- # * Header creation
- #--------------------------------------------------------------------------
- def header
- mp = Mark_Parser.new("header")
- mp.add_item("Language",@name)
- mp.add_item("ID",@id)
- return mp.to_s
- end
- #--------------------------------------------------------------------------
- # * Actors list creation
- #--------------------------------------------------------------------------
- def actors
- attributes = [:id, :name, :nickname, :description]
- return attr_process("actors",$data_actors,attributes)
- end
- #--------------------------------------------------------------------------
- # * Classes list creation
- #--------------------------------------------------------------------------
- def classes
- attributes = [:id, :name]
- return attr_process("classes",$data_classes,attributes)
- end
- #--------------------------------------------------------------------------
- # * Skills list creation
- #--------------------------------------------------------------------------
- def skills
- attributes = [:id, :name, :description, :message1, :message2]
- return attr_process("skills",$data_skills,attributes)
- end
- #--------------------------------------------------------------------------
- # * Items list creation
- #--------------------------------------------------------------------------
- def items
- attributes = [:id, :name, :description]
- return attr_process("items",$data_items,attributes)
- end
- #--------------------------------------------------------------------------
- # * Weapons list creation
- #--------------------------------------------------------------------------
- def weapons
- attributes = [:id, :name, :description]
- return attr_process("weapons",$data_weapons,attributes)
- end
- #--------------------------------------------------------------------------
- # * Armors list creation
- #--------------------------------------------------------------------------
- def armors
- attributes = [:id, :name, :description]
- return attr_process("armors",$data_armors,attributes)
- end
- #--------------------------------------------------------------------------
- # * Enemies list creation
- #--------------------------------------------------------------------------
- def enemies
- attributes = [:id, :name]
- return attr_process("enemies",$data_enemies,attributes)
- end
- #--------------------------------------------------------------------------
- # * States list creation
- #--------------------------------------------------------------------------
- def states
- attributes = [:id, :name, :message1, :message2, :message3, :message4]
- return attr_process("states",$data_states,attributes)
- end
- #--------------------------------------------------------------------------
- # * Terms list creation
- #--------------------------------------------------------------------------
- def terms
- terms = $data_system.terms
- mp = Mark_Parser.new("params")
- for i in 0..terms.basic.size-1
- mp.add_item(i, terms.params[i])
- end
- mp2 = Mark_Parser.new("basic")
- for i in 0..terms.basic.size-1
- mp2.add_item(i, terms.basic[i])
- end
- mp3 = Mark_Parser.new("etypes")
- for i in 0..terms.etypes.size-1
- mp3.add_item(i, terms.etypes[i])
- end
- mp4 = Mark_Parser.new("commands")
- for i in 0..terms.commands.size-1
- mp4.add_item(i, terms.commands[i])
- end
- return mp.to_s + mp2.to_s + mp3.to_s + mp4.to_s
- end
- #--------------------------------------------------------------------------
- # * Dialog list creation
- #--------------------------------------------------------------------------
- def dialogs
- mp = Mark_Parser.new("strings")
- records = 0
- records += get_from_map(mp)
- records += get_from_troops(mp)
- records += get_from_common_events(mp)
- println "#{records} strings created from Message Dialogs."
- return mp.to_s
- end
- #--------------------------------------------------------------------------
- # * Get all message box on all over the maps
- #--------------------------------------------------------------------------
- def get_from_map(mp)
- records = 0
- for i in 1..999
- map_file = sprintf("Data/Map%03d.rvdata2", i)
- next unless File.exist?(map_file)
- map = load_data(map_file)
- if !map.display_name.empty?
- name = sprintf(MAPNAM,i)
- mp.add_item(name, map.display_name)
- map.display_name = "{S: #{name}}"
- end
- map.events.each_pair do |event_id, event|
- event.pages.each_with_index do |page, page_i|
- page.list.each_with_index do |command, command_i|
- case command.code
- when 401
- next if command.parameters[0] =~ H87Localization::REG_EXCAPE
- name = sprintf(STRING,i,event_id,page_i,command_i)
- mp.add_item(name, command.parameters[0])
- command.parameters[0] = "{S: #{name}}"
- records += 1
- when 102
- command.parameters[0].each_with_index do |param, param_i|
- next if param =~ H87Localization::REG_EXCAPE
- name = sprintf(CHOICE,i,event_id,page_i,command_i,param_i)
- mp.add_item(name, param)
- command.parameters[0][param_i] = "{S: #{name}}"
- records += 1
- end
- end
- end
- end
- end
- save_data(map, map_file)
- end
- return records
- end
- #--------------------------------------------------------------------------
- # * Get all message box in all troops
- #--------------------------------------------------------------------------
- def get_from_troops(mp)
- records = 0
- for troop in $data_troops
- next if troop.nil?
- troop.pages.each_with_index do |page, page_i|
- page.list.each_with_index do |command, command_i|
- case command.code
- when 401
- next if command.parameters[0] =~ H87Localization::REG_EXCAPE
- name = sprintf(BATTLE,troop.id,page_i,command_i)
- mp.add_item(name, command.parameters[0])
- command.parameters[0] = "{S: #{name}}"
- records += 1
- when 102
- command.parameters[0].each_with_index do |param, param_i|
- next if param =~ H87Localization::REG_EXCAPE
- name = sprintf(BATTLC,troop.id,page_i,command_i,param_i)
- mp.add_item(name, param)
- command.parameters[0][param_i] = "{S: #{name}}"
- records += 1
- end
- end
- end
- end
- end
- save_data($data_troops,"Data/Troops.rvdata2")
- return records
- end
- #--------------------------------------------------------------------------
- # * Gets all message box in all common events
- #--------------------------------------------------------------------------
- def get_from_common_events(mp)
- records = 0
- for event in $data_common_events
- next if event.nil?
- event.list.each_with_index do |command, command_i|
- case command.code
- when 401
- next if command.parameters[0] =~ H87Localization::REG_EXCAPE
- name = sprintf(COMMON,event.id,command_i)
- mp.add_item(name, command.parameters[0])
- command.parameters[0] = "{S: #{name}}"
- records += 1
- when 102
- command.parameters[0].each_with_index do |param, param_i|
- next if param =~ H87Localization::REG_EXCAPE
- name = sprintf(COMMOC,event.id,command_i,param_i)
- mp.add_item(name, param)
- command.parameters[0][param_i] = "{S: #{name}}"
- records += 1
- end
- end
- end
- end
- save_data($data_common_events, "Data/CommonEvents.rvdata2")
- return records
- end
- #--------------------------------------------------------------------------
- # * Process that creates tag with attributes
- # name: tag name
- # array: database array
- # attributes: attributes to copy
- #--------------------------------------------------------------------------
- def attr_process(name, array, attributes)
- mp = Mark_Parser.new(name)
- for item in array
- next if item.nil?
- next if item.name.empty?
- next if item.name == " "
- mp.add_item
- for attr in attributes
- attr_value = eval("item.#{attr}")
- next if attr_value == ""
- mp.push_attr(attr.to_s, attr_value)
- end
- end
- println "#{name} saved. #{array.size} lines created."
- return mp.to_s
- end
- end
- #==============================================================================
- # ** Mark Parser
- #------------------------------------------------------------------------------
- # This class is used within Localization_Tool and creates the string that
- # will be written into the file.
- #==============================================================================
- class Mark_Parser
- attr_accessor :tag
- #--------------------------------------------------------------------------
- # * Object initialization
- #--------------------------------------------------------------------------
- def initialize(tag)
- @tag = tag
- @items = []
- end
- #--------------------------------------------------------------------------
- # * Add attribute to item
- # attr_name: name of attribute
- # value: value of attribute
- #--------------------------------------------------------------------------
- def push_attr(attr_name, value)
- return if value =~ H87Localization::REG_EXCAPE
- val = value.to_s.gsub(/[\r\n]+/,"\\n").gsub(";","\\;")
- @items.last.push("#{attr_name}:#{val}")
- end
- #--------------------------------------------------------------------------
- # * Add new item
- #--------------------------------------------------------------------------
- def add_item(attr_name = nil, value = nil)
- @items.push([])
- push_attr(attr_name, value) if attr_name != nil
- end
- #--------------------------------------------------------------------------
- # * String converter
- #--------------------------------------------------------------------------
- def to_s
- string = ""
- string << "<#{@tag}>\n"
- @items.each do |item|
- string << item * "; "
- string << "\n"
- end
- string << "</#{@tag}>\n\n"
- return string
- end
- end
- #==============================================================================
- # ** Scene_Title
- #------------------------------------------------------------------------------
- # Access for tool's scene
- #==============================================================================
- class Scene_Title < Scene_Base
- alias h87loctool_update update unless $@
- #--------------------------------------------------------------------------
- # * update
- #--------------------------------------------------------------------------
- def update
- h87loctool_update
- go_loc_tool if Input.trigger?(:B) && Input.press?(:LEFT) && $TEST
- end
- #--------------------------------------------------------------------------
- # * go to localizer tool scene
- #--------------------------------------------------------------------------
- def go_loc_tool
- SceneManager.call(Scene_Localization)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement