-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathlang.c
52 lines (44 loc) · 1.05 KB
/
lang.c
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
/* Language base - this contains the language detector function */
#include <windows.h>
#include <wchar.h>
#include <string.h>
#include "lang.h"
enum {
LANG_EN_US = 0,
LANG_ZH_TW = 1,
};
int lang_index;
const WCHAR *lang_tbl[][N_ELEMS] =
{
//ID 0: English
{
#include "lang_en-us.h"
},
//ID 1: Chinese (Traditional)
{
#include "lang_zh-tw.h"
},
};
void detectLanguage(int argc, WCHAR **argv) {
LANGID lang;
int offs;
//append "_en" to exe name to force English
offs = wcslen(argv[0]) - 7;
if(0 == _wcsicmp(argv[0]+offs, L"_en.exe"))
lang_index = LANG_EN_US;
//append "_zh" to exe name to force Chinese
else if(0 == _wcsicmp(argv[0]+offs, L"_zh.exe"))
lang_index = LANG_ZH_TW;
//otherwise, follow the system preferred language settings
else {
lang = GetUserDefaultUILanguage();
if((lang & 0x0ff) == 0x04)
//xx04 => some form of Chinese; we only have 1 Chinese translation, so use that for all Chinese locales
lang_index = LANG_ZH_TW;
else
lang_index = LANG_EN_US;
}
}
const WCHAR* TR(int id) {
return lang_tbl[lang_index][id];
}