I have a resource file which has two String Tables.Both contain same String
IDs.But the String values are different.The first one is in French-canadian
language and the other one is in English - US.
My application uses LoadString() method to load the string from the String
table by giving the String ID.At this time This method will automatically
read the Locale of the System(Regional Settings) and take the relevent
language String table and retrive the corresponding Language String values.
My requirement is to retrieve the language strings not by reading the Local
System's Regional Settings.I need to retrieve the Language Strings from
the String Table depending upon my parameters(Country,Language) which I will
be getting externally(Coming from remote clients ).Why this is required is
because my application is running as a Server and I need to get the language
Strings depending on the clients Locale information and pass it the Client.
I have tried setting the locale by
setLocale() method
but the loadString method doesn't get affected by this.
We even tried setting the registry keys(All the items under
HKEY_CURRENT_USER\Control Panel\International)
Still No Use.
Please HELP
Thanks
Shaj Manohar
Kshema Technologies ltd.
shaj.m...@kshema.com
Second of all, claiming you need to change the locale of the system to
internationalize an application is like claiming you need to tear down and
rebuild a house to support the new paint color. You MUST respect user
settings here.
There is a documented technique for loading strings and other resources for
other locales, starting with FindResourceEx. You really need to not consider
changing locale to make this happen as it is NOT your choice what the user's
settings are; it is theirs.
Internationalization (i18n) is not a process of battering a user into
submission to meet your criteria; it is working with their preferences.
You might want to try dumping most of the groups you have posted to, trying:
microsoft.public.platformsdk.localization
microsoft.public.win32.programmer.international
instead.
--
MichKa
random junk of dubious value at the multilingual
http://www.trigeminal.com/ and a new book on
i18N in VB at http://www.trigeminal.com/michka.asp
"Deepa" <deepala...@kshema.com> wrote in message
news:#ZUdEJhAAHA.1580@cpmsftngp03...
I had to get onto Microsoft to explain how to do this :)
Bellow is the Functions that I use to Load a specific String from a
Sepcific String Table :-
---------
////////////////////////////////////////////////////////////////////////////////////////////
// FUNCTION : FindCurrentLanguage
// FUNCTIONALITY : Used to find out the current run time
language of the main application
// : so that a resource string can be loaded from
the correct MAKELANGID
// Written By : Marcus.
// DATE WRITTEN : June 1998
////////////////////////////////////////////////////////////////////////////////////////////
WORD FindCurrentLanguage(void)
{
#define KEY "Language"
HKEY regKey;
TCHAR path[_MAX_PATH];
TCHAR currentLanguage[100];
DWORD sizeOfData;
DWORD disposition;
WORD langId;
int error = 0;
int val = -1;
// The MAKELANGID macro creates a language identifier from a
// primary language identifier and a sublanguage identifier.
// set the langId to a default of english
langId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK);
_tcscpy(path, g_RegPath);
// add the language key on to the end
_tcscat(path,"\\");
_tcscat(path,KEY);
// open the registry at the language bit path
error = RegCreateKeyEx(HKEY_LOCAL_MACHINE, path, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
®Key, &disposition);
// okay so its valid
if (error == ERROR_SUCCESS)
{
// read the value of the language key
sizeOfData = sizeof(currentLanguage);
error = RegQueryValueEx(regKey, _T(KEY),NULL, NULL,(BYTE
*)currentLanguage, &sizeOfData);
}
// Close key, if this fails, do nothing
RegCloseKey(regKey);
// find out what the language is
if (currentLanguage[0])
{
if(!(_tcsicmp(currentLanguage, "English(British)")))
val = 0;
else if(!(_tcsicmp(currentLanguage, "German")))
val = 1;
else if(!(_tcsicmp(currentLanguage, "Japanese")))
val = 2;
}
// find the correct language id
switch(val)
{
case 0:
langId = MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_UK);
break;
case 1:
langId = MAKELANGID(LANG_GERMAN,SUBLANG_GERMAN);
break;
case 2:
langId = MAKELANGID(LANG_JAPANESE,SUBLANG_DEFAULT);
break;
default:
langId = MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_UK);
break;
}
// return the result of makelangid
return langId;
}
////////////////////////////////////////////////////////////////////////////////////////////
// FUNCTION : GetText
// FUNCTIONALITY : Used to load a string from a string table
dependant on the current
// : and the string specified language
// Written By : Marcus.
// DATE WRITTEN : June 1998
////////////////////////////////////////////////////////////////////////////////////////////
int GetText(UINT resourceID,TCHAR *stringLoad, DWORD sizeOfString)
{
#define StringBlock 16
static WORD language = 0;
HRSRC hRes;
HGLOBAL hLoad;
LPVOID lpLock;
WCHAR* pStr;
int nLenStr, i, len, err; // The size
of each string we extract.
int blockNumber, position;
// If this is the first time this function has been entered,
look up
// which language has been selected during installation
if(!language)
{
// Get the language the user selected during
installation
// taken from a registry value added during
installation
language = FindCurrentLanguage();
// If nothing is returned, default to English
if(!language)
language = MAKELANGID(LANG_ENGLISH,
SUBLANG_ENGLISH_UK);
}
if(hInst)
{
// find out which block the thing is in
blockNumber = resourceID / StringBlock;
// add one to the block number
blockNumber++;
//get the position of the string in the block
position = resourceID % StringBlock;
// okay lets find the block
// If this fails the first try, try with the default
language (UK)
// This is needed if user asks for Japanese but the pc
can not handle it (err code 120)
if (!(hRes = FindResourceEx(hInst, RT_STRING,
MAKEINTRESOURCE(blockNumber), language)))
{
language = MAKELANGID(LANG_ENGLISH,
SUBLANG_ENGLISH_UK);
hRes = FindResourceEx(hInst, RT_STRING,
MAKEINTRESOURCE(blockNumber), language);
}
// Try again, if this fails this time an unknown error
has occured
if (hRes)
{
// load the block of strings
hLoad = LoadResource(hInst, hRes);
// put in memory
lpLock = LockResource(hLoad);
// Now try loading the string.
pStr = (WCHAR *)lpLock;
// loop through finding the string in the
// ource blockloaded res
for(i = 0; i < position; i++ )
{
nLenStr = (int)( *pStr++ );
pStr += nLenStr;
}
// get the length of the string
nLenStr = ( int )( *pStr++ );
// set the size of the string to the correct size
if ((UINT)nLenStr > sizeOfString)
{
nLenStr++; // increment by one
sizeOfString = nLenStr;
return FALSE; // return false
}
#ifdef UNICODE
_tcsncpy(stringLoad, pStr, nLenStr);
stringLoad[nLenStr] = '\0';
//Don't use the variable "len" in the UNICODE
build - so we do this to remove the compiler warning.
len;
#else
// Convert the wide char string into multi
byte and pass back as stringload
len = WideCharToMultiByte(CP_ACP, 0, pStr,
nLenStr, stringLoad, 256, NULL, NULL);
stringLoad[len] = '\0';
#endif
return TRUE;
}
else
err = GetLastError();
}
return FALSE;
}
Hope This Helps
Orion
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnic...@geocities.com
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Michael (michka) Kaplan" <forme...@spamfree.trigeminal.nospam.com> wrote
in message news:OthAdNhAAHA.248@cppssbbsa04...
--
MichKa
random junk of dubious value at the multilingual
http://www.trigeminal.com/ and a new book on
i18N in VB at http://www.trigeminal.com/michka.asp
"Alexander Nickolov" <agnic...@geocities.com> wrote in message
news:ePMkffjAAHA.195@cppssbbsa04...