summaryrefslogtreecommitdiff
path: root/plugins/TipperYM/src/translations.cpp
blob: aee33a5dc83ad5f17d9f45ede363bb304902a60e (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
/*
Copyright (C) 2006-2007 Scott Ellis
Copyright (C) 2007-2011 Jan Holub

This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this file; see the file license.txt.  If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  
*/

#include "stdafx.h"

int iTransFuncsCount = 0;
DBVTranslation *translations = 0;

DWORD dwNextFuncId;
HANDLE hServiceAdd;

void AddTranslation(DBVTranslation *newTrans) 
{
	DBVTranslation *ptranslations = (DBVTranslation *)mir_realloc(translations, sizeof(DBVTranslation) * (iTransFuncsCount+1));
	if (ptranslations == NULL)
		return;
	translations = ptranslations;
	iTransFuncsCount++;
	translations[iTransFuncsCount - 1] = *newTrans;
	
	char *szName = mir_t2a(newTrans->swzName);
	char szSetting[256];
	mir_snprintf(szSetting, sizeof(szSetting),"Trans_%s",szName);

	if (mir_tstrcmp(newTrans->swzName, _T("[No translation]")) == 0) 
	{
		translations[iTransFuncsCount - 1].id = 0;
	} 
	else 
	{
		DWORD id = db_get_dw(0, MODULE_ITEMS, szSetting, 0);
		if (id != 0) 
		{
			translations[iTransFuncsCount - 1].id = id;
			if (dwNextFuncId <= id) dwNextFuncId = id + 1;
		} 
		else
		{
			translations[iTransFuncsCount - 1].id = dwNextFuncId++;
			db_set_dw(0, MODULE_ITEMS, szSetting, translations[iTransFuncsCount - 1].id);
		}

		db_set_dw(0, MODULE_ITEMS, "NextFuncId", dwNextFuncId);
	}

	mir_free(szName);
}

TCHAR *NullTranslation(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	if (DBGetContactSettingAsString(hContact, szModuleName, szSettingName, buff, bufflen))
		return buff;
	return NULL;
}

TCHAR* TimestampToShortDate(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	DWORD ts = db_get_dw(hContact, szModuleName, szSettingName, 0);
	if (ts == 0)
		return 0;
	
	return TimeZone_ToStringT(ts, _T("d"), buff, bufflen);
}

TCHAR* TimestampToLongDate(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	DWORD ts = db_get_dw(hContact, szModuleName, szSettingName, 0);
	if (ts == 0)
		return 0;
	
	return TimeZone_ToStringT(ts, _T("D"), buff, bufflen);
}

TCHAR* TimestampToTime(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	DWORD ts = db_get_dw(hContact, szModuleName, szSettingName, 0);
	if (ts == 0)
		return 0;
	
	return TimeZone_ToStringT(ts, _T("s"), buff, bufflen);
}

TCHAR* TimestampToTimeNoSecs(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	DWORD ts = db_get_dw(hContact, szModuleName, szSettingName, 0);
	if (ts == 0)
		return 0;
	
	return TimeZone_ToStringT(ts, _T("t"), buff, bufflen);
}

TCHAR* TimestampToTimeDifference(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	DWORD ts = db_get_dw(hContact, szModuleName, szSettingName, 0);
	DWORD t = (DWORD)time(0);
	if (ts == 0) return 0;
	
	DWORD diff = (ts > t) ? 0 : (t - ts);
	int d = (diff / 60 / 60 / 24);
	int h = (diff - d * 60 * 60 * 24) / 60 / 60;
	int m = (diff  - d * 60 * 60 * 24 - h * 60 * 60) / 60;
	if (d > 0)
		mir_sntprintf(buff, bufflen, TranslateT("%dd %dh %dm"), d, h, m);
	else if (h > 0)
		mir_sntprintf(buff, bufflen, TranslateT("%dh %dm"), h, m);
	else
		mir_sntprintf(buff, bufflen, TranslateT("%dm"), m);

	return buff;
}

TCHAR *SecondsToTimeDifference(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	DWORD diff = db_get_dw(hContact, szModuleName, szSettingName, 0);
	int d = (diff / 60 / 60 / 24);
	int h = (diff - d * 60 * 60 * 24) / 60 / 60;
	int m = (diff  - d * 60 * 60 * 24 - h * 60 * 60) / 60;
	if (d > 0)
		mir_sntprintf(buff, bufflen, TranslateT("%dd %dh %dm"), d, h, m);
	else if (h > 0)
		mir_sntprintf(buff, bufflen, TranslateT("%dh %dm"), h, m);
	else
		mir_sntprintf(buff, bufflen, TranslateT("%dm"), m);

	return buff;
}

TCHAR *WordToStatusDesc(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	WORD wStatus = db_get_w(hContact, szModuleName, szSettingName, ID_STATUS_OFFLINE);
	TCHAR *szStatus = pcli->pfnGetStatusModeDescription(wStatus, 0);
	_tcsncpy_s(buff, bufflen, szStatus, _TRUNCATE);
	return buff;
}

TCHAR *ByteToYesNo(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	DBVARIANT dbv;
	if (!db_get(hContact, szModuleName, szSettingName, &dbv))
	{
		if (dbv.type == DBVT_BYTE)
		{
			if (dbv.bVal != 0)
				_tcsncpy(buff, _T("Yes"), bufflen);
			else
				_tcsncpy(buff, _T("No"), bufflen);
			buff[bufflen - 1] = 0;
			db_free(&dbv);
			return buff;
		}
		db_free(&dbv);
	}
	return 0;
}

TCHAR *ByteToGender(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	BYTE val = (BYTE)db_get_b(hContact, szModuleName, szSettingName, 0);
	if (val == 'F')
		_tcsncpy(buff, TranslateT("Female"), bufflen);
	else if (val == 'M')
		_tcsncpy(buff, TranslateT("Male"), bufflen);
	else
		return 0;

	buff[bufflen - 1] = 0;
	return buff;
}

TCHAR *WordToCountry(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	char *szCountryName = 0;
	WORD cid = (WORD)db_get_w(hContact, szModuleName, szSettingName, (WORD)-1);
	if (cid != (WORD)-1 && ServiceExists(MS_UTILS_GETCOUNTRYBYNUMBER) && (szCountryName = (char *)CallService(MS_UTILS_GETCOUNTRYBYNUMBER, cid, 0)) != 0)
	{
		if (mir_strcmp(szCountryName, "Unknown") == 0)
			return 0;
		a2t(szCountryName, buff, bufflen);
		buff[bufflen - 1] = 0;
		return buff;
	}
	return 0;
}

TCHAR *DwordToIp(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	DWORD ip = db_get_dw(hContact, szModuleName, szSettingName, 0);
	if (ip) {
		unsigned char *ipc = (unsigned char*)&ip;
		mir_sntprintf(buff, bufflen, _T("%u.%u.%u.%u"), ipc[3], ipc[2], ipc[1], ipc[0]);
		return buff;
	}
	return 0;
}

bool GetInt(const DBVARIANT &dbv, int *iVal) 
{
	if (!iVal) return false;

	switch(dbv.type) 
	{
		case DBVT_BYTE:
			if (iVal) *iVal = (int)dbv.bVal;
			return true;
		case DBVT_WORD:
			if (iVal) *iVal = (int)dbv.wVal;
			return true;
		case DBVT_DWORD:
			if (iVal) *iVal = (int)dbv.dVal;
			return true;
	}
	return false;
}

TCHAR *DayMonthYearToDate(MCONTACT hContact, const char *szModuleName, const char *prefix, TCHAR *buff, int bufflen) 
{
	DBVARIANT dbv;
	char szSettingName[256];
	mir_snprintf(szSettingName, _countof(szSettingName), "%sDay", prefix);
	if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
	{
		int day = 0;
		if (GetInt(dbv, &day))
		{
			db_free(&dbv);
			mir_snprintf(szSettingName, _countof(szSettingName), "%sMonth", prefix);
			int month = 0;
			if (!db_get(hContact, szModuleName, szSettingName, &dbv))
			{
				if (GetInt(dbv, &month))
				{
					db_free(&dbv);
					mir_snprintf(szSettingName, _countof(szSettingName), "%sYear", prefix);
					int year = 0;
					if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
					{
						if (GetInt(dbv, &year) && year != 0)
						{
							db_free(&dbv);

							SYSTEMTIME st = {0};
							st.wDay = day;
							st.wMonth = month;
							st.wYear = year;

							GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, 0, buff, bufflen); 
							return buff;
						} 
						else 
							db_free(&dbv);
					}
				} 
				else 
					db_free(&dbv);
			}
		} 
		else 
			db_free(&dbv);
	}
	return 0;
}

