[AD] About get_config_text and it's actual problems |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
Hi. I am not sending a bug report about the problem I had with get_config_text, because the problem was not having updated the local allegro.cfg file of my game, which didn't have the language variable in a system section. But I have found another problem with the current system, and it's that there's no easy way to switch languages at run time. I have tried the following example which attempted to print the same get_config_text string in different languages, and it works, but it's unpretty: #include <allegro.h> void _load_config_text (); int main (void) { char buf[256]; install_allegro (SYSTEM_NONE, &errno, atexit); /* This code will successfully reload language especifications for * english (it's not my default language, so I see a difference :-)) */ set_config_string ("system", "language", "en"); _load_config_text(); /* However this uses a private call */ allegro_message ("English message: %s\n", get_config_text ("Cancel")); /* Now the following does the trick, setting a global public config * file which can be modified by Allegro, but also read from */ set_config_file ("estext.cfg"); allegro_message ("Spanish message: %s\n", get_config_text ("Cancel")); /* Finally, this does the same, but shows how detext.cfg would be * modified, which is _bad_, especially if the allegro-user is expecting * to save it's other variables to whatever.cfg and they end up in the * language file. */ set_config_file ("detext.cfg"); allegro_message ("German message: %s\n", get_config_text ("Cancel")); set_config_string ("test", "test", "test"); /* At this exit point, detext.cfg _is_ modified */ return 0; } END_OF_MAIN(); The example is self explanatory: unless I've overlooked some other function, there's no easy way to change languages without completely shutting down allegro to reinitialize it or calling a private function, which is used by allegro _only_ in install_allegro. And calling install_allegro several times doesn't look very good, especially because the function may change the system_driver variable. I don't know what consequences may have that, but doesn't look good. The only way I found to change language was using an external .cfg file, but then all the config variables will be written to this file, as shown with the last set_config_string of the example. Therefore, unless someone shows a simple way to switch languages at run time, I would like to propose the following patch, which just makes _load_config_text public as reload_config_texts. Thanks to this function Allegro can update the needed internal variables without touching anything else, and I think it looks much better than patching install_allegro. -- Grzegorz Adam Hankiewicz gradha@xxxxxxxxxx http://gradha.infierno.org
Attachment:
language_patch.gz
Description: Binary data
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |