OLD | NEW |
1 #include <fstream> | 1 #include <fstream> |
2 #include <stdexcept> | 2 #include <stdexcept> |
3 #include <Windows.h> | 3 #include <Windows.h> |
4 | 4 |
5 #include "Dictionary.h" | 5 #include "Dictionary.h" |
6 #include "Utils.h" | 6 #include "Utils.h" |
7 | 7 |
8 Dictionary* Dictionary::instance = 0; | 8 Dictionary* Dictionary::instance = 0; |
9 | 9 |
10 const std::wstring baseLocale = L"en"; | 10 const std::wstring baseLocale = L"en"; |
11 | 11 |
12 Dictionary::Dictionary(const std::wstring& locale) | 12 Dictionary::Dictionary( const std::wstring& locale, std::wstring basePath ) |
13 { | 13 { |
14 std::wstring basePath = GetDllDir() + L"locales\\"; | |
15 | |
16 // Always load base locale first - that's our fallback | 14 // Always load base locale first - that's our fallback |
17 ReadDictionary(basePath, baseLocale); | 15 ReadDictionary(basePath, baseLocale); |
18 | 16 |
19 // Now try to load by full locale code | 17 // Now try to load by full locale code |
20 if (locale != baseLocale && !ReadDictionary(basePath, locale)) | 18 if (locale != baseLocale && !ReadDictionary(basePath, locale)) |
21 { | 19 { |
22 // Fall back to short locale name | 20 // Fall back to short locale name |
23 size_t pos = locale.find(L'-'); | 21 size_t pos = locale.find(L'-'); |
24 if (pos != std::wstring::npos && locale.compare(0, pos, baseLocale) != 0) | 22 if (pos != std::wstring::npos && locale.compare(0, pos, baseLocale) != 0) |
25 ReadDictionary(basePath, locale.substr(0, pos)); | 23 ReadDictionary(basePath, locale.substr(0, pos)); |
26 } | 24 } |
27 } | 25 } |
28 | 26 |
29 void Dictionary::Create(const std::wstring& locale) | 27 void Dictionary::Create(const std::wstring& locale, std::wstring basePath ) |
30 { | 28 { |
31 if (!instance) | 29 if (!instance) |
32 instance = new Dictionary(locale); | 30 instance = new Dictionary(locale, basePath); |
33 } | 31 } |
34 | 32 |
35 Dictionary* Dictionary::GetInstance() | 33 Dictionary* Dictionary::GetInstance() |
36 { | 34 { |
37 if (!instance) | 35 if (!instance) |
38 throw std::runtime_error("Attempt to access dictionary before creating"); | 36 throw std::runtime_error("Attempt to access dictionary before creating"); |
39 | 37 |
40 return instance; | 38 return instance; |
41 } | 39 } |
42 | 40 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 79 } |
82 | 80 |
83 std::wstring Dictionary::Lookup(const std::string& section, const std::string& k
ey) const | 81 std::wstring Dictionary::Lookup(const std::string& section, const std::string& k
ey) const |
84 { | 82 { |
85 DataType::const_iterator it = data.find(KeyType(section, key)); | 83 DataType::const_iterator it = data.find(KeyType(section, key)); |
86 if (it == data.end()) | 84 if (it == data.end()) |
87 return L"### MISSING STRING [" + ToUtf16String(section) + L", " + ToUtf16Str
ing(key) + L"] ###"; | 85 return L"### MISSING STRING [" + ToUtf16String(section) + L", " + ToUtf16Str
ing(key) + L"] ###"; |
88 | 86 |
89 return it->second; | 87 return it->second; |
90 } | 88 } |
OLD | NEW |