53 lines
1.6 KiB
C++
53 lines
1.6 KiB
C++
/**
|
|
* @file Translation.h
|
|
* @brief Translation class
|
|
* @date May 9, 2017
|
|
* @author J.C.M. Raats
|
|
* @copyright 2015 Dual Inventive Technology Centre B.V.
|
|
*
|
|
* Translation class. Use this class to get a message in a specific language
|
|
*/
|
|
#ifndef INCLUDE_DI_TRANSLATION_H_
|
|
#define INCLUDE_DI_TRANSLATION_H_
|
|
|
|
#include <mutex>
|
|
#include <shared_mutex>
|
|
#include <string>
|
|
#include <memory>
|
|
#include <map>
|
|
|
|
namespace Di {
|
|
|
|
/**
|
|
* @class Translation
|
|
*
|
|
* Translation class. Use this class to get a message in a specific language
|
|
*/
|
|
class Translation {
|
|
public:
|
|
explicit Translation(const std::string &basedir);
|
|
std::string getDefaultTranslation(const std::string key, ...);
|
|
std::string getTranslation(const std::string &key, const std::string langCode, ...);
|
|
void reloadLanguage(const std::string &langCode);
|
|
void setDefaultLanguage(const std::string &langCode);
|
|
bool isDefaultLanguage(const std::string &langCode);
|
|
|
|
private:
|
|
mutable std::shared_timed_mutex __mutex;
|
|
|
|
std::string __basedir;
|
|
std::string __defaultLanguage;
|
|
std::map<std::string, std::map<std::string, std::string>> __translations;
|
|
|
|
std::shared_ptr<std::string> __getTranslationText(const std::string &key, const std::string &langCode);
|
|
std::string __formatTranslationText(std::shared_ptr<std::string> format, va_list args);
|
|
std::shared_ptr<std::string> __getTranslation(const std::string &key, const std::string &langCode);
|
|
void __loadLanguage(const std::string &langCode, bool forceReload);
|
|
std::string __getFilePath(const std::string &langCode);
|
|
bool __fileExists(const std::string &filename);
|
|
};
|
|
|
|
} // namespace Di
|
|
|
|
#endif // INCLUDE_DI_TRANSLATION_H_
|