1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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"
23 // #include <nel/misc/debug.h>
24 #include <nel/misc/i18n.h>
27 #include "snowballs_client.h"
28 #include "snowballs_config.h"
29 #include "configuration.h"
32 using namespace NLMISC
;
36 class _CI18NLoadProxy
: public CI18N::ILoadProxy
40 virtual ~_CI18NLoadProxy() { }
41 virtual void loadStringFile(const std::string
&filename
, ucstring
&text
)
43 CI18N::readTextFile(filename
, text
);
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"
51 "COMPILE_MODE [NL_DEBUG]\n"
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"
59 "COMPILE_MODE [NL_RELEASE]\n"
63 "RELEASE_TYPE [FINAL_VERSION]\n"
65 "RELEASE_TYPE [DEVELOPER_VERSION]\n"
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; }
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
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 */