Improved internationalization support

This commit is contained in:
Mathew Velasquez 2016-04-06 13:45:36 -04:00
parent d0cb19e9d2
commit d53ad4b124
17 changed files with 1823 additions and 344 deletions

1476
binding-mri/module_rpg1.rb Normal file

File diff suppressed because it is too large Load Diff

View File

@ -235,7 +235,7 @@ class Interpreter
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def setup_choices(parameters) def setup_choices(parameters)
# Set choices # Set choices
$game_temp.choices = parameters[0].map{|s| $tr.event(@event_name, s.strip)} $game_temp.choices = parameters[0].map{|s| Language.tr(s.strip)}
# Set cancel processing # Set cancel processing
$game_temp.choice_cancel_type = parameters[1] $game_temp.choice_cancel_type = parameters[1]
# Set callback # Set callback

View File

@ -45,7 +45,7 @@ class Interpreter
text.strip! text.strip!
# Translate text # Translate text
text = $tr.event(@event_name, text).clone text = Language.tr(text).clone
# Parse first line for portrait specifier # Parse first line for portrait specifier
if text[0,1] == '@' if text[0,1] == '@'

View File

@ -11,6 +11,7 @@ begin
# Load persistent data # Load persistent data
Persistent.load Persistent.load
$persistent.lang = 'ja'
# Prepare for transition # Prepare for transition
Graphics.freeze Graphics.freeze

View File

@ -28,11 +28,15 @@ class Persistent
# Members # Members
def lang=(val) def lang=(val)
@lang = val case val
$tr = Translator.new(@lang) when String
$lang = Language.get(@lang) @lang = LanguageCode.new(val)
Font.default_name = $lang.font when LanguageCode
Oneshot.set_yes_no(tr('Yes'), tr('No')) @lang = val
else
raise 'value passed to Persistent.lang neither String nor LanguageCode'
end
Language.set(@lang)
end end
# MARSHAL # MARSHAL

View File

@ -11,7 +11,7 @@ class Scene_Name
def main def main
# Make windows # Make windows
@edit_window = Window_NameEdit.new @edit_window = Window_NameEdit.new
@input_window = Window_NameInput.new @input_window = Language.create_input
# Execute transition # Execute transition
Graphics.transition Graphics.transition
# Main loop # Main loop
@ -56,26 +56,35 @@ class Scene_Name
if Input.trigger?(Input::ACTION) if Input.trigger?(Input::ACTION)
# If cursor position is at [OK] # If cursor position is at [OK]
if @input_window.character == nil if @input_window.character == nil
# If name is empty # Cursor is at OK or mode buttons
if @edit_window.name == "" slot = @input_window.mode_button_slot
# Return to default name if slot == -1
@edit_window.restore_default # Cursor is at OK
# If name is empty # If name is empty
if @edit_window.name == "" if @edit_window.name == ""
# Play buzzer SE # Return to default name
$game_system.se_play($data_system.buzzer_se) @edit_window.restore_default
# If name is empty
if @edit_window.name == ""
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
return return
end end
# Change actor name
$game_oneshot.player_name = @edit_window.name
# Play decision SE # Play decision SE
$game_system.se_play($data_system.decision_se) $game_system.se_play($data_system.decision_se)
# Switch to map screen
$scene = Scene_Map.new
return return
end end
# Change actor name # Cursor is on mode buttons
$game_oneshot.player_name = @edit_window.name
# Play decision SE
$game_system.se_play($data_system.decision_se) $game_system.se_play($data_system.decision_se)
# Switch to map screen @input_window.cycle_mode(slot)
$scene = Scene_Map.new
return return
end end
# If cursor position is at maximum # If cursor position is at maximum

View File

@ -26,6 +26,7 @@ class Scene_Title
$data_tilesets = load_data("Data/Tilesets.rxdata") $data_tilesets = load_data("Data/Tilesets.rxdata")
$data_common_events = load_data("Data/CommonEvents.rxdata") $data_common_events = load_data("Data/CommonEvents.rxdata")
$data_system = load_data("Data/System.rxdata") $data_system = load_data("Data/System.rxdata")
Language.initialize_database
# Load save game/initialize data # Load save game/initialize data
$game_temp = Game_Temp.new $game_temp = Game_Temp.new
new_game unless load new_game unless load

