3
// I18N = I....18..dots.....N = INTERNATIONALIZATION
5
// Super simple I18N library.
6
// Just enough to be useful and usable.
7
// Spits out easy-to-edit utf-8 .INI files.
9
// As usual, everything is UTF-8. Nothing else allowed.
15
#include "base/stringutil.h"
16
#include "file/ini_file.h"
18
// Reasonably thread safe.
23
I18NEntry(const std::string &t) : text(t), readFlag(false) {}
24
I18NEntry() : readFlag(false) {}
29
struct I18NCandidate {
30
I18NCandidate() : key(0), defVal(0) {}
31
I18NCandidate(const char *k, const char *d) : key(k), defVal(d) {}
38
// NOTE: Name must be a global constant string - it is not copied.
39
I18NCategory(const char *name) : name_(name) {}
40
const char *T(const char *key, const char *def = 0);
41
const char *T(const std::string &key) {
42
return T(key.c_str(), nullptr);
45
const std::map<std::string, std::string> &Missed() const {
49
void SetMap(const std::map<std::string, std::string> &m);
50
const std::map<std::string, I18NEntry> &GetMap() { return map_; }
51
void ClearMissed() { missedKeyLog_.clear(); }
52
const char *GetName() const { return name_.c_str(); }
55
I18NCategory(I18NRepo *repo, const char *name) : name_(name) {}
59
std::map<std::string, I18NEntry> map_;
60
std::map<std::string, std::string> missedKeyLog_;
62
// Noone else can create these.
63
friend class I18NRepo;
65
DISALLOW_COPY_AND_ASSIGN(I18NCategory);
73
bool IniExists(const std::string &languageID) const;
74
bool LoadIni(const std::string &languageID, const std::string &overridePath = ""); // NOT the filename!
75
void SaveIni(const std::string &languageID);
77
I18NCategory *GetCategory(const char *categoryName);
78
const char *T(const char *category, const char *key, const char *def = 0);
81
std::string GetIniPath(const std::string &languageID) const;
83
I18NCategory *LoadSection(const IniFile::Section *section, const char *name);
84
void SaveSection(IniFile &ini, IniFile::Section *section, I18NCategory *cat);
86
std::map<std::string, I18NCategory *> cats_;
88
DISALLOW_COPY_AND_ASSIGN(I18NRepo);
91
extern I18NRepo i18nrepo;
93
// These are simply talking to the one global instance of I18NRepo.
95
inline I18NCategory *GetI18NCategory(const char *categoryName) {
98
return i18nrepo.GetCategory(categoryName);
101
inline const char *T(const char *category, const char *key, const char *def = 0) {
102
return i18nrepo.T(category, key, def);