Linux multi-monitor fullscreen support
[ryzomcore.git] / snowballs2 / client / src / internationalization.cpp
blobde7bddfcc863f2bc1d1670fecfe8d5937ee509f5
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <nel/misc/types_nl.h>
18 #include "internationalization.h"
20 // STL includes
22 // NeL includes
23 // #include <nel/misc/debug.h>
24 #include <nel/misc/i18n.h>
26 // Project includes
27 #include "snowballs_client.h"
28 #include "snowballs_config.h"
29 #include "configuration.h"
31 using namespace std;
32 using namespace NLMISC;
34 namespace SBCLIENT {
36 class _CI18NLoadProxy : public CI18N::ILoadProxy
38 public:
39 _CI18NLoadProxy() { }
40 virtual ~_CI18NLoadProxy() { }
41 virtual void loadStringFile(const std::string &filename, ucstring &text)
43 CI18N::readTextFile(filename, text);
44 text += ucstring("\n"
45 #if defined (NL_DEBUG)
46 # if defined (NL_DEBUG_FAST)
47 "COMPILE_MODE [NL_DEBUG (NL_DEBUG_FAST)]\n"
48 # elif defined (NL_DEBUG_INSTRUMENT)
49 "COMPILE_MODE [NL_DEBUG (NL_DEBUG_INSTRUMENT)]\n"
50 # else
51 "COMPILE_MODE [NL_DEBUG]\n"
52 # endif
53 #elif defined (NL_RELEASE_DEBUG)
54 "COMPILE_MODE [NL_RELEASE_DEBUG]\n"
55 #elif defined (NL_RELEASE)
56 # if defined (NL_NO_DEBUG)
57 "COMPILE_MODE [NL_RELEASE (NL_NO_DEBUG)]\n"
58 # else
59 "COMPILE_MODE [NL_RELEASE]\n"
60 # endif
61 #endif
62 #if FINAL_VERSION
63 "RELEASE_TYPE [FINAL_VERSION]\n"
64 #else
65 "RELEASE_TYPE [DEVELOPER_VERSION]\n"
66 #endif
67 "VERSION_NUMBER [" SBCLIENT_VERSION "]\n");
71 static _CI18NLoadProxy _I18NLoadProxy;
72 static std::vector<void (*)()> _Callbacks;
74 void CInternationalization::enableCallback(void (*cb)())
76 _Callbacks.push_back(cb);
79 void CInternationalization::disableCallback(void (*cb)())
81 std::vector<void (*)()>::iterator it(_Callbacks.begin()), end(_Callbacks.end());
82 for (; it != end; ++it) if (*it == cb) { _Callbacks.erase(it); return; }
83 nlassert(false);
86 static void cbLanguageCode(CConfigFile::CVar &var)
88 CI18N::load(var.asString());
89 std::vector<void (*)()>::iterator it(_Callbacks.begin()), end(_Callbacks.end());
90 for (; it != end; ++it) (*it)();
93 void CInternationalization::init()
95 // check stuff we need
96 nlassert(ConfigFile);
98 // set the load proxy
99 nlassert(!_Callbacks.size());
100 CI18N::setLoadProxy(&_I18NLoadProxy);
102 // set the language code
103 CConfiguration::setAndCallback("LanguageCode", cbLanguageCode);
106 void CInternationalization::release()
108 // i18n itself cannot be released, but is 'ok' since static
109 CConfiguration::dropCallback("LanguageCode");
111 // drop the load proxy
112 CI18N::setLoadProxy(NULL);
113 nlassert(!_Callbacks.size());
116 } /* namespace SBCLIENT */
118 /* end of file */