View File

@ -117,7 +117,7 @@ end
# Map specific settings # Map specific settings
def green_ambient def green_ambient
ambient -50, -50, -50 ambient -40, -40, -40
end end
# Travel # Travel

View File

@ -12,7 +12,6 @@ class Sprite_Timer < Sprite
def initialize def initialize
super super
self.bitmap = Bitmap.new(88, 48) self.bitmap = Bitmap.new(88, 48)
self.bitmap.font.name = "Terminus (TTF)"
self.bitmap.font.size = 32 self.bitmap.font.size = 32
self.x = 640 - self.bitmap.width self.x = 640 - self.bitmap.width
self.y = 0 self.y = 0

View File

@ -87,7 +87,6 @@ class Window_Message < Window_Selectable
# Initialize # Initialize
@blip = BLIP_TIME @blip = BLIP_TIME
@text = '' @text = ''
y = -1
# Pre-process text # Pre-process text
if $game_temp.message_text != nil && !$game_temp.message_text.empty? if $game_temp.message_text != nil && !$game_temp.message_text.empty?
@ -140,6 +139,8 @@ class Window_Message < Window_Selectable
break if y >= 4 break if y >= 4
end end
end end
@text.rstrip!
lines = @text.empty? ? 0 : @text.count("\n") + 1
# Prepare renderer # Prepare renderer
self.contents.clear self.contents.clear
@ -154,8 +155,8 @@ class Window_Message < Window_Selectable
if $game_temp.choices != nil if $game_temp.choices != nil
# Prepare choices, if they fit # Prepare choices, if they fit
if $game_temp.choices.size + y < 4 if lines + $game_temp.choices.size <= 4
@choice_start = y + 1 @choice_start = lines
@item_max = $game_temp.choices.size @item_max = $game_temp.choices.size
else else
# Don't call the message callback till we can show all the choices # Don't call the message callback till we can show all the choices
@ -163,8 +164,8 @@ class Window_Message < Window_Selectable
end end
elsif $game_temp.num_input_variable_id > 0 elsif $game_temp.num_input_variable_id > 0
# Prepare number input, if it fits # Prepare number input, if it fits
if y < 3 if lines < 3
@number_start = y + 1 @number_start = lines
else else
# Don't call the message callback till we get a number # Don't call the message callback till we get a number
@skip_message_proc = true @skip_message_proc = true

View File

