Multiple Language Script
v0.54
I posted a screen in the respective thread, and now I finally post the script... Let's see if someone can put it in good use besides me ^_^
Introduction
This scripts purpose is to make your game multiple language-ready. It enables an interface launched before the title screen to select a language to play with. The list shown there consists of folder names inside your Game/Language directory.
The big idea is to make the language of a game independent from the native language of the creator and/or his foreign language skills. Of course, if you're going to release it in an English community and your game is English from the begin with, you won't need to do the (relatively big) efford and implement this.
Screenshots
Script and Resources
Instructions
v0.54
I posted a screen in the respective thread, and now I finally post the script... Let's see if someone can put it in good use besides me ^_^
Introduction
This scripts purpose is to make your game multiple language-ready. It enables an interface launched before the title screen to select a language to play with. The list shown there consists of folder names inside your Game/Language directory.
The big idea is to make the language of a game independent from the native language of the creator and/or his foreign language skills. Of course, if you're going to release it in an English community and your game is English from the begin with, you won't need to do the (relatively big) efford and implement this.
Screenshots


Script and Resources
Code:
#==============================================================================
# Multiple Language Script
#------------------------------------------------------------------------------
# Script by BlueScope
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
attr_accessor :language
#--------------------------------------------------------------------------
def read_text(id)
file = File.open("Language/" + @language + "/Generic.txt")
content = file.readlines
for line in 0..content.size-1
if content[line].include?("*" + id)
temp_content = content[line]
temp_content.gsub!(("*" + id + " "), "")
end
end
return temp_content
end
#--------------------------------------------------------------------------
def read_base(id)
file = File.open("Language/" + @language + "/Database.txt")
content = file.readlines
id = id.split(" ")
for line in 0..content.size-1
if content[line].include?("*" + id[0])
temp_content = content[line]
temp_content.gsub!(("*" + id[0] + " "), "")
end
end
return temp_content
end
#--------------------------------------------------------------------------
end
class Window_Version < Window_Base
#--------------------------------------------------------------------------
def initialize
super(320, 176, 240, 128)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, self.width-40, 32, $game_system.read_text("00000"), 0)
self.contents.draw_text(4, 37, self.width-40, 32, $game_system.read_text("00002"), 0)
self.contents.draw_text(4, 64, self.width-40, 32, $game_system.read_text("00004"), 0)
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, self.width-40, 32, $game_system.read_text("00001"), 2)
self.contents.draw_text(4, 37, self.width-40, 32, $game_system.read_text("00003"), 2)
self.contents.draw_text(4, 64, self.width-40, 32, "1.0", 2) # Game Version
self.contents.fill_rect(4, 34, self.width-40, 1, disabled_color)
end
#--------------------------------------------------------------------------
end
class Window_CommandLanguage < Window_Selectable
#--------------------------------------------------------------------------
def initialize(width, commands)
super(0, 0, width, commands.size * 32 + 32)
@item_max = commands.size
@commands = commands
self.contents = Bitmap.new(width - 32, @item_max * 32)
self.opacity = 0
refresh
self.index = 0
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i, normal_color)
end
end
#--------------------------------------------------------------------------
def draw_item(index, color)
self.contents.font.color = color
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index], 1)
end
#--------------------------------------------------------------------------
def disable_item(index)
draw_item(index, disabled_color)
end
#--------------------------------------------------------------------------
end
class Scene_Language
#--------------------------------------------------------------------------
def main
$game_system = Game_System.new
$data_system = load_data("Data/System.rxdata")
@command_window = Window_CommandLanguage.new(240, read_languages)
@command_window.x = 80
@command_window.y = 240 - @command_window.height / 2
$game_system.language = read_languages[@command_window.index]
@version_window = Window_Version.new
@dummy = Window_Base.new(80, 176, 240, 128)
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@command_window.dispose
@version_window.dispose
@dummy.dispose
end
#--------------------------------------------------------------------------
def read_languages
entries = Dir.entries("Language/.")
entries.delete_at(0)
entries.delete_at(0)
entries.sort!
return entries
end
#--------------------------------------------------------------------------
def update
@command_window.update
if Input.trigger?(Input::UP) or Input.trigger?(Input::DOWN)
$game_system.language = read_languages[@command_window.index]
@version_window.refresh
end
if Input.trigger?(Input::C)
$scene = Scene_Title.new
end
end
#--------------------------------------------------------------------------
end
class Scene_Title
#--------------------------------------------------------------------------
def command_new_game
$game_system.se_play($data_system.decision_se)
Audio.bgm_stop
Graphics.frame_count = 0
$game_temp = Game_Temp.new
$game_switches = Game_Switches.new
$game_variables = Game_Variables.new
$game_self_switches = Game_SelfSwitches.new
$game_screen = Game_Screen.new
$game_actors = Game_Actors.new
$game_party = Game_Party.new
$game_troop = Game_Troop.new
$game_map = Game_Map.new
$game_player = Game_Player.new
$game_party.setup_starting_members
$game_map.setup($data_system.start_map_id)
$game_player.moveto($data_system.start_x, $data_system.start_y)
$game_player.refresh
$game_map.autoplay
$game_map.update
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
end
*00000 Author
*00001 BlueScope
*00002 Language Version
*00003 1.0
*00004 Game Version
Instructions
Script Installation":28pbyzrk said:Of course, you first have to copy the script part in the script editor, in a new script above Main. The script is plug-and-play, besides a single thing: You need to trigger it in Main, so head for this line:Go change it to this:Code:# Make scene object (title screen) $scene = Scene_Title.new
Code:# Make scene object (language selection screen) $scene = Scene_Language.new
Now you have to create files to store your strings in. I posted an example file further above that only includes the language menu. Create a new directory inside your game's folder and save the content of the spoiler in a txt file named "Generic.txt". Note that you also need other files for several areas where strings are used. The path should be [Game Directory]\Language\English\[filename].txt, if you chose English to be your language of choice. Here's the list of files you need currently, along with an explanation of what they contain:Note that if you're going to use special characters the English language doesn't know, you should use UTF-8 encoding for the txt file which you can choose while saving. It will show German dieresis and Japanese Kana and Kanji in RMXP this way. Credit for this hint goes to Selwyn, who told me this some time ago.Code:Language\[language]\Generic.txt # read with $game_system.read_text(id); used for draw_text strings within the script editor Language\[language]\Database.txt # read with $game_system.read_base(id); used for strings like item names or class names within the Database
Since the language scene isn't the only thing you'd want to be translated, I'll tell you how to mark other strings as ones to be replaced.
First, you might want to replace strings defined in the script editor, like the ones in command windows and such. I'll take the title screen as an example, which of course is classed in Scene_Title.
What we need to look at is this:Three strings are defined there. Let's replace "New Game" only for space-saving purposes in this example. Of course, we first need a new entry in the language file, so fire it up. Create a new identification line and a string, so it looks like this (default part left out):Code:# Make command window s1 = [color=Blue]"New Game"[/color] s2 = "Continue" s3 = "Shutdown" @command_window = Window_Command.new(192, [s1, s2, s3])
Now that you created the string, you need to create a reference. Open Scene_Title again, and replace the default s1 line with this:*00005 New GameTry it out by testplaying your game.Code:s1 = [color=Blue]$game_system.read_text("00005")[/color]
System strings are strings defined in the database's system tab, in the column 'Words'. You can't simply put a number inside these to replace the strings, you need to manually replace the references in the script editor. You might also overwrite RPG::System::Words, which can be found in RMXPs help file.
I'll take Window_Gold as an example this time, and I'll use the replacement method. Let's take a look at the important part...$data_system.words.gold is in there two times. This line holds the string; you could write "Gold", too, for example. Well, in order to have the currency name tagged, you need to replace these references. I won't explain how to create a language string in the txt file, but here's how your Window_Gold part should look like if you used 00006 as the currency identifier:Code:def refresh self.contents.clear cx = contents.text_size([color=Blue]$data_system.words.gold[/color]).width self.contents.font.color = normal_color self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2) self.contents.font.color = system_color self.contents.draw_text(124-cx, 0, cx, 32, [color=Blue]$data_system.words.gold[/color], 2) end
Note that you probably won't need to translate the currency name at all... it was just an example from me, if you don't see a reason why it should be replaced, don't include it in the language file.Code:def refresh self.contents.clear cx = contents.text_size([color=Blue]$game_system.read_text("00006")[/color]).width self.contents.font.color = normal_color self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2) self.contents.font.color = system_color self.contents.draw_text(124-cx, 0, cx, 32, [color=Blue]$game_system.read_text("00006")[/color], 2) end
Another important part to translate are database strings, like item names, which I'll take as the example this time. In Window_Item, there's a single line refering to the name:Let's assume we want to translate the default #0001 item: Potion. Note that for database items, you have to use entries in the Database.txt located in your language's folder. After you created your language string in the txt file (number "00001" for this example - note that you can of course use multiple instances of the same number as long it's referencing to different files), replace the line I posted before with this:Code:self.contents.draw_text(x + 28, y, 212, 32, [color=Blue]item.name[/color], 0)
Now you only need to name the item properly. Instead of Potion, you have to name it 00001 now. It's important to not include quotation marks in here, you'll get an error if you try. Note that you can name the item something like 00001 Potion, as everything behind the number (as long as it's seperated with a space) gets ignored by the respective method.Code:self.contents.draw_base(x + 28, y, 212, 32, [color=Blue]$game_system.read_base(item.name)[/color], 0)
This works with all the database strings, you just need to find the respective places to change the reference inside the script editor. Once again, pay attention on what you translate - you probably don't want your heroes to have different names in different languages, as this might be confusing.
ToDo-List
- Only launch up the language selection screen if there's more than one language folder in the 'Language' folder
- Read the default language from compiled Data directory to make it inaccessable to the player
- Adjust Scene_Load to only show files with the language currently selected
- Window_Message support
- Easier language tagging and language file handling
Frequently Asked Questions
None so far...
Compatibility
This should be compatible with everything because it doesn't change and/or overwrite any of the default methods.
Credits
BlueScope ^_^
vgvgf for helping me out with a file reading problem I couldn't solve by myself.
Chaosg1 for helping me out with the global variable replacing.
- Only launch up the language selection screen if there's more than one language folder in the 'Language' folder
- Read the default language from compiled Data directory to make it inaccessable to the player
- Adjust Scene_Load to only show files with the language currently selected
- Window_Message support
- Easier language tagging and language file handling
Frequently Asked Questions
None so far...
Compatibility
This should be compatible with everything because it doesn't change and/or overwrite any of the default methods.
Credits
BlueScope ^_^
vgvgf for helping me out with a file reading problem I couldn't solve by myself.
Chaosg1 for helping me out with the global variable replacing.