Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FbLocale.cpp « MyRuLib « sources - github.com/lintest/myrulib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb32ecc95d24f8efa73c8fce507c66aa20e2089f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//////////////////////////////////////////////////////////////////////
//                                                                  //
//  Use this command to create or update locale catalog:            //
//                                                                  //
//  xgettext -CFnj -k_ -o locale/ru.po *.cpp *.h ./*/*.cpp ./*/*.h  //
//                                                                  //
//////////////////////////////////////////////////////////////////////

#include "FbLocale.h"
#include <wx/wfstream.h>
#include "FbDatabase.h"
#include "FbConst.h"
#include "controls/FbChoiceCtrl.h"

#ifdef __WXMSW__

#include <wx/msw/private.h>

bool FbLocale::LoadResource(const wxLanguageInfo * info, const wxString & filename)
{
	HRSRC hResource = ::FindResource(wxGetInstance(), info->CanonicalName.c_str(), wxT("RC_DATA"));
	if ( !hResource ) return false;

	HGLOBAL hData = ::LoadResource(wxGetInstance(), hResource);
	if ( !hData ) return false;

	void * data = ::LockResource(hData);
	if ( !data ) return false;

	unsigned long size = ::SizeofResource(wxGetInstance(), hResource);

	return Save(filename, data, size);
}

bool FbLocale::Init(int language, int flags)
{
	const wxLanguageInfo * info = FbLocale::GetLanguageInfo(language);

	#ifdef wxHAVE_TCHAR_SUPPORT
	if (info) wxSetlocale(LC_COLLATE, info->CanonicalName);
	#endif

	wxFileName filename = FbConfigDatabase::GetConfigName();
	filename.SetExt(wxT("mo"));
	if (language == wxLANGUAGE_DEFAULT) language = GetSystemLanguage();
	bool ok = info && LoadResource(info, filename.GetFullPath());

	if (ok) AddCatalogLookupPathPrefix(filename.GetPath());
	bool res = wxLocale::Init(language, flags);
	if (ok) AddCatalog(filename.GetName());
	return res;
}

#else

bool FbLocale::Init(int language, int flags)
{
	const wxLanguageInfo * info = FbLocale::GetLanguageInfo(language);

	#ifdef wxHAVE_TCHAR_SUPPORT
	if (info) wxSetlocale(LC_COLLATE, info->CanonicalName);
	#endif

	wxFileName filename = FbConfigDatabase::GetConfigName();

	#ifdef FB_INCLUDE_LOCALE

	filename.SetExt(wxT("mo"));

	if (language == wxLANGUAGE_DEFAULT) language = GetSystemLanguage();

	bool ok = false;
	switch (language) {
		case wxLANGUAGE_RUSSIAN: {
			#include "ru.inc"
			ok = Save(filename, locale_binary_file, sizeof(locale_binary_file));
		} break;
		case wxLANGUAGE_UKRAINIAN: {
			#include "uk.inc"
			ok = Save(filename, locale_binary_file, sizeof(locale_binary_file));
		} break;
		case wxLANGUAGE_BELARUSIAN: {
			#include "be.inc"
			ok = Save(filename, locale_binary_file, sizeof(locale_binary_file));
		} break;
		case wxLANGUAGE_CZECH: {
			#include "cs.inc"
			ok = Save(filename, locale_binary_file, sizeof(locale_binary_file));
		} break;
		case wxLANGUAGE_SWEDISH: {
			#include "sv.inc"
			ok = Save(filename, locale_binary_file, sizeof(locale_binary_file));
		} break;
	}

	if (ok) AddCatalogLookupPathPrefix(filename.GetPath());

	#else

	bool ok = true;

	#endif //FB_INCLUDE_LOCALE

	bool res = wxLocale::Init(language, flags);

	if (ok) AddCatalog(filename.GetName());

	return res;
}

#endif // __WXMSW__

bool FbLocale::Save(const wxFileName &filename, const void *data, size_t size)
{
	wxLogNull log;
	wxFileOutputStream out(filename.GetFullPath());
	out.Write(data, size);
	return true;
}

void FbLocale::Fill(FbChoiceInt * choise, int value)
{
	choise->Append(wxT("Default"), wxLANGUAGE_DEFAULT);
	choise->SetSelection(0);

	wxLanguage langs[] = {
		wxLANGUAGE_ENGLISH,
		wxLANGUAGE_RUSSIAN,
		wxLANGUAGE_UKRAINIAN,
		wxLANGUAGE_BELARUSIAN,
		wxLANGUAGE_CZECH,
		wxLANGUAGE_SWEDISH,
	};
	size_t count = sizeof(langs) / sizeof(wxLanguage);

	for (size_t i = 0; i < count; i++) {
		wxLanguage lang = langs[i];
		const wxLanguageInfo * info = wxLocale::GetLanguageInfo(lang);
		int index = choise->Append(info->Description, lang);
		if (lang == value) choise->SetSelection(index);
	}
}