┌──────────────────────────────────────────────────────────────────────┐ │Externalize PII from the executable module and load an appropriate PII│ │according to the current locale. │ └──────────────────────────────────────────────────────────────────────┘
In order to determine which language PII should be used, you can use the current locale name by the setlocale() and the nl_langinfo() functions (Determining an Environment).
PII of each language may be stored in:
The resource files and IPF files are good examples of the former case. The
sample program of this primer searches a subdirectory whose name is the
same as the current locale (language and territory). Then the program loads
the resource file, which has been created as the .DLL, by the DosLoadModule()
API. LoadingGUIresourcefiles( XPRMMAIN . C )
... static char *prodLocale, *custLocale, *curLocale; /* locale information*/ static char acDriveName[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z' }; ... /*****************************************************************************/ /* loadResource() */ /* Query the current disk & path name and generate the qualified file */ /* name of the resource file. If loading the resource is failed, it */ /* loads the default resource. */ /*****************************************************************************/ static Boolean loadResource( char* pszResFile ) { int i; APIRET ret; ULONG ulDriveNum=0; ULONG ulDriveMap=0; ULONG ulLength = 253; char acCurDir[256]; DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap ); for( i=0; i<26; i++ ) { if( (i+1) == ulDriveNum ) acCurDir[0] = acDriveName[i]; } acCurDir[1] = ':'; acCurDir[2] = '\\'; DosQueryCurrentDir( 0L, &acCurDir[3], &ulLength ); strcpy( pszResFile, acCurDir ); strcat( pszResFile, "\\" ); strcat( pszResFile, curLocale ); strcat( pszResFile, pszResName ); if( DosLoadModule( NULL, 0, pszResFile, &hModRsrc ) != 0 ) { strcpy( pszResFile, acCurDir ); strcat( pszResFile, pszDefRes ); if( (ret=DosLoadModule( NULL, 0, pszResFile, &hModRsrc )) != 0 ) { logError( ERR_LOAD_RESOURCE, MPFROMLONG(ret) ); return FALSE; } } return TRUE; }
Storing PII of each language into one data file is not recommended because it may require change in the application logic if the supported languages are added. However, this will be useful for supporting the dual languages, one is the national language and the other is English. This English facility is welcomed by users working at foreign-capitalized companies operating in Asian countries.
In the sample program, the products data and customers data files store both the national language data and the corresponding English data.