// Loads text overrides from the given module. They must be in a "L10N" resource with ID=1
void LoadTranslationOverrides( HMODULE hModule )
{
	HRSRC hResInfo=FindResource(hModule,MAKEINTRESOURCE(1),L"L10N");
	if (hResInfo)
	{
		g_TranslationOverrides.LoadText(hModule,hResInfo);
		g_TranslationOverrides.ParseText();
	}
}
// Parses the settings from an ini file. Supports UTF16, UTF8 or ANSI files
// Use forceLang for force a specific language
void ParseTranslations( const wchar_t *fname, const wchar_t *forceLang )
{
	g_Translations.Reset();

	if (fname)
	{
		if (!g_Translations.LoadText(fname)) return;
		g_Translations.ParseText();
	}

	wchar_t languages[100]={0};
	if (forceLang && *forceLang)
	{
		int len=(int)wcslen(forceLang);
		if (len>5) len=5;
		memcpy(languages,forceLang,len*2);
		wcscpy_s(languages+len+1,10,L"default");
	}
	else
	{
		ULONG size=4; // up to 4 languages
		ULONG len=_countof(languages);
		GetThreadPreferredUILanguages(MUI_LANGUAGE_NAME,&size,languages,&len);
		wcscpy_s(languages+len-1,10,L"default");
		languages[len+7]=0;
	}

	g_Translations.FilterLanguages(languages);

	// Checks for right-to-left languages
	g_bRTL=false;
	LOCALESIGNATURE localesig;
	LANGID language=GetUserDefaultUILanguage();
	if (forceLang && *forceLang)
	{
		if (GetLocaleInfoEx(forceLang,LOCALE_FONTSIGNATURE,(LPWSTR)&localesig,(sizeof(localesig)/sizeof(wchar_t))) && (localesig.lsUsb[3]&0x08000000))
			g_bRTL=true;
	}
	else
	{
		if (GetLocaleInfoW(language,LOCALE_FONTSIGNATURE,(LPWSTR)&localesig,(sizeof(localesig)/sizeof(wchar_t))) && (localesig.lsUsb[3]&0x08000000))
			g_bRTL=true;
	}
}
Beispiel #3
0
int ExtractStrings( const wchar_t *dllName, const wchar_t *csvName )
{
	HMODULE hDLL=LoadLibraryEx(dllName,NULL,LOAD_LIBRARY_AS_DATAFILE|LOAD_LIBRARY_AS_IMAGE_RESOURCE);
	if (!hDLL)
	{
		Printf("Failed to open %S (err: %d)\n",dllName,GetLastError());
		return 1;
	}

	int res=1;
	CSettingsParser parser;
	parser.LoadText(L"LocComments.txt");
	parser.ParseText();

	HANDLE hCSV=CreateFile(csvName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
	if (hCSV==INVALID_HANDLE_VALUE)
	{
		Printf("Failed to write %S\n",csvName);
		CloseHandle(hDLL);
		return 1;
	}

	wchar_t title[]=L"\xFEFFID\tEnglish\tTranslation\tComment\r\n";
	DWORD q;
	WriteFile(hCSV,title,Strlen(title)*2,&q,NULL);

	// copy strings
	for (int i=2000;i<6000;i+=16)
	{
		int id=i/16;
		HRSRC hResInfo=FindResource(hDLL,MAKEINTRESOURCE(id),RT_STRING);
		if (!hResInfo) continue;
		HGLOBAL hRes=LoadResource(hDLL,hResInfo);
		void *pRes=LockResource(hRes);
		if (!pRes) continue;
		const WORD *data=(WORD*)pRes;
		for (int j=0;j<16;j++)
		{
			int len=*data;
			if (len>0)
				WriteString(hCSV,(id-1)*16+j,(const wchar_t*)data+1,len,parser);
			data+=len+1;
		}
	}

	HWND parent=CreateWindow(L"button",NULL,WS_POPUP,0,0,10,10,NULL,NULL,NULL,NULL);

	// copy dialogs
	for (int id=2000;id<4010;id++)
	{
		if (id>=2010 && id<3000) continue;
		if (id>=3010 && id<4000) continue;
		HRSRC hResInfo=FindResource(hDLL,MAKEINTRESOURCE(id),RT_DIALOG);
		if (!hResInfo) continue;
		HGLOBAL hRes=LoadResource(hDLL,hResInfo);
		void *pRes=LockResource(hRes);
		if (!pRes) continue;
		WriteDialog(parent,hCSV,id,hDLL,(DLGTEMPLATE*)pRes,parser);
	}

	// additional strings
	{
		HRSRC hResInfo=FindResource(hDLL,MAKEINTRESOURCE(1),L"L10N");
		if (hResInfo)
		{
			HGLOBAL hRes=LoadResource(hDLL,hResInfo);
			const wchar_t *pRes=(wchar_t*)LockResource(hRes);
			if (pRes)
			{
				int size=SizeofResource(hDLL,hResInfo)/2;
				if (*pRes==L'\xFEFF')
					pRes++, size--;
				wchar_t *pBuf=new wchar_t[size+1];
				memcpy(pBuf,pRes,size*2);
				pBuf[size]=0;
				for (int i=0;i<size;i++)
					if (pBuf[i]=='=')
						pBuf[i]='\t';
				WriteFile(hCSV,pBuf,size*2,&q,NULL);
			}
		}
	}

	CloseHandle(hCSV);
	DestroyWindow(parent);
	if (hDLL) FreeLibrary(hDLL);

	return res;
}