I know you didn't ask for advice on this specifically but I figured it might be worthwhile to chime in here. To do 'proper' localization, it's generally easiest to have a single file dedicated to each language and to store all your strings in a ds_map. When the program loads, you populate that map with all the dialogue strings in the game from the given file. That way, if you want to change language you simply have to load a different file. I'm guessing the reason you are doing it this way in particular is because the built-in support for key pairs is fairly easy with .ini files, but depending on how much localization you need to do that file is going to get pretty large and the code you need to write to load it will too. Here's just an example of a way to handle this with normal text files:
Code:
/// @func database_open( filename )
/// @param {string} filename - the path/name of the file to open
var _file = ( file_exists( argument0 ) ? file_text_open_read( argument0 ) : undefined );
var _line;
if is_undefined( _file ) { exit }
else {
var _list = ds_list_create();
while ( !file_text_eof( _file ) ) {
_line = file_text_read_string( _file ); file_text_readln( _file );
if _line == "" { continue }
else { ds_list_add( _list, _line ) }
}
file_text_close( _file );
return _list;
}
Code:
///@func localization_read( list, map )
///@param {int} list - a list containing a localization file
///@param {int} map - the map to read the file into
var _list = argument0;
var _map = argument1;
var _line, _key, _value, _break;
ds_map_clear( _map );
while ( !ds_list_empty( _list ) ) {
_line = _list[| 0 ]; ds_list_delete( _list, 0 );
_break = string_pos( "=\"", _line );
_key = string_copy( _line, 1, _break - 1 );
_value = string_delete( _line, 1, _break + 1 );
_map[? _key ] = _value;
}
I put together a project that demonstrates this method
you can download from my dropbox. But just to explain the method a bit, basically the first script, database_open, reads the entire text file into a ds_list and throws away any 'blank' lines. The second script, localization_read then breaks those lines apart into their key/value pairs and reads them into the ds_map you specify. This prevents you from having to do a bunch of unnecessary reads to the ini file, and ensures that your game only contains in memory the current localization. That way you can simply refer to everything by it's specific name. Perhaps a script like:
Code:
///@func get_string( name )
///@param {string} name - the name of the string to retrieve
var _string = LOCALIZATION_MAP[? argument0 ];
if is_undefined( _string ) { return "" }
return _string;
That way if, for some reason, a string isn't defined it won't cause a crash. I would also suggest pairing
this with caching the result local to the object so you don't have to do a lookup each frame either.
Code:
myString = get_string( "string1" );
This should, hopefully, fix the issue you are having as well as give you a more flexible framework to build from. I realize this is a bit of an extreme example, and isn't exactly the question you had, but hopefully if nothing else this gives you another avenue to consider. Have fun and keep coding!