@ -4,8 +4,38 @@
# This window is used to select text characters on the input name screen. # This window is used to select text characters on the input name screen.
#============================================================================== #==============================================================================
class NameInputMode
attr_reader :names
attr_reader :size
attr_accessor :index
attr_accessor :count
def initialize(names, bitmap)
@names = names
@size = names.map { |n| bitmap.text_size(n).width }.max
@index = 0
@count = 0
end
def cycle
@index = (@index + 1) % @count
end
def label
@names[(@index + 1) % @count]
end
end
class Window_NameInput < Window_Base class Window_NameInput < Window_Base
GROUP_WIDTH = 5 BUTTON_BUFFER = 8
BUTTON_PADDING = 16
attr_accessor :index
attr_accessor :ok_text
attr_accessor :character_tables
attr_accessor :table_height
attr_accessor :char_w
attr_accessor :char_h
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# * Object Initialization # * Object Initialization
@ -14,51 +44,123 @@ class Window_NameInput < Window_Base
super(0, 128, 640, 352) super(0, 128, 640, 352)
self.contents = Bitmap.new(width - 32, height - 32) self.contents = Bitmap.new(width - 32, height - 32)
@index = 0 @index = 0
@ok_text = "OK"
@char_w = 28
@char_h = 32
end
def init
# Create dimension information # Create dimension information
@character_table = $lang.character_table @table_size = @character_tables.values.first.size
@group_height = $lang.character_table_height @table_width = @table_size / @table_height
@group_size = @group_height * GROUP_WIDTH @start_x = ((width - 32) - @table_width * @char_w) / 2
@num_groups = @character_table.length / @group_size @start_y = ((height - 32) - (@table_height + 1) * @char_h + BUTTON_BUFFER) / 2
@start_x = ((width - 32) - @num_groups * 152 + 12) / 2
@ok_text = tr("OK")
@ok_text_size = self.contents.text_size(@ok_text).width @ok_text_size = self.contents.text_size(@ok_text).width
# Initialize mode information
@character_tables.each_key do |key|
key.each_with_index do |new_max, i|
@modes[i].count = new_max + 1 if @modes[i].count < new_max + 1
end
end
refresh refresh
update_cursor_rect update_cursor_rect
self
end
#--------------------------------------------------------------------------
# * Properties
#--------------------------------------------------------------------------
def set_mode_buttons(buttons)
@modes = buttons.map { |n| NameInputMode.new(n, self.contents) }
end end
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# * Text Character Acquisition # * Text Character Acquisition
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def character def character
return @character_table[@index] return current_table[@index]
end
#--------------------------------------------------------------------------
# * Mode Button Cursor Positioning
#--------------------------------------------------------------------------
def mode_button_slot
pos = @index % @table_width
x = 0
@modes.each_with_index do |mode, i|
size = mode.size + BUTTON_PADDING * 2
if pos * @char_w >= x && pos * @char_w <= x + size
if (pos + 1) * @char_w - BUTTON_PADDING <= x + size || i < @modes.size - 1
return i
end
end
x += size
end
return -1
end
#--------------------------------------------------------------------------
# * Cycle Current Mode
#--------------------------------------------------------------------------
def cycle_mode(slot)
@modes[slot].cycle
refresh
end
#--------------------------------------------------------------------------
# * Get Character Table for Mode
#--------------------------------------------------------------------------
def current_table
@character_tables[@modes.map { |m| m.index }]
end end
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# * Refresh # * Refresh
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def refresh def refresh
self.contents.clear self.contents.clear
for i in 0...@character_table.length table = current_table
x = @start_x + i / GROUP_WIDTH / @group_height * 152 + i % GROUP_WIDTH * 28 @table_size.times do |i|
y = i / GROUP_WIDTH % @group_height * 32 x = @start_x + (i % @table_width) * @char_w
self.contents.draw_text(x, y, 28, 32, @character_table[i], 1) y = @start_y + (i / @table_width) * @char_h
self.contents.draw_text(x, y, @char_w, @char_h, table[i], 1)
end
# OK button
self.contents.draw_text(@start_x + @table_width * @char_w - @ok_text_size - BUTTON_PADDING,
@start_y + @table_height * @char_h + BUTTON_BUFFER,
@ok_text_size, @char_h, @ok_text, 1)
# Mode buttons
x = @start_x + BUTTON_PADDING
@modes.each do |mode|
self.contents.draw_text(x, @start_y + @table_height * @char_h + BUTTON_BUFFER,
mode.size, @char_h, mode.label, 1)
x += BUTTON_PADDING * 2 + mode.size
end end
self.contents.draw_text(@start_x + @num_groups * 152 - 12 - @ok_text_size - 16,
9 * 32, @ok_text_size, 32, @ok_text, 1)
end end
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# * Cursor Rectangle Update # * Cursor Rectangle Update
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def update_cursor_rect def update_cursor_rect
# If cursor is positioned on [OK] if @index >= @table_size
if @index >= @character_table.length # Cursor is positioned on OK or mode buttons
self.cursor_rect.set(@start_x + @num_groups * 152 - 12 - @ok_text_size - 32, slot = mode_button_slot
9 * 32, @ok_text_size + 32, 32) if slot >= 0
# If cursor is positioned on anything other than [OK] # Cursor is positioned on mode button
x = @start_x
@modes.each_with_index do |mode, i|
if slot == i
self.cursor_rect.set(x, @start_y + @table_height * @char_h + BUTTON_BUFFER,
mode.size + BUTTON_PADDING * 2, @char_h)
break
end
x += BUTTON_PADDING * 2 + mode.size
end
else
# Cursor is positioned on OK button
self.cursor_rect.set(@start_x + @table_width * @char_w - @ok_text_size - BUTTON_PADDING * 2,
@start_y + @table_height * @char_h + BUTTON_BUFFER,
@ok_text_size + 32, @char_h)
end
else else
x = @start_x + @index / GROUP_WIDTH / @group_height * 152 + @index % GROUP_WIDTH * 28 # Cursor is not positioned on OK or mode buttons
y = @index / GROUP_WIDTH % @group_height * 32 x = @start_x + (@index % @table_width) * @char_w
self.cursor_rect.set(x, y, 28, 32) y = @start_y + (@index / @table_width) * @char_h
self.cursor_rect.set(x, y, @char_w, @char_h)
end end
end end
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
@ -66,77 +168,87 @@ class Window_NameInput < Window_Base
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def update def update
super super
# If cursor is positioned on [OK] if @index >= @table_size
if @index >= @character_table.length # Cursor is positioned on OK or mode buttons
# Cursor down
if Input.trigger?(Input::DOWN)
$game_system.se_play($data_system.cursor_se)
@index -= @character_table.length
end
# Cursor up
if Input.repeat?(Input::UP)
$game_system.se_play($data_system.cursor_se)
@index -= @character_table.length - (@group_size - GROUP_WIDTH)
end
# If cursor is positioned on anything other than [OK]
else
# If right directional button is pushed
if Input.repeat?(Input::RIGHT)
# If directional button pressed down is not a repeat, or
# cursor is not positioned on the right edge
if Input.trigger?(Input::RIGHT) or
@index / @group_size < 3 or @index % GROUP_WIDTH < 4
# Move cursor to right
$game_system.se_play($data_system.cursor_se)
if @index % GROUP_WIDTH < 4
@index += 1
else
@index += @group_size - 4
end
if @index >= @character_table.length
@index -= @character_table.length
end
end
end
# If left directional button is pushed
if Input.repeat?(Input::LEFT) if Input.repeat?(Input::LEFT)
# If directional button pressed down is not a repeat, or # If directional button pressed down is not a repeat, or
# cursor is not positioned on the left edge # cursor is not positioned on the left edge
if Input.trigger?(Input::LEFT) or old_slot = mode_button_slot
@index / @group_size > 0 or @index % GROUP_WIDTH > 0 if Input.trigger?(Input::LEFT) || old_slot != 0
# Move cursor to left
$game_system.se_play($data_system.cursor_se) $game_system.se_play($data_system.cursor_se)
if @index % GROUP_WIDTH > 0 if old_slot == 0
@index = @table_size + @table_width - 1
else
loop do
@index -= 1
break if old_slot != mode_button_slot
end
end
end
end
if Input.repeat?(Input::RIGHT)
# If directional button pressed down is not a repeat, or
# cursor is not positioned on the right edge
old_slot = mode_button_slot
if Input.trigger?(Input::RIGHT) || old_slot != -1
$game_system.se_play($data_system.cursor_se)
if old_slot == -1
@index = @table_size
else
loop do
@index += 1
break if old_slot != mode_button_slot
end
end
end
end
if Input.trigger?(Input::DOWN)
$game_system.se_play($data_system.cursor_se)
@index -= @table_size
end
if Input.repeat?(Input::UP)
$game_system.se_play($data_system.cursor_se)
@index -= @table_width
end
else
# Cursor is not positioned on OK or mode buttons
if Input.repeat?(Input::RIGHT)
# If directional button pressed down is not a repeat, or
# cursor is not positioned on the right edge
if Input.trigger?(Input::RIGHT) || @index % @table_width < @table_width - 1
$game_system.se_play($data_system.cursor_se)
if @index % @table_width < @table_width - 1
@index += 1
else
@index -= @table_width - 1
end
end
end
if Input.repeat?(Input::LEFT)
# If directional button pressed down is not a repeat, or
# cursor is not positioned on the left edge
if Input.trigger?(Input::LEFT) || @index % @table_width > 0
$game_system.se_play($data_system.cursor_se)
if @index % @table_width > 0
@index -= 1 @index -= 1
else else
@index -= @group_size - 4 @index += @table_width - 1
end
if @index < 0
@index += @character_table.length
end end
end end
end end
# If down directional button is pushed
if Input.repeat?(Input::DOWN) if Input.repeat?(Input::DOWN)
# Move cursor down
$game_system.se_play($data_system.cursor_se) $game_system.se_play($data_system.cursor_se)
if @index % @group_size < @group_size - GROUP_WIDTH @index += @table_width
@index += GROUP_WIDTH
else
@index += @character_table.length - (@group_size - GROUP_WIDTH)
end
end end
# If up directional button is pushed
if Input.repeat?(Input::UP) if Input.repeat?(Input::UP)
# If directional button pressed down is not a repeat, or # If directional button pressed down is not a repeat, or
# cursor is not positioned on the upper edge # cursor is not positioned on the upper edge
if Input.trigger?(Input::UP) or @index % @group_size >= GROUP_WIDTH if Input.trigger?(Input::UP) || @index >= @table_width
# Move cursor up
$game_system.se_play($data_system.cursor_se) $game_system.se_play($data_system.cursor_se)
if @index % @group_size >= GROUP_WIDTH if @index >= @table_width
@index -= GROUP_WIDTH @index -= @table_width
else else
@index += @character_table.length @index += @table_size
end end
end end
end end

