|
35 | 35 |
|
36 | 36 | #define MAX_STRING_LENGTH (64 * 1024)
|
37 | 37 |
|
| 38 | +std::map<std::wstring, std::wstring> CLanguage::langmapBack; |
| 39 | + |
38 | 40 | bool CLanguage::LoadFile(const std::wstring& path)
|
39 | 41 | {
|
40 | 42 | static std::wstring lastLangPath;
|
41 | 43 |
|
42 |
| - // revert to original language |
| 44 | + // revert to original language, special: L1 -> L2 (fail -> L0) -> L0 (En) |
43 | 45 | if (_wcsicmp(lastLangPath.c_str(), path.c_str()))
|
44 | 46 | {
|
45 |
| - std::map<std::wstring, std::wstring> langMap2; |
| 47 | + langmapBack.clear(); |
46 | 48 | for (auto it = langmap.cbegin(); it != langmap.cend(); ++it)
|
47 | 49 | {
|
48 |
| - langMap2[it->second] = it->first; |
| 50 | + langmapBack[it->second] = it->first; |
49 | 51 | }
|
50 |
| - langmap = langMap2; |
| 52 | + langmap.clear(); |
51 | 53 | }
|
52 |
| - |
53 |
| - if (!PathFileExists(path.c_str())) |
54 |
| - return false; |
55 |
| - |
56 | 54 | lastLangPath = path;
|
57 | 55 |
|
58 |
| - // since stream classes still expect the filepath in char and not wchar_t |
59 |
| - // we need to convert the filepath to multibyte first |
60 |
| - |
61 |
| - std::ifstream file; |
62 |
| - try |
63 |
| - { |
64 |
| - } |
65 |
| - catch (std::ios_base::failure&) |
| 56 | + if (!PathFileExists(path.c_str())) |
66 | 57 | {
|
| 58 | + lastLangPath = L""; |
67 | 59 | return false;
|
68 | 60 | }
|
| 61 | + |
| 62 | + std::ifstream file; |
69 | 63 | file.open(path);
|
70 | 64 | if (!file.good())
|
71 | 65 | {
|
| 66 | + lastLangPath = L""; |
72 | 67 | return false;
|
73 | 68 | }
|
74 | 69 | auto line = std::make_unique<char[]>(2 * MAX_STRING_LENGTH);
|
@@ -163,9 +158,33 @@ std::wstring CLanguage::GetTranslatedString(const std::wstring& s)
|
163 | 158 |
|
164 | 159 | std::wstring CLanguage::GetTranslatedString(const std::wstring& s, std::map<std::wstring, std::wstring>* pLangMap)
|
165 | 160 | {
|
166 |
| - auto foundIt = pLangMap->find(s); |
| 161 | + if (s.length() == 0) |
| 162 | + { |
| 163 | + return s; |
| 164 | + } |
| 165 | + |
| 166 | + auto foundIt = langmapBack.find(s); |
| 167 | + if ((foundIt != langmapBack.end()) && (!foundIt->second.empty())) |
| 168 | + { |
| 169 | + if (!pLangMap->empty()) |
| 170 | + { |
| 171 | + auto foundIt2 = pLangMap->find(foundIt->second); |
| 172 | + if ((foundIt2 != pLangMap->end()) && (!foundIt2->second.empty())) |
| 173 | + { |
| 174 | + return foundIt2->second; |
| 175 | + } |
| 176 | + } |
| 177 | + // msgId |
| 178 | + return foundIt->second; |
| 179 | + } |
| 180 | + |
| 181 | + // windows initializing |
| 182 | + foundIt = pLangMap->find(s); |
167 | 183 | if ((foundIt != pLangMap->end()) && (!foundIt->second.empty()))
|
| 184 | + { |
168 | 185 | return foundIt->second;
|
| 186 | + } |
| 187 | + |
169 | 188 | return s;
|
170 | 189 | }
|
171 | 190 |
|
|
0 commit comments