aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/UI/FileManager/LangPage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/UI/FileManager/LangPage.cpp')
-rw-r--r--CPP/7zip/UI/FileManager/LangPage.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/CPP/7zip/UI/FileManager/LangPage.cpp b/CPP/7zip/UI/FileManager/LangPage.cpp
new file mode 100644
index 0000000..47e7894
--- /dev/null
+++ b/CPP/7zip/UI/FileManager/LangPage.cpp
@@ -0,0 +1,120 @@
1// LangPage.cpp
2
3#include "StdAfx.h"
4
5#include "../../../Common/Lang.h"
6
7#include "../../../Windows/FileFind.h"
8#include "../../../Windows/ResourceString.h"
9
10#include "HelpUtils.h"
11#include "LangPage.h"
12#include "LangPageRes.h"
13#include "LangUtils.h"
14#include "RegistryUtils.h"
15
16using namespace NWindows;
17
18static const UInt32 kLangIDs[] =
19{
20 IDT_LANG_LANG
21};
22
23#define kLangTopic "fm/options.htm#language"
24
25static void NativeLangString(UString &dest, const wchar_t *s)
26{
27 dest += " (";
28 dest += s;
29 dest += ')';
30}
31
32bool LangOpen(CLang &lang, CFSTR fileName);
33
34bool CLangPage::OnInit()
35{
36 LangSetDlgItems(*this, kLangIDs, ARRAY_SIZE(kLangIDs));
37
38 _langCombo.Attach(GetItem(IDC_LANG_LANG));
39
40 UString temp = MyLoadString(IDS_LANG_ENGLISH);
41 NativeLangString(temp, MyLoadString(IDS_LANG_NATIVE));
42 int index = (int)_langCombo.AddString(temp);
43 _langCombo.SetItemData(index, _paths.Size());
44 _paths.Add(L"-");
45 _langCombo.SetCurSel(0);
46
47 const FString dirPrefix = GetLangDirPrefix();
48 NFile::NFind::CEnumerator enumerator;
49 enumerator.SetDirPrefix(dirPrefix);
50 NFile::NFind::CFileInfo fi;
51 CLang lang;
52 UString error;
53
54 while (enumerator.Next(fi))
55 {
56 if (fi.IsDir())
57 continue;
58 const unsigned kExtSize = 4;
59 if (fi.Name.Len() < kExtSize)
60 continue;
61 const unsigned pos = fi.Name.Len() - kExtSize;
62 if (!StringsAreEqualNoCase_Ascii(fi.Name.Ptr(pos), ".txt"))
63 {
64 // if (!StringsAreEqualNoCase_Ascii(fi.Name.Ptr(pos), ".ttt"))
65 continue;
66 }
67
68 if (!LangOpen(lang, dirPrefix + fi.Name))
69 {
70 error.Add_Space_if_NotEmpty();
71 error += fs2us(fi.Name);
72 continue;
73 }
74
75 const UString shortName = fs2us(fi.Name.Left(pos));
76 UString s = shortName;
77 const wchar_t *eng = lang.Get(IDS_LANG_ENGLISH);
78 if (eng)
79 s = eng;
80 const wchar_t *native = lang.Get(IDS_LANG_NATIVE);
81 if (native)
82 NativeLangString(s, native);
83 index = (int)_langCombo.AddString(s);
84 _langCombo.SetItemData(index, _paths.Size());
85 _paths.Add(shortName);
86 if (g_LangID.IsEqualTo_NoCase(shortName))
87 _langCombo.SetCurSel(index);
88 }
89
90 if (!error.IsEmpty())
91 MessageBoxW(0, error, L"Error in Lang file", MB_ICONERROR);
92 return CPropertyPage::OnInit();
93}
94
95LONG CLangPage::OnApply()
96{
97 int pathIndex = (int)_langCombo.GetItemData_of_CurSel();
98 if (_needSave)
99 SaveRegLang(_paths[pathIndex]);
100 _needSave = false;
101 ReloadLang();
102 LangWasChanged = true;
103 return PSNRET_NOERROR;
104}
105
106void CLangPage::OnNotifyHelp()
107{
108 ShowHelpWindow(kLangTopic);
109}
110
111bool CLangPage::OnCommand(int code, int itemID, LPARAM param)
112{
113 if (code == CBN_SELCHANGE && itemID == IDC_LANG_LANG)
114 {
115 _needSave = true;
116 Changed();
117 return true;
118 }
119 return CPropertyPage::OnCommand(code, itemID, param);
120}