Sync DrDump crash handler with TortoiseSVN codebase
[TortoiseGit.git] / ext / CrashServer / CrashHandler / SendRpt / Translator.cpp
blob884a5016df7c5cd063f36470f755beed3c4840bb
1 // Copyright 2014 Idol Software, Inc.
2 //
3 // This file is part of Doctor Dump SDK.
4 //
5 // Doctor Dump SDK is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "StdAfx.h"
19 #include "Translator.h"
21 static const wchar_t* DefaultSection = L"crashhandler";
23 Translator::Translator(const wchar_t* appName, const wchar_t* company, HMODULE hImage, DWORD resId, const wchar_t* path)
24 : m_appName(appName)
25 , m_company(company)
26 , m_default(hImage, resId)
28 if (path && *path)
29 m_custom.reset(new IniFile(path));
30 // if (WINVER >= 0x0600) Use LOCALE_SNAME en-us
31 // LOCALE_SISO639LANGNAME returns en
32 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, m_userLanguage.GetBuffer(1024), 1024);
33 m_userLanguage.ReleaseBuffer(-1);
34 m_userLanguage = DefaultSection + (L"-" + m_userLanguage);
37 CStringW Translator::GetString(const wchar_t* variable)
39 CStringW result;
40 if (m_custom)
42 result = m_custom->GetString(m_userLanguage, variable);
43 if (result.IsEmpty())
44 result = m_custom->GetString(DefaultSection, variable);
46 if (result.IsEmpty())
47 result = m_default.GetString(m_userLanguage, variable);
48 if (result.IsEmpty())
49 result = m_default.GetString(DefaultSection, variable);
50 if (result.IsEmpty())
51 MessageBoxW(0, variable, L"Doesn't translated string", MB_ICONERROR);
53 result.Replace(L"\\n", L"\n");
54 result.Replace(L"[AppName]", m_appName);
55 result.Replace(L"[Company]", m_company);
57 return result;