TCHAR *DayMonthYearToAge(MCONTACT hContact, const char *szModuleName, const char *szPrefix, TCHAR *buff, int bufflen) 
{
	DBVARIANT dbv;
	char szSettingName[256];
	mir_snprintf(szSettingName, _countof(szSettingName), "%sDay", szPrefix);
	if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
	{
		int day = 0;
		if (GetInt(dbv, &day))
		{
			db_free(&dbv);
			mir_snprintf(szSettingName, _countof(szSettingName), "%sMonth", szPrefix);
			int month = 0;
			if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
			{
				if (GetInt(dbv, &month))
				{
					db_free(&dbv);
					mir_snprintf(szSettingName, _countof(szSettingName), "%sYear", szPrefix);
					int year = 0;
					if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
					{
						if (GetInt(dbv, &year) && year != 0)
						{
							db_free(&dbv);

							SYSTEMTIME now;
							GetLocalTime(&now);

							int age = now.wYear - year;
							if (now.wMonth < month || (now.wMonth == month && now.wDay < day))
								age--;
							mir_sntprintf(buff, bufflen, _T("%d"), age);
							return buff;
						} 
						else
							db_free(&dbv);
					}
				} 
				else
					db_free(&dbv);
			}
		} 
		else
			db_free(&dbv);
	}
	return 0;
}

TCHAR *HoursMinutesSecondsToTime(MCONTACT hContact, const char *szModuleName, const char *szPrefix, TCHAR *buff, int bufflen) 
{
	DBVARIANT dbv;
	char szSettingName[256];
	mir_snprintf(szSettingName, _countof(szSettingName), "%sHours", szPrefix);
	if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
	{
		int hours = 0;
		if (GetInt(dbv, &hours))
		{
			db_free(&dbv);
			mir_snprintf(szSettingName, _countof(szSettingName), "%sMinutes", szPrefix);
			int minutes = 0;
			if (!db_get(hContact, szModuleName, szSettingName, &dbv))
			{
				if (GetInt(dbv, &minutes))
				{
					db_free(&dbv);
					mir_snprintf(szSettingName, _countof(szSettingName), "%sSeconds", szPrefix);
					int seconds = 0;
					if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
					{
						GetInt(dbv, &seconds);
						db_free(&dbv);
					}

					SYSTEMTIME st = {0};
					st.wHour = hours;
					st.wMinute = minutes;
					st.wSecond = seconds;

					GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, 0, buff, bufflen); 
					return buff;
				} 
				else
					db_free(&dbv);
			}
		} 
		else
			db_free(&dbv);
	}
	return 0;
}

TCHAR *HoursMinutesToTime(MCONTACT hContact, const char *szModuleName, const char *szPrefix, TCHAR *buff, int bufflen) 
{
	DBVARIANT dbv;
	char szSettingName[256];
	mir_snprintf(szSettingName, _countof(szSettingName), "%sHours", szPrefix);
	if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
	{
		int hours = 0;
		if (GetInt(dbv, &hours)) 
		{
			db_free(&dbv);
			mir_snprintf(szSettingName, _countof(szSettingName), "%sMinutes", szPrefix);
			int minutes = 0;
			if (!db_get(hContact, szModuleName, szSettingName, &dbv))
			{
				if (GetInt(dbv, &minutes))
				{
					db_free(&dbv);

					SYSTEMTIME st = {0};
					st.wHour = hours;
					st.wMinute = minutes;

					GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, 0, buff, bufflen); 
					return buff;
				} 
				else
					db_free(&dbv);
			}
		} 
		else
			db_free(&dbv);
	}
	return 0;
}

TCHAR *DmyToTimeDifference(MCONTACT hContact, const char *szModuleName, const char *szPrefix, TCHAR *buff, int bufflen) 
{
	DBVARIANT dbv;
	char szSettingName[256];
	mir_snprintf(szSettingName, _countof(szSettingName), "%sDay", szPrefix);
	if (!db_get(hContact, szModuleName, szSettingName, &dbv))
	{
		int day = 0;
		if (GetInt(dbv, &day))
		{
			db_free(&dbv);
			mir_snprintf(szSettingName, _countof(szSettingName), "%sMonth", szPrefix);
			int month = 0;
			if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
			{
				if (GetInt(dbv, &month)) 
				{
					db_free(&dbv);
					mir_snprintf(szSettingName, _countof(szSettingName), "%sYear", szPrefix);
					int year = 0;
					if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
					{
						if (GetInt(dbv, &year)) 
						{
							db_free(&dbv);
							mir_snprintf(szSettingName, _countof(szSettingName), "%sHours", szPrefix);
							if (!db_get(hContact, szModuleName, szSettingName, &dbv))
							{
								int hours = 0;
								if (GetInt(dbv, &hours))
								{
									db_free(&dbv);
									mir_snprintf(szSettingName, _countof(szSettingName), "%sMinutes", szPrefix);
									int minutes = 0;
									if (!db_get(hContact, szModuleName, szSettingName, &dbv))
									{
										if (GetInt(dbv, &minutes)) 
										{
											db_free(&dbv);
											mir_snprintf(szSettingName, _countof(szSettingName), "%sSeconds", szPrefix);
											int seconds = 0;
											if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
											{
												GetInt(dbv, &seconds);
												db_free(&dbv);
											}

											SYSTEMTIME st = {0}, st_now;
											st.wDay = day;
											st.wMonth = month;
											st.wYear = year;
											st.wHour = hours;
											st.wMinute = minutes;
											st.wSecond = seconds;
											GetLocalTime(&st_now);

											FILETIME ft, ft_now;
											SystemTimeToFileTime(&st, &ft);
											SystemTimeToFileTime(&st_now, &ft_now);
											
											LARGE_INTEGER li, li_now;
											li.HighPart = ft.dwHighDateTime; li.LowPart = ft.dwLowDateTime;
											li_now.HighPart = ft_now.dwHighDateTime; li_now.LowPart = ft_now.dwLowDateTime;

											long diff = (long)((li_now.QuadPart - li.QuadPart) / (LONGLONG)10000000L);
											int y = diff / 60 / 60 / 24 / 365;
											int d = (diff - y * 60 * 60 * 24 * 365) / 60 / 60 / 24;
											int h = (diff - y * 60 * 60 * 24 * 365 - d * 60 * 60 * 24) / 60 / 60;
											int m = (diff - y * 60 * 60 * 24 * 365  - d * 60 * 60 * 24 - h * 60 * 60) / 60;
											if (y != 0)
												mir_sntprintf(buff, bufflen, TranslateT("%dy %dd %dh %dm"), y, d, h, m);
											else if (d != 0)
												mir_sntprintf(buff, bufflen, TranslateT("%dd %dh %dm"), d, h, m);
											else if (h != 0)
												mir_sntprintf(buff, bufflen, TranslateT("%dh %dm"), h, m);
											else
												mir_sntprintf(buff, bufflen, TranslateT("%dm"), m);

											return buff;
										} 
										else
											db_free(&dbv);
									}
								} 
								else
									db_free(&dbv);
							}
						} 
						else
							db_free(&dbv);
					}
				} 
				else
					db_free(&dbv);
			}
		} 
		else
			db_free(&dbv);
	}
	return 0;
}

TCHAR *DayMonthToDaysToNextBirthday(MCONTACT hContact, const char *szModuleName, const char *szPrefix, TCHAR *buff, int bufflen) 
{
	DBVARIANT dbv;
	char szSettingName[256];
	mir_snprintf(szSettingName, _countof(szSettingName), "%sDay", szPrefix);
	if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
	{
		int day = 0;
		if (GetInt(dbv, &day))
		{
			db_free(&dbv);
			mir_snprintf(szSettingName, _countof(szSettingName), "%sMonth", szPrefix);
			int month = 0;
			if (!db_get(hContact, szModuleName, szSettingName, &dbv)) 
			{
				if (GetInt(dbv, &month)) 
				{
					db_free(&dbv);
					time_t now = time(NULL);
					struct tm *ti = localtime(&now);
					int yday_now = ti->tm_yday;

					ti->tm_mday = day;
					ti->tm_mon = month - 1;
					mktime(ti);

					int yday_birth = ti->tm_yday;
					if (yday_birth < yday_now)
					{
						yday_now -= 365;
						yday_now -= (ti->tm_year % 4) ? 0 : 1; 
					}

					int diff = yday_birth - yday_now;
					mir_sntprintf(buff, bufflen, TranslateT("%dd"), diff);
					
					return buff;
				}
				else
				{
					db_free(&dbv);
				}
			}
		} 
		else
		{
			db_free(&dbv);
		}
	}
	return 0;
}


TCHAR *EmptyXStatusToDefaultName(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	TCHAR szDefaultName[1024];
	CUSTOM_STATUS xstatus = {0};
	DBVARIANT dbv;

	// translate jabber mood
	if (ProtoServiceExists(szModuleName, "/SendXML")) // jabber protocol?
	{ 
		if (!db_get_ts(hContact, szModuleName, szSettingName, &dbv))
		{
			_tcsncpy(buff, TranslateTS(dbv.ptszVal), bufflen);
			buff[bufflen - 1] = 0;
			return buff;
		}
	}

	if (NullTranslation(hContact, szModuleName, szSettingName, buff, bufflen))
	   return buff;
	
	int status = db_get_b(hContact, szModuleName, "XStatusId", 0);
	if (!status) return 0;
	
	if (ProtoServiceExists(szModuleName, PS_GETCUSTOMSTATUSEX))
	{ 
		xstatus.cbSize = sizeof(CUSTOM_STATUS);
		xstatus.flags = CSSF_MASK_NAME | CSSF_DEFAULT_NAME | CSSF_TCHAR;
		xstatus.ptszName = szDefaultName;
		xstatus.wParam = (WPARAM *)&status;
		if (CallProtoService(szModuleName, PS_GETCUSTOMSTATUSEX, 0, (LPARAM)&xstatus))
		   return 0;
		
		_tcsncpy(buff, TranslateTS(szDefaultName), bufflen);
		buff[bufflen - 1] = 0;
		return buff;
	} 

	return 0;
}

TCHAR *TimezoneToTime(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	int timezone = db_get_b(hContact,szModuleName,szSettingName,256);
	if (timezone==256 || (char)timezone==-100) 
		return 0;

	TIME_ZONE_INFORMATION tzi;
	FILETIME ft;
	LARGE_INTEGER lift;
	SYSTEMTIME st;

	timezone=(char)timezone;
	GetSystemTimeAsFileTime(&ft);
	if (GetTimeZoneInformation(&tzi) == TIME_ZONE_ID_DAYLIGHT)
		timezone += tzi.DaylightBias / 30;

	lift.QuadPart = *(__int64*)&ft;
	lift.QuadPart -= (__int64)timezone * BIGI(30) * BIGI(60) * BIGI(10000000);
	*(__int64*)&ft = lift.QuadPart;
	FileTimeToSystemTime(&ft, &st);
	GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, NULL, buff, bufflen);

	return buff;
}

TCHAR *ByteToDay(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	int iDay = db_get_w(hContact, szModuleName, szSettingName, -1);
	if (iDay > -1 && iDay < 7)
	{
		a2t(Translate(days[iDay]), buff, bufflen);
		buff[bufflen - 1] = 0;
		return buff;
	}

	return 0;
}

TCHAR *ByteToMonth(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	int iMonth = db_get_w(hContact, szModuleName, szSettingName, 0);
	if (iMonth > 0 && iMonth < 13) 
	{
		a2t(Translate(months[iMonth - 1]), buff, bufflen);
		buff[bufflen - 1] = 0;
		return buff;
	}

	return 0;
}

TCHAR *ByteToLanguage(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) 
{
	int iLang = db_get_b(hContact, szModuleName, szSettingName, 0);
	if (iLang)
	{
		for (int i = 0; i < _countof(languages); i++)
		{
			if (iLang == languages[i].id)
			{
				a2t(Translate(languages[i].szValue), buff, bufflen);
				buff[bufflen - 1] = 0;
				return buff;
			}
		}
	}

	return 0;
}

INT_PTR ServiceAddTranslation(WPARAM wParam, LPARAM lParam) 
{
	if (!lParam) return 1;

	DBVTranslation *trans = (DBVTranslation *)lParam;
	AddTranslation(trans);

	return 0;
}

static DBVTranslation internalTranslations[] = 
{
	{	NullTranslation,               LPGENT("[No translation]")                                                },
	{	WordToStatusDesc,              LPGENT("WORD to status description")                                      },
	{	TimestampToTime,               LPGENT("DWORD timestamp to time")                                         },
	{	TimestampToTimeDifference,     LPGENT("DWORD timestamp to time difference")                              },
	{	ByteToYesNo,                   LPGENT("BYTE to Yes/No")                                                  },
	{	ByteToGender,                  LPGENT("BYTE to Male/Female (ICQ)")                                       },
	{	WordToCountry,                 LPGENT("WORD to country name")                                            },
	{	DwordToIp,                     LPGENT("DWORD to IP address")                                             },
	{	DayMonthYearToDate,            LPGENT("<prefix>Day|Month|Year to date")                                  },
	{  DayMonthYearToAge,             LPGENT("<prefix>Day|Month|Year to age")                                   },
	{	HoursMinutesSecondsToTime,     LPGENT("<prefix>Hours|Minutes|Seconds to time")                           },
	{	DmyToTimeDifference,           LPGENT("<prefix>Day|Month|Year|Hours|Minutes|Seconds to time difference") },
	{	DayMonthToDaysToNextBirthday,  LPGENT("<prefix>Day|Month to days to next birthday")                      },
	{	TimestampToTimeNoSecs,         LPGENT("DWORD timestamp to time (no seconds)")                            },
	{	HoursMinutesToTime,            LPGENT("<prefix>Hours|Minutes to time")                                   },
	{	TimestampToShortDate,          LPGENT("DWORD timestamp to date (short)")                                 },
	{	TimestampToLongDate,           LPGENT("DWORD timestamp to date (long)")                                  },
	{	EmptyXStatusToDefaultName,     LPGENT("xStatus: empty xStatus name to default name")                     },
	{	SecondsToTimeDifference,       LPGENT("DWORD seconds to time difference")                                },
	{	TimezoneToTime,                LPGENT("BYTE timezone to time")                                           },
	{	ByteToDay,                     LPGENT("WORD to name of a day (0..6, 0 is Sunday)")                       },
	{	ByteToMonth,                   LPGENT("WORD to name of a month (1..12, 1 is January)")                   },
	{	ByteToLanguage,                LPGENT("BYTE to language (ICQ)")                                          },
};

void InitTranslations() 
{
	dwNextFuncId = db_get_dw(0, MODULE_ITEMS, "NextFuncId", 1);
	for (int i = 0; i < _countof(internalTranslations); i++)
		AddTranslation(&internalTranslations[i]);

	hServiceAdd = CreateServiceFunction(MS_TIPPER_ADDTRANSLATION, ServiceAddTranslation);
}

void DeinitTranslations()
{
	DestroyServiceFunction(hServiceAdd);
	mir_free(translations);
}