/*
Copyright (c) 2017 DIVIDE-Studio
Copyright (c) 2009 Ionut Cava
This file is part of DIVIDE Framework.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software
and associated documentation files (the "Software"), to deal in the Software
without restriction,
including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _LOCALE_H_
#define _LOCALE_H_
static const char* DEFAULT_LANG = "enGB";
#include "Platform/Headers/PlatformDefines.h"
namespace Divide {
enum class ErrorCode : I32;
namespace Locale {
namespace detail {
/// Is everything loaded and ready for use?
static bool s_initialized = false;
/// Default language can be set at compile time
static stringImpl s_localeFile = DEFAULT_LANG;
/// Each string key in the map matches a key in the language ini file
/// each string value in the map matches the value in the ini file for the given key
/// Basicly, the hashMapImpl is a direct copy of the [language] section of the
/// give ini file
static hashMapImpl<U64, stringImpl> s_languageTable;
static vectorImpl<DELEGATE_CBK<void, const char* /*new language*/>> s_languageChangeCallbacks;
/// Callback for external file changes.
void onLanguageFileModify(const char* languageFile);
}; //detail
/// Reset everything and load the specified language file.
ErrorCode init(const stringImpl& newLanguage = DEFAULT_LANG);
/// clear the language table
void clear();
/// perform maintnance tasks
void idle();
/// Altough the language can be set at compile time, in-game options may support
/// language changes
void changeLanguage(const stringImpl& newLanguage);
/// Add a function to be called on each language change
void addChangeLanguageCallback(const DELEGATE_CBK<void, const char* /*new language*/>& cbk);
/// Query the current language code to detect changes
inline const stringImpl& currentLanguage() { return detail::s_localeFile; }
/// usage: Locale::get(_ID("A_B_C")) or Locale::get(_ID("A_B_C"),"X") where "A_B_C" is the
/// language key we want
/// and "X" is a default string in case the key does not exist in the INI file
const char* get(U64 key, const char* defaultValue);
const char* get(U64 key);
}; // namespace Locale
}; // namespace Divide
#endif

[IonutCava]- Replace all string indexed maps with unsigned long long indexed maps and add both compile time and runtime hashing functions to convert strings to the proper indices— Balancing the calls between _ID and _ID_RT can reduce map lookup overhead, especially with ParamHandler and Locale::get