mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-19 13:29:54 +00:00
Enable localization of game text
This commit is contained in:
parent
0f3217d16d
commit
cfd30bbca6
9 changed files with 144 additions and 32 deletions
|
|
@ -25,9 +25,9 @@ module EdText
|
|||
sleep 0.2
|
||||
end
|
||||
result = nil
|
||||
text = Language.tr(text.to_s.gsub(/\s*\n\s*/, " ").strip)
|
||||
thread = Thread.new do
|
||||
result = Oneshot.msgbox(type, text
|
||||
.gsub(/\s+\n\s+/, " ")
|
||||
.gsub("\\p", $game_oneshot.player_name) +
|
||||
" " * 10)
|
||||
# HACK: Fuck
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ class Interpreter
|
|||
# Create full text string
|
||||
choices = false
|
||||
text = @list[@index].parameters[0].strip
|
||||
|
||||
# Translate text
|
||||
text = Language.tr(text).clone
|
||||
|
||||
if text.start_with?('$')
|
||||
is_doc = true
|
||||
text.slice!(0)
|
||||
|
|
@ -31,11 +35,11 @@ class Interpreter
|
|||
# 401: another line of text
|
||||
if @list[@index+1].code == 401
|
||||
@index += 1
|
||||
text << " " << @list[@index].parameters[0].rstrip
|
||||
text << " " << Language.tr(@list[@index].parameters[0].rstrip).clone
|
||||
elsif @list[@index+1].code == 101 && (is_doc || is_credits)
|
||||
# 101: Another message box
|
||||
# Tack on if we're a doc
|
||||
new_text = @list[@index+1].parameters[0].strip
|
||||
new_text = Language.tr(@list[@index+1].parameters[0].strip).clone
|
||||
if new_text.start_with?('$')
|
||||
text << "\n\n" << new_text[1..-1]
|
||||
@index += 1
|
||||
|
|
@ -64,9 +68,7 @@ class Interpreter
|
|||
end
|
||||
text.gsub!(/\s*\\n\s*/, '\\n')
|
||||
text.strip!
|
||||
|
||||
# Translate text
|
||||
text = Language.tr(text).clone
|
||||
text = Language.tr(text)
|
||||
|
||||
# Parse first line for portrait specifier
|
||||
if text[0,1] == '@'
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ begin
|
|||
|
||||
# Load persistent data
|
||||
Persistent.load
|
||||
$persistent.lang = 'ja'
|
||||
|
||||
# Prepare for transition
|
||||
Graphics.freeze
|
||||
|
|
|
|||
|
|
@ -39,6 +39,10 @@ class Persistent
|
|||
Language.set(@lang)
|
||||
end
|
||||
|
||||
def langcode
|
||||
self.lang.full.to_s
|
||||
end
|
||||
|
||||
# MARSHAL
|
||||
def marshal_dump
|
||||
[@lang]
|
||||
|
|
@ -49,7 +53,7 @@ class Persistent
|
|||
|
||||
# Save/Load global instance of persistent
|
||||
FILE_NAME = Oneshot::SAVE_PATH + '/persistent.dat'
|
||||
def self.save
|
||||
def save
|
||||
File.open(FILE_NAME, 'wb') do |file|
|
||||
Marshal.dump($persistent, file)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class Scene_Map
|
|||
# either telling them they can't quit during a cutscene
|
||||
# or telling them they're saving and quitting
|
||||
if $game_system.map_interpreter.running?
|
||||
EdText.info("You cannot perform this action during cutscenes.")
|
||||
EdText.info(tr("You cannot perform this action during cutscenes."))
|
||||
return
|
||||
else
|
||||
$game_temp.common_event_id = 35
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ class Window_MainMenu < Window_Selectable
|
|||
|
||||
# Set up menu options
|
||||
@commands = Array.new
|
||||
@commands << tr('Travel')
|
||||
@commands << tr('Notes')
|
||||
@commands << tr('Settings')
|
||||
@commands << 'Travel'
|
||||
@commands << 'Notes'
|
||||
@commands << 'Settings'
|
||||
@item_max = @commands.size
|
||||
@column_max = @item_max
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ class Window_MainMenu < Window_Selectable
|
|||
# Update item
|
||||
rect = Rect.new(w * index, 0, w - 32, 32)
|
||||
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
|
||||
self.contents.draw_text(rect, @commands[index], 1)
|
||||
self.contents.draw_text(rect, tr(@commands[index]), 1)
|
||||
end
|
||||
#--------------------------------------------------------------------------
|
||||
# * Disable Item
|
||||
|
|
@ -59,6 +59,10 @@ class Window_MainMenu < Window_Selectable
|
|||
|
||||
# Open/show the menu
|
||||
def open
|
||||
# redraw in case language has been updated
|
||||
for i in 0...@item_max
|
||||
draw_item(i, normal_color)
|
||||
end
|
||||
self.opacity = 0
|
||||
self.contents_opacity = 0
|
||||
self.visible = true
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class Window_Settings
|
|||
SETTINGS_FILE_NAME = Oneshot::SAVE_PATH + '/settings.conf'
|
||||
|
||||
def save_settings
|
||||
$persistent.save
|
||||
File.open(SETTINGS_FILE_NAME, 'w') do |file|
|
||||
file.puts('bgm_volume=' + Audio.bgm_volume.to_s)
|
||||
file.puts('sfx_volume=' + Audio.sfx_volume.to_s)
|
||||
|
|
@ -75,6 +76,7 @@ class Window_Settings
|
|||
@title.bitmap.font.size = 40
|
||||
@title.y = TITLE_TOP_MARGIN
|
||||
@title.x = MARGIN
|
||||
Language.register_text_sprite(self.class.name + "_title", @title)
|
||||
@data_sprites = []
|
||||
@viewport.z = 9998
|
||||
|
||||
|
|
@ -110,10 +112,16 @@ class Window_Settings
|
|||
tr('Default movement'),
|
||||
tr('Colorblind mode'),
|
||||
tr('Frameskip'),
|
||||
tr('Language'),
|
||||
tr('Configure Controls (Press F1)'),
|
||||
]
|
||||
|
||||
@index = 0
|
||||
# Load our language settings from persistent, stored differently
|
||||
@lang_index = Language::LANGUAGES.index($persistent.langcode)
|
||||
if @lang_index.nil?
|
||||
@lang_index = 0
|
||||
end
|
||||
|
||||
# Create title
|
||||
@title.bitmap.clear
|
||||
|
|
@ -126,6 +134,7 @@ class Window_Settings
|
|||
spr.x = MARGIN
|
||||
spr.y = TITLE_MARGIN + TITLE_TOP_MARGIN + ITEM_SPACING * i
|
||||
spr.opacity = 0
|
||||
Language.register_text_sprite(self.class.name + "_option_#{i}", spr)
|
||||
redraw_setting(spr, i)
|
||||
|
||||
@data_sprites << spr
|
||||
|
|
@ -168,9 +177,13 @@ class Window_Settings
|
|||
else
|
||||
spr.bitmap.draw_text(260, 0, spr.bitmap.width, spr.bitmap.height, tr("OFF"))
|
||||
end
|
||||
when 6 # Language
|
||||
l = Language::LANGUAGES[@lang_index] rescue Language::LANGUAGES[0]
|
||||
spr.bitmap.draw_text(260, 0, spr.bitmap.width, spr.bitmap.height, l)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def redraw_setting_index(i)
|
||||
if !@data_sprites.kind_of?(Array)
|
||||
return
|
||||
|
|
@ -181,6 +194,16 @@ class Window_Settings
|
|||
redraw_setting(@data_sprites[i], i)
|
||||
end
|
||||
|
||||
|
||||
def redraw_all_settings
|
||||
@title.bitmap.clear
|
||||
@title.bitmap.draw_text(0, 0, @title.bitmap.width, @title.bitmap.height, tr("Settings"))
|
||||
for i in 0..7
|
||||
redraw_setting_index(i)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
if @fade_in
|
||||
self.opacity += 20
|
||||
|
|
@ -276,15 +299,16 @@ class Window_Settings
|
|||
Audio.bgm_volume -= 1
|
||||
if old_vol > 1
|
||||
Audio.se_play("Audio/SE/text_robot.wav", 70, (Audio.bgm_volume/2) + 75)
|
||||
redraw_setting_index(0)
|
||||
end
|
||||
elsif Input.trigger?(Input::RIGHT) || (Input.press?(Input::RIGHT) && (@right_hold_timer >= 15))
|
||||
@right_hold_timer -= 2
|
||||
Audio.bgm_volume += 1
|
||||
if old_vol < 100
|
||||
Audio.se_play("Audio/SE/text_robot.wav", 70, (Audio.bgm_volume/2) + 75)
|
||||
end
|
||||
end
|
||||
redraw_setting_index(0)
|
||||
end
|
||||
end
|
||||
|
||||
when 1 #sfx vol
|
||||
old_vol = Audio.sfx_volume
|
||||
|
|
@ -293,15 +317,16 @@ class Window_Settings
|
|||
Audio.sfx_volume -= 1
|
||||
if old_vol > 1
|
||||
Audio.se_play("Audio/SE/text_robot.wav", 70, (Audio.sfx_volume/2) + 75)
|
||||
redraw_setting_index(1)
|
||||
end
|
||||
elsif Input.trigger?(Input::RIGHT) || (Input.press?(Input::RIGHT) && (@right_hold_timer >= 15))
|
||||
@right_hold_timer -= 2
|
||||
Audio.sfx_volume += 1
|
||||
if old_vol < 100
|
||||
Audio.se_play("Audio/SE/text_robot.wav", 70, (Audio.sfx_volume/2) + 75)
|
||||
end
|
||||
end
|
||||
redraw_setting_index(1)
|
||||
end
|
||||
end
|
||||
|
||||
when 2 #fullscreen
|
||||
if Input.trigger?(Input::ACTION) || Input.trigger?(Input::LEFT) || Input.trigger?(Input::RIGHT)
|
||||
|
|
@ -354,6 +379,24 @@ class Window_Settings
|
|||
end
|
||||
redraw_setting_index(5)
|
||||
end
|
||||
|
||||
when 6 #language
|
||||
if Input.trigger?(Input::ACTION) || Input.trigger?(Input::RIGHT)
|
||||
@lang_index += 1
|
||||
if @lang_index >= Language::LANGUAGES.length
|
||||
@lang_index = 0
|
||||
end
|
||||
$persistent.lang = Language::LANGUAGES[@lang_index]
|
||||
redraw_all_settings()
|
||||
end
|
||||
if Input.trigger?(Input::LEFT)
|
||||
@lang_index -= 1
|
||||
if @lang_index < 0
|
||||
@lang_index = Language::LANGUAGES.length - 1
|
||||
end
|
||||
$persistent.lang = Language::LANGUAGES[@lang_index]
|
||||
redraw_all_settings()
|
||||
end
|
||||
end
|
||||
|
||||
if Input.trigger?(Input::CANCEL)
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ Persistent
|
|||
|
||||
# Internationalization
|
||||
i18n_Language
|
||||
i18n_English
|
||||
i18n_Japanese
|
||||
|
||||
# Data
|
||||
Data_Item
|
||||
|
|
|
|||
|
|
@ -1,32 +1,56 @@
|
|||
# Classes for translating text similar to GNU gettext
|
||||
|
||||
# Translator class: translate text to another language
|
||||
|
||||
# for debug REMOVE BEFORE COMMITTING
|
||||
require "zlib"
|
||||
|
||||
class Language
|
||||
FONT_WESTERN = 'Terminus (TTF)'
|
||||
FONT_CJK = 'WenQuanYi Micro Hei'
|
||||
LANG_WESTERN = [
|
||||
'en', 'fr', 'pt_BR'
|
||||
]
|
||||
LANG_CJK = [
|
||||
'ja', 'ko', 'zh_CN'
|
||||
]
|
||||
LANGUAGES = LANG_WESTERN + LANG_CJK
|
||||
|
||||
class << self
|
||||
def set(lc)
|
||||
dbg_print(lc.lang)
|
||||
@data = nil
|
||||
@tr = nil
|
||||
script = nil
|
||||
[lc.full.to_s, lc.lang.to_s].each do |name|
|
||||
begin
|
||||
@tr, script = load_data("Languages/#{name}.rxdata")
|
||||
break
|
||||
rescue
|
||||
path = "Languages/#{name}.loc"
|
||||
dbg_print(path)
|
||||
if FileTest.exist?(path)
|
||||
File.open(path, "rb") do |file|
|
||||
@data = Marshal.load(file)
|
||||
if LANG_CJK.include? name
|
||||
Font.default_name = FONT_CJK
|
||||
else
|
||||
Font.default_name = FONT_WESTERN
|
||||
end
|
||||
end
|
||||
exec(script) if script
|
||||
end
|
||||
end
|
||||
reset_fonts(@text_sprites)
|
||||
Oneshot.set_yes_no(tr('Yes'), tr('No'))
|
||||
end
|
||||
|
||||
# Translate some text
|
||||
def tr(string)
|
||||
#dbg_print(caller_locations(1, 1).first.tap{|loc| puts "#{loc.path}:#{loc.lineno}"})
|
||||
dbg_print(string)
|
||||
if @data
|
||||
@data[Zlib::crc32(string)] || string
|
||||
rv = @data[Zlib::crc32(string)] || string
|
||||
else
|
||||
string
|
||||
rv = string
|
||||
end
|
||||
dbg_print(rv)
|
||||
return rv
|
||||
end
|
||||
|
||||
# Turn all database items into translatable strings
|
||||
|
|
@ -41,6 +65,42 @@ class Language
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def dbg_print(str)
|
||||
dbg = IO.new(STDERR.fileno)
|
||||
if str.nil?
|
||||
dbg.write("null\n")
|
||||
else
|
||||
dbg.write(str.to_s + "\n")
|
||||
end
|
||||
dbg.close()
|
||||
end
|
||||
|
||||
def register_text_sprite(key, spr)
|
||||
dbg_print(key)
|
||||
if @text_sprites.nil?
|
||||
@text_sprites = Hash.new()
|
||||
end
|
||||
@text_sprites[key] = spr
|
||||
end
|
||||
|
||||
def reset_fonts(sprites)
|
||||
if sprites.kind_of?(Array)
|
||||
sprites.each do |spr|
|
||||
if spr.kind_of?(Sprite)
|
||||
spr.bitmap.font.name = Font.default_name
|
||||
end
|
||||
end
|
||||
elsif sprites.kind_of?(Hash)
|
||||
sprites.each_value do |spr|
|
||||
if spr.kind_of?(Sprite)
|
||||
spr.bitmap.font.name = Font.default_name
|
||||
end
|
||||
end
|
||||
elsif sprites.kind_of?(Sprite)
|
||||
sprites.bitmap.font.name = Font.default_name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue