[Amis-devl] The design of the class LanguageCodeFormat
Brought to you by:
julienq,
marisademeglio
From: Sahira B. <sah...@ya...> - 2004-11-26 08:48:38
|
Hi all, The following is the design of the class LanguageCodeFormat.If anybody has any suggestions then please reply. Synopsis: This class is used to convert language code specification given in RFC 3066 to langID specified in windows platform. class LanguageCodeFormat In the class create four arrays as follows. 1. PrimaryLangCode: an array of char* type to hold primary language codes. this should store three digit codes. see www.w3.org/WAI/ER/IG/ert/iso639.htm for a complete listing. 2. PrimaryLangID: an array of int type to hold primary language IDentifiers as defined in MSDN mostly found in msdn 2003 > development (general) > Internationalization > SDK Documentation > International Text Display > National Language Support > National Language Support Reference > National Language Support Constants > Primary Language Identifiers. 3. SecondaryLangCode: an array of char* type to hold secondary codes, which is for the country code, and should store three digit codes. see userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html for complete listing. 4. SecondaryLangID: an array of int type to hold Secondary language IDentifiers as defined in MSDN mostly found in msdn 2003 > development (general) > Internationalization > SDK Documentation > International Text Display > National Language Support > National Language Support Reference > National Language Support Constants > secondary Language Identifiers. Array 1 and 2 and array 3 and 4 should be index simitrical, i.e. index for a langCode in array 1 should match with the index for the same langID for array 2. Initialize all the arrays in the constructor of the class. For language codes, initialize the array with lower case characters and for country codes, initialize the array with upper case characters. Because this is the recommended specification by the corresponding standard bodies, but we will be doing case insensitive search. Make sure that the codes are stored in asending alphabetacal order because we will be doing binary search on them. Four variables which will be filled during the processing: 1. primaryLangCodeValue: a variable of string type to hold primary language part of the language code. 2. primaryLangIDValue: a variable of int type to hold primary language part of the language ID 3. secondaryLangCodeValue: a variable of string type to hold secondary language part of the language code. 4. secondaryLangIDValue: a variable of string type to hold secondary language part of the language ID. Find or write a binary sort function to match a string in form of char* or string with a given array of char*. using the above function, find a langID from a given langCode the flow is as follows. For primaryLangCodeValue, do binary search in the primaryLangCode array and if the value is found, at the same index where the item is found, get the langID from the primaryLangID array. For secondaryLangCodeValue, do binary search in the secondaryLangCode array and if the value is found, at the same index where the item is found, get the langID from the secondaryLangID array. ---------------------------------------------------------- once above mentioned setup is ready, the regular working of the operation is to lookup the langID from the given langCode. We will have a function to do that, which is defined below. LangIDFromLangCode(char* langCode) look for "-" in the langCode if "-" is found, then store first part of the langCode which occurs before the "-" in primaryLangCodeValue after converting it to lower case and second part in the secondaryLangCodeValue after converting to upper case. using the binary function, look for the langID for the primaryLangCodeValue. if found, store it in PrimaryLangIDValue else store the default primary langID in primaryLangIDValue. then using the binary function, look for the langID for the secondaryLangCodeValue. if found, store it in secondaryLangIDValue else store the default secondary langID in secondaryLangIDValue. then create langID with a macro found in windows MAKELANGID from the primaryLangIDValue and secondaryLangIDValue. return this langID in form of a string. if "-" not found, then just store the entire langCode in primaryLangCodeValue after converting it to lower case. using the binary function, look for the langID for the primaryLangCodeValue. if found, store it in PrimaryLangIDValue else store the default primary langID in primaryLangIDValue. store the default secondary langID in secondaryLangIDValue. then create langID with a macro found in windows MAKELANGID from the primaryLangIDValue and secondaryLangIDValue. return this langID in form of a string. Note: 1. While performaing the search, if the length of primary or secondary code is two, only look for two characters in the array, ignore the third character and if the length is three characters, then do full comparison. 2. making language code to lower case and secondary code (country code) to upper case, we will be able to do case insensitive search. end function description end class description. --------------------------------- Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. |