Skip to content
This repository
Browse code

Fied the translation and translation update for names contained withi…

…n global scripts.

This fixes skills, items, status effects, ... names and description when displayed
in another language than english.
  • Loading branch information...
commit 1559c6c204a2cd7b6780168ce99276e916aa999c 1 parent 7b1549a
Yohann Ferreira authored
10 src/common/global/global.cpp
@@ -91,6 +91,10 @@ GameGlobal::~GameGlobal()
91 91
92 92 ClearAllData();
93 93
  94 + _CloseGlobalScripts();
  95 +} // GameGlobal::~GameGlobal()
  96 +
  97 +void GameGlobal::_CloseGlobalScripts() {
94 98 // Close all persistent script files
95 99 _global_script.CloseFile();
96 100
@@ -130,9 +134,9 @@ GameGlobal::~GameGlobal()
130 134 _map_sprites_script.CloseFile();
131 135 _map_objects_script.CloseFile();
132 136 _map_treasures_script.CloseFile();
133   -} // GameGlobal::~GameGlobal()
  137 +}
134 138
135   -bool GameGlobal::SingletonInitialize()
  139 +bool GameGlobal::_LoadGlobalScripts()
136 140 {
137 141 // Open up the persistent script files
138 142 if(_global_script.OpenFile("dat/global.lua") == false) {
@@ -202,7 +206,7 @@ bool GameGlobal::SingletonInitialize()
202 206 return false;
203 207
204 208 return true;
205   -} // bool GameGlobal::SingletonInitialize()
  209 +}
206 210
207 211 void GameGlobal::ClearAllData()
208 212 {
13 src/common/global/global.h
@@ -158,7 +158,12 @@ class GameGlobal : public hoa_utils::Singleton<GameGlobal>
158 158 public:
159 159 ~GameGlobal();
160 160
161   - bool SingletonInitialize();
  161 + bool SingletonInitialize()
  162 + { return _LoadGlobalScripts(); }
  163 +
  164 + //! Reloads the persistent scripts. Used when changing the language for instance.
  165 + bool ReloadGlobalScripts()
  166 + { _CloseGlobalScripts(); return _LoadGlobalScripts(); }
162 167
163 168 /** \brief Deletes all data stored within the GameGlobal class object
164 169 *** This function is meant to be called when the user quits the current game instance
@@ -795,6 +800,12 @@ class GameGlobal : public hoa_utils::Singleton<GameGlobal>
795 800 *** \param group_name The name of the event group to load
796 801 **/
797 802 void _LoadEvents(hoa_script::ReadScriptDescriptor &file, const std::string &group_name);
  803 +
  804 + //! Loads every persistent scripts, used at the global initialization time.
  805 + bool _LoadGlobalScripts();
  806 +
  807 + //! Unloads every persistent scripts by closing their files.
  808 + void _CloseGlobalScripts();
798 809 }; // class GameGlobal : public hoa_utils::Singleton<GameGlobal>
799 810
800 811 //-----------------------------------------------------------------------------
2  src/engine/script/script_write.cpp
@@ -260,7 +260,6 @@ void WriteScriptDescriptor::WriteString(const int32 key, const std::string &valu
260 260
261 261 // WriteUString can not use the _WriteData helper because it needs to do additional
262 262 // checking and add quotation marks around its value.
263   -// TODO: Write strings with a call to the gettext library to retrieve translated strings
264 263 void WriteScriptDescriptor::WriteUString(const std::string &key, const std::string &value)
265 264 {
266 265 WriteString(key, value);
@@ -387,7 +386,6 @@ void WriteScriptDescriptor::WriteStringVector(const int32 key, std::vector<std::
387 386
388 387 // WriteUString can not use the _WriteData helper because it needs to do additional
389 388 // checking and add quotation marks around its value.
390   -// TODO: Write strings with a call to the gettext library to retrieve translated strings
391 389 void WriteScriptDescriptor::WriteUStringVector(const std::string &key, std::vector<std::string>& vect)
392 390 {
393 391 WriteStringVector(key, vect);
2  src/engine/system.cpp
@@ -303,7 +303,7 @@ void Reinitl10n()
303 303 }
304 304
305 305
306   -void SystemEngine::SetLanguage(std::string lang)
  306 +void SystemEngine::SetLanguage(const std::string& lang)
307 307 {
308 308 Reinitl10n();
309 309
4 src/engine/system.h
@@ -430,14 +430,14 @@ class SystemEngine : public hoa_utils::Singleton<SystemEngine>
430 430 /** \brief Used to determine what language the game is running in.
431 431 *** \return The language that the game is running in.
432 432 **/
433   - std::string GetLanguage() const {
  433 + const std::string& GetLanguage() const {
434 434 return _language;
435 435 }
436 436
437 437 /** \brief Sets the language that the game should use.
438 438 *** \param lang A two-character string representing the language to execute the game in
439 439 **/
440   - void SetLanguage(std::string lang);
  440 + void SetLanguage(const std::string& lang);
441 441
442 442 /** \brief Determines whether the user is done with the game.
443 443 *** \return False if the user would like to exit the game.
11 src/main.cpp
@@ -288,8 +288,6 @@ void InitializeEngine() throw(Exception)
288 288 GUIManager = GUISystem::SingletonCreate();
289 289 GlobalManager = GameGlobal::SingletonCreate();
290 290
291   - // TODO: Open the user setting's file and apply those settings
292   -
293 291 if(VideoManager->SingletonInitialize() == false) {
294 292 throw Exception("ERROR: unable to initialize VideoManager", __FILE__, __LINE__, __FUNCTION__);
295 293 }
@@ -315,9 +313,6 @@ void InitializeEngine() throw(Exception)
315 313 if(ModeManager->SingletonInitialize() == false) {
316 314 throw Exception("ERROR: unable to initialize ModeManager", __FILE__, __LINE__, __FUNCTION__);
317 315 }
318   - if(GlobalManager->SingletonInitialize() == false) {
319   - throw Exception("ERROR: unable to initialize GlobalManager", __FILE__, __LINE__, __FUNCTION__);
320   - }
321 316
322 317 // Set the window icon
323 318 #ifdef _WIN32
@@ -369,6 +364,12 @@ void InitializeEngine() throw(Exception)
369 364 throw Exception("ERROR: unable to initialize GUIManager", __FILE__, __LINE__, __FUNCTION__);
370 365 }
371 366
  367 + // This loads the game global script, once everything is ready,
  368 + // and will permit to load skills, items and other translatable strings
  369 + // using the correct settings language.
  370 + if(!GlobalManager->SingletonInitialize())
  371 + throw Exception("ERROR: unable to initialize GlobalManager", __FILE__, __LINE__, __FUNCTION__);
  372 +
372 373 SystemManager->InitializeTimers();
373 374 } // void InitializeEngine()
374 375
3  src/modes/boot/boot.cpp
@@ -910,6 +910,9 @@ void BootMode::_OnLanguageSelect()
910 910
911 911 // Reload all the translatable text in the boot menus.
912 912 _ReloadTranslatableMenus();
  913 +
  914 + // Reloads the global scripts to update their inner translatable strings
  915 + GlobalManager->ReloadGlobalScripts();
913 916 }
914 917
915 918

0 comments on commit 1559c6c

Please sign in to comment.
Something went wrong with that request. Please try again.