View File

@ -100,8 +100,8 @@ Scene_Debug
Persistent Persistent
# Internationalization # Internationalization
i18n_Translator
i18n_Language i18n_Language
i18n_English
# Data # Data
Data_Item Data_Item

27
scripts/i18n_English.rb Normal file
View File

@ -0,0 +1,27 @@
# Default English localization settings
Font.default_name = Language::FONT_WESTERN
class Language
def self.create_input
input = Window_NameInput.new
input.set_mode_buttons [['Upper', 'Lower']]
input.character_tables = {
[0] => [ # Case: Upper
"A","B","C","D","E","F","G","H","I","J",
"K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z"," ",".",",","-",
"0","1","2","3","4","5","6","7","8","9",
"!","?",'"',"'","/","&","[","]","(",")",
],
[1] => [ # Case: Lower
"a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z"," ",".",",","-",
"0","1","2","3","4","5","6","7","8","9",
"!","?",'"',"'","/","&","[","]","(",")",
],
}
input.table_height = 5
input.init
end
end

35
scripts/i18n_Japanese.rb Normal file
View File

@ -0,0 +1,35 @@
Font.default_name = Language::FONT_CJK
class Language
def self.create_input
input = Window_NameInput.new
input.ok_text = '決定'
input.set_mode_buttons [['かな', 'カナ', '英字']]
input.character_tables = {
[0] => [ # Hiragana
"","","","","","","","","","","","","","","","","","",
"","","","","","","",""," ",""," ","","","","","","","",
"","","","","","","","","","","","","","","","","","",
"","","","","","","",""," ",""," ","","","","","","","",
"","","","","","","","","","","","","","","","","","",
],
[1] => [ # Katakana
"","","","","","","","","","","","","","","","","","",
"","","","","","","",""," ",""," ","","","","","","","",
"","","","","","","","","","","","","","","","","","",
"","","","","","","",""," ",""," ","","","","","","","",
"","","","","","","","","","","","","","","","","","",
],
[2] => [ # Latin
"A","B","C","D","E","F","G","H","I","a","b","c","d","e","f","g","h","i",
"J","K","L","M","N","O","P","Q","R","j","k","l","m","n","o","p","q","r",
"S","T","U","V","W","X","Y","Z"," ","s","t","u","v","w","x","y","z"," ",
"0","1","2","3","4","+","-","=","&","!","?","'",'"',".",",",":",";","$",
"5","6","7","8","9","*","/","#","|","[","]","(",")","<",">","{","}","@",
],
}
input.index = 17 # Start on あ
input.table_height = 5
input.init
end
end

View File

@ -1,147 +1,61 @@
# Classes for translating text similar to GNU gettext
# Translator class: translate text to another language
class Language class Language
attr_reader :font
attr_reader :character_table
attr_reader :character_table_height
def initialize(font, character_table, character_table_height)
@font = font
@character_table = character_table
@character_table_height = character_table_height
end
def self.get(lc)
return LANGUAGES[lc.full] || LANGUAGES[lc.lang] || LANGUAGES[:en]
end
FONT_WESTERN = 'Terminus (TTF)' FONT_WESTERN = 'Terminus (TTF)'
FONT_CJK = 'WenQuanYi Micro Hei' FONT_CJK = 'WenQuanYi Micro Hei'
LANGUAGES = { class << self
:en => Language.new( def set(lc)
FONT_WESTERN, [ @tr = nil
"A","B","C","D","E", script = nil
"F","G","H","I","J", [lc.full.to_s, lc.lang.to_s].each do |name|
"K","L","M","N","O", begin
"P","Q","R","S","T", @tr, script = load_data("Languages/#{name}.rxdata")
"U","V","W","X","Y", break
"Z"," "," "," "," ", rescue
"+","-","*","/","!", end
"1","2","3","4","5", end
exec(script) if script
Oneshot.set_yes_no(tr('Yes'), tr('No'))
end
"a","b","c","d","e", # Translate some text
"f","g","h","i","j", def tr(string)
"k","l","m","n","o", if @data
"p","q","r","s","t", @data[Zlib::crc32(string)] || string
"u","v","w","x","y", else
"z"," "," "," "," ", string
"#","$","%","&","@", end
"6","7","8","9","0", end
], 8
),
:es => Language.new(
FONT_WESTERN, [
"A","B","C","D","E",
"F","G","H","I","J",
"K","L","M","N","O",
"P","Q","R","S","T",
"U","V","W","X","Y",
"Z"," ","Ñ","Ü"," ",
"Á","É","Í","Ó","Ú",
"+","-","*","/","!",
"1","2","3","4","5",
"a","b","c","d","e", # Turn all database items into translatable strings
"f","g","h","i","j", def initialize_database
"k","l","m","n","o", $data_actors.each do |i|
"p","q","r","s","t", i.name = TrString.new(i.name) if i && !i.name.empty?
"u","v","w","x","y", end
"z"," ","ñ","ü"," ", $data_items.each do |i|
"á","é","í","ó","ú", if i && !i.name.empty?
"¡","#","%","&","@", i.name = TrString.new(i.name)
"6","7","8","9","0", i.description = TrString.new(i.description)
], 9 end
), end
:ja => Language.new( end
FONT_CJK, [ end
"","","","","", end
"","","","","",
"","","","","", # Translatable string
"","","","","", class TrString
"","","","","", def initialize(str)
"","","","","", @str = str
"","","","","", end
"", "","", "","",
"","","","","", def to_str
Language.tr(@str)
"", "","", "","", end
"","","","","", alias :to_s :to_str
"","","","","", end
"","","","","",
"","","","","", def tr(text)
"","","","","", TrString.new(text)
"","","","","",
"","","","","",
"","", "", "", "",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"", "","", "","",
"","","","","",
"", "","", "","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","", "", "",
], 9
),
:ko => Language.new(
FONT_CJK, [
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
], 8
),
}
end end

View File

@ -1,87 +0,0 @@
# Classes for translating text similar to GNU gettext
# Translation class: contains translation data
class Translation
attr_reader :events
attr_reader :scripts
attr_reader :actors
attr_reader :items
end
# Translator class: translate text to another language
class Translator
# Create Translator object
def initialize(lc)
@data = nil
[lc.full.to_s, lc.lang.to_s].each do |name|
begin
@data = load_data("Langauges/#{name}.rxdata")
break
rescue
end
end
end
# Translate all database items
def translate_database
$data_actors.each do |i|
i.name = actor(i.name) if i && !i.name.empty?
end
$data_items.each do |i|
i.name, i.description = item(i.name, i.description) if i && !i.name.empty?
end
end
# Translate script text
def script(name, text)
if @data == nil
return text
else
return @data.scripts["#{name}/#{text}"] || text
end
end
# Translate text from event
def event(name, text)
if @data == nil
return text
else
return @data.events["#{name}/#{text}"] || text
end
end
private
# Translate Actor name
def actor(name)
if @data == nil
return name
else
return @data.actors[name] || name
end
end
# Translate Item name (and description)
def item(name, description)
if @data == nil
return [name, description]
else
return @data.items[name] || [name, description]
end
end
end
# Translatable string
class TrString
def initialize(str)
@str = str
end
def to_str
@str
end
alias :to_s :to_str
end
def tr(text)
TrString.new(text)
end

View File

@ -49,19 +49,6 @@ SharedState *SharedState::instance = 0;
int SharedState::rgssVersion = 0; int SharedState::rgssVersion = 0;
static GlobalIBO *_globalIBO = 0; static GlobalIBO *_globalIBO = 0;
static const char *gameArchExt()
{
if (rgssVer == 1)
return ".rgssad";
else if (rgssVer == 2)
return ".rgss2a";
else if (rgssVer == 3)
return ".rgss3a";
assert(!"unreachable");
return 0;
}
struct SharedStatePrivate struct SharedStatePrivate
{ {
void *bindingData; void *bindingData;