hxlang.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:12k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35.  
  36. #include "hxtypes.h"
  37. #include "hxlang.h"
  38. #include "hlxclib/string.h"
  39. #include "hxstrutl.h"
  40. #include "hxheap.h"
  41. #ifdef _DEBUG
  42. #undef HX_THIS_FILE
  43. static const char HX_THIS_FILE[] = __FILE__;
  44. #endif
  45. const HXLangMapping CHXLang::Languages[] =
  46. {
  47. #ifdef _WINDOWS        
  48. {"af",MAKELANGID(LANG_AFRIKAANS,SUBLANG_NEUTRAL)},
  49. {"sq",MAKELANGID(LANG_ALBANIAN,SUBLANG_NEUTRAL)},
  50. {"ar",MAKELANGID(LANG_ARABIC,SUBLANG_NEUTRAL)},
  51. {"ar-DZ",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_ALGERIA)},
  52. {"ar-BH",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_BAHRAIN)},
  53. {"ar-EG",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_EGYPT)},
  54. {"ar-JO",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_JORDAN)},
  55. {"ar-KW",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_KUWAIT)},
  56. {"ar-LB",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_LEBANON)},
  57. {"ar-MA",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_MOROCCO)},
  58. {"ar-OM",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_OMAN)},
  59. {"ar-QA",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_QATAR)},
  60. {"ar-SA",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_SAUDI_ARABIA)},
  61. {"ar-TN",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_TUNISIA)},
  62. {"ar-AE",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_UAE)},
  63. {"ar-YE",MAKELANGID(LANG_ARABIC,SUBLANG_ARABIC_YEMEN)},
  64. {"hy",MAKELANGID(LANG_ARMENIAN,SUBLANG_NEUTRAL)},
  65. {"as",MAKELANGID(LANG_ASSAMESE,SUBLANG_NEUTRAL)},
  66. {"az",MAKELANGID(LANG_AZERI,SUBLANG_AZERI_LATIN)},
  67. {"az",MAKELANGID(LANG_AZERI,SUBLANG_AZERI_CYRILLIC)},
  68. {"eu",MAKELANGID(LANG_BASQUE,SUBLANG_NEUTRAL)},
  69. {"be",MAKELANGID(LANG_BELARUSIAN,SUBLANG_NEUTRAL)},
  70. {"bn",MAKELANGID(LANG_BENGALI,SUBLANG_NEUTRAL)},
  71. {"bg",MAKELANGID(LANG_BULGARIAN,SUBLANG_NEUTRAL)},
  72. {"ca",MAKELANGID(LANG_CATALAN,SUBLANG_NEUTRAL)},
  73. {"cs",MAKELANGID(LANG_CZECH,SUBLANG_NEUTRAL)},
  74. {"da",MAKELANGID(LANG_DANISH,SUBLANG_NEUTRAL)},
  75. {"de-AT",MAKELANGID(LANG_GERMAN,SUBLANG_GERMAN_AUSTRIAN)},
  76. {"de-CH",MAKELANGID(LANG_GERMAN,SUBLANG_GERMAN_SWISS)},
  77. {"de-LI",MAKELANGID(LANG_GERMAN,SUBLANG_GERMAN_LIECHTENSTEIN)},
  78. {"de-LU",MAKELANGID(LANG_GERMAN,SUBLANG_GERMAN_LUXEMBOURG)},
  79. {"de",MAKELANGID(LANG_GERMAN,SUBLANG_NEUTRAL)},
  80. {"el",MAKELANGID(LANG_GREEK,SUBLANG_NEUTRAL)},
  81. {"en-AU",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_AUS)},
  82. {"en-BZ",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_BELIZE)},
  83. {"en-CA",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_CAN)},
  84. {"en",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_CARIBBEAN)},
  85. {"en-GB",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_UK)},
  86. {"en-IE",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_EIRE)},
  87. {"en-JM",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_JAMAICA)},
  88. {"en-NZ",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_NZ)},
  89. {"en-TT",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_TRINIDAD)},
  90. #endif /* _WINDOWS */
  91. {"en-US",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US)},
  92. #ifdef _WINDOWS        
  93. {"en-ZA",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_SOUTH_AFRICA)},
  94. {"en-PH",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_PHILIPPINES)},
  95. {"en-ZW",MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_ZIMBABWE)},
  96. {"en",MAKELANGID(LANG_ENGLISH,SUBLANG_NEUTRAL)},
  97. {"fa",MAKELANGID(LANG_FARSI,SUBLANG_NEUTRAL)},
  98. {"es-AR",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_ARGENTINA)},
  99. {"es-BO",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_BOLIVIA  )},
  100. {"es-CL",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_CHILE    )},
  101. {"es-CO",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_COLOMBIA )},
  102. {"es-CR",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_COSTA_RICA)},
  103. {"es-DO",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_DOMINICAN_REPUBLIC)},
  104. {"es-EC",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_ECUADOR  )},
  105. {"es-GT",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_GUATEMALA  )},
  106. {"es-HN",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_HONDURAS )},
  107. {"es-MX",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_MEXICAN    )},
  108. {"es-NI",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_NICARAGUA)},
  109. {"es-PA",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_PANAMA     )},
  110. {"es-PE",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_PERU     )},
  111. {"es-PR",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_PUERTO_RICO)},
  112. {"es-PY",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_PARAGUAY )},
  113. {"es-SV",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_EL_SALVADOR)},
  114. {"es-UY",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_URUGUAY  )},
  115. {"es-VE",MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_VENEZUELA)},
  116. {"es",MAKELANGID(LANG_SPANISH,SUBLANG_NEUTRAL)},
  117. {"et",MAKELANGID(LANG_ESTONIAN,SUBLANG_NEUTRAL)},
  118. {"fi",MAKELANGID(LANG_FINNISH,SUBLANG_NEUTRAL)},
  119. {"fo",MAKELANGID(LANG_FAEROESE,SUBLANG_NEUTRAL)},
  120. {"fr-BE",MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH_BELGIAN)},
  121. {"fr-CA",MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH_CANADIAN)},
  122. {"fr-CH",MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH_SWISS)},
  123. {"fr-LU",MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH_LUXEMBOURG)},
  124. {"fr-MC",MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH_MONACO)},
  125. {"fr",MAKELANGID(LANG_FRENCH,SUBLANG_NEUTRAL)},
  126. {"mk",MAKELANGID(LANG_MACEDONIAN,SUBLANG_NEUTRAL)},
  127. {"ka",MAKELANGID(LANG_GEORGIAN,SUBLANG_NEUTRAL)},
  128. {"gu",MAKELANGID(LANG_GUJARATI,SUBLANG_NEUTRAL)},
  129. {"he",MAKELANGID(LANG_HEBREW,SUBLANG_NEUTRAL)},
  130. {"hi",MAKELANGID(LANG_HINDI,SUBLANG_NEUTRAL)},
  131. {"hr",MAKELANGID(LANG_CROATIAN,SUBLANG_NEUTRAL)},
  132. {"hu",MAKELANGID(LANG_HUNGARIAN,SUBLANG_NEUTRAL)},
  133. {"id",MAKELANGID(LANG_INDONESIAN,SUBLANG_NEUTRAL)},
  134. {"is",MAKELANGID(LANG_ICELANDIC,SUBLANG_NEUTRAL)},
  135. {"it-CH",MAKELANGID(LANG_ITALIAN,SUBLANG_ITALIAN_SWISS)},
  136. {"it",MAKELANGID(LANG_ITALIAN,SUBLANG_NEUTRAL)},
  137. {"ja",MAKELANGID(LANG_JAPANESE,SUBLANG_NEUTRAL)},
  138. {"ko",MAKELANGID(LANG_KOREAN,SUBLANG_NEUTRAL)},
  139. {"kn",MAKELANGID(LANG_KANNADA,SUBLANG_NEUTRAL)},
  140. {"kk",MAKELANGID(LANG_KAZAK,SUBLANG_NEUTRAL)},
  141. {"lt",MAKELANGID(LANG_LITHUANIAN,SUBLANG_NEUTRAL)},
  142. {"lv",MAKELANGID(LANG_LATVIAN,SUBLANG_NEUTRAL)},
  143. {"ms",MAKELANGID(LANG_MALAY,SUBLANG_MALAY_BRUNEI_DARUSSALAM)},
  144. {"ms",MAKELANGID(LANG_MALAY,SUBLANG_MALAY_MALAYSIA)},
  145. {"ml",MAKELANGID(LANG_MALAYALAM,SUBLANG_NEUTRAL)},
  146. {"mr",MAKELANGID(LANG_MARATHI,SUBLANG_NEUTRAL)},
  147. {"ne",MAKELANGID(LANG_NEPALI,SUBLANG_NEUTRAL)},
  148. {"nl-BE",MAKELANGID(LANG_DUTCH,SUBLANG_DUTCH_BELGIAN)},
  149. {"nl",MAKELANGID(LANG_DUTCH,SUBLANG_NEUTRAL)},
  150. {"no",MAKELANGID(LANG_NORWEGIAN,SUBLANG_NEUTRAL)},
  151. {"nb-no",MAKELANGID(LANG_NORWEGIAN,SUBLANG_NORWEGIAN_BOKMAL)},
  152. {"nn-no",MAKELANGID(LANG_NORWEGIAN,SUBLANG_NORWEGIAN_NYNORSK)},
  153. {"or",MAKELANGID(LANG_ORIYA,SUBLANG_NEUTRAL)},
  154. {"pa",MAKELANGID(LANG_PUNJABI,SUBLANG_NEUTRAL)},
  155. {"sa",MAKELANGID(LANG_SANSKRIT,SUBLANG_NEUTRAL)},
  156. {"pl",MAKELANGID(LANG_POLISH,SUBLANG_NEUTRAL)},
  157. {"pt-BR",MAKELANGID(LANG_PORTUGUESE,SUBLANG_PORTUGUESE_BRAZILIAN)},
  158. {"pt",MAKELANGID(LANG_PORTUGUESE,SUBLANG_NEUTRAL)},
  159. {"ro",MAKELANGID(LANG_ROMANIAN,SUBLANG_NEUTRAL)},
  160. {"ru",MAKELANGID(LANG_RUSSIAN,SUBLANG_NEUTRAL)},
  161. {"sk",MAKELANGID(LANG_SLOVAK,SUBLANG_NEUTRAL)},
  162. {"sl",MAKELANGID(LANG_SLOVENIAN,SUBLANG_NEUTRAL)},
  163. {"sr",MAKELANGID(LANG_SERBIAN,SUBLANG_SERBIAN_CYRILLIC)},
  164. {"sr",MAKELANGID(LANG_SERBIAN,SUBLANG_SERBO_CROATIAN_LATIN)},
  165. {"sw",MAKELANGID(LANG_SWAHILI,SUBLANG_NEUTRAL)},
  166. {"sv-FI",MAKELANGID(LANG_SWEDISH,SUBLANG_SWEDISH_FINLAND)},
  167. {"sv",MAKELANGID(LANG_SWEDISH,SUBLANG_NEUTRAL)},
  168. {"ta",MAKELANGID(LANG_TAMIL,SUBLANG_NEUTRAL)},
  169. {"tt",MAKELANGID(LANG_TATAR,SUBLANG_NEUTRAL)},
  170. {"te",MAKELANGID(LANG_TELUGU,SUBLANG_NEUTRAL)},
  171. {"th",MAKELANGID(LANG_THAI,SUBLANG_NEUTRAL)},
  172. {"tr",MAKELANGID(LANG_TURKISH,SUBLANG_NEUTRAL)},
  173. {"uk",MAKELANGID(LANG_UKRAINIAN,SUBLANG_NEUTRAL)},
  174. {"ur",MAKELANGID(LANG_URDU,SUBLANG_NEUTRAL)},
  175. {"uz",MAKELANGID(LANG_UZBEK,SUBLANG_UZBEK_CYRILLIC)},
  176. {"uz",MAKELANGID(LANG_UZBEK,SUBLANG_UZBEK_LATIN)},
  177. {"vi",MAKELANGID(LANG_VIETNAMESE,SUBLANG_NEUTRAL)},
  178. {"zh-CN",MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED)},
  179. {"zh-HK",MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_HONGKONG)},
  180. {"zh-SG",MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SINGAPORE)},
  181. {"zh-MO",MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_MACAU)},
  182. {"zh-TW",MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_TRADITIONAL)},
  183. {"zh",MAKELANGID(LANG_CHINESE,SUBLANG_NEUTRAL)}
  184. #endif /* _WINDOWS */        
  185. };
  186. /////////////////////////////////////////////////////////////////
  187. // Given a languageID (defined in olenls.h), this returns the
  188. // index of the exact language, or -1 if not found.
  189. INT16 CHXLang::FindExact(UINT16 nLangID)
  190. {
  191. INT16 nIdx=0;
  192. for (nIdx=0; nIdx<GetCount(); nIdx++ )
  193. {
  194. if (Languages[nIdx].nLangID == nLangID)
  195. break;
  196. }
  197. if (nIdx==GetCount())
  198. nIdx=-1;
  199. return(nIdx);
  200. }
  201. /////////////////////////////////////////////////////////////////
  202. // Given a languageID (defined in olenls.h), this returns the
  203. // index of the exact language, or -1 if not found.
  204. INT16 CHXLang::FindExact(const char* szISO639)
  205. {
  206. if (szISO639==NULL) return(-1);
  207. INT16 nIdx=0;
  208. for (nIdx=0; nIdx<GetCount(); nIdx++ )
  209. {
  210. if (!stricmp(Languages[nIdx].szISO639,szISO639))
  211. break;
  212. }
  213. if (nIdx==GetCount())
  214. nIdx=-1;
  215. return(nIdx);
  216. }
  217. /////////////////////////////////////////////////////////////////
  218. // Given a languageID (defined in olenls.h), this returns the
  219. // index of the closest matching language, or -1
  220. INT16 CHXLang::FindClosest(UINT16 nLangID)
  221. {
  222. INT16 nIdx = FindExact(nLangID);
  223. // didn't find exact match?
  224. if (nIdx==-1)
  225. {
  226. // On non windows system we always just return english for now. 
  227. #ifdef _WINDOWS        
  228. UINT16 nNeutral = MAKELANGID(PRIMARYLANGID(nLangID), SUBLANG_NEUTRAL);
  229. #else
  230. UINT16 nNeutral = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
  231. #endif        
  232. if (nNeutral != nLangID)
  233. {
  234. nIdx = FindExact(nLangID);
  235. }
  236. }
  237. return(nIdx);
  238. }
  239. /////////////////////////////////////////////////////////////////
  240. // Given an index from 0 to GetCount()-1 ...
  241. const char* CHXLang::GetISO639(INT16 nIndex)
  242. {
  243. if (IsValidIndex(nIndex))
  244. return(Languages[nIndex].szISO639);
  245. return(NULL);
  246. }
  247. /////////////////////////////////////////////////////////////////
  248. // Given an index from 0 to GetCount()-1 ...
  249. UINT16 CHXLang::GetLangID(INT16 nIndex)
  250. {
  251. if (IsValidIndex(nIndex))
  252. return(Languages[nIndex].nLangID);
  253. return(0);
  254. }
  255. /////////////////////////////////////////////////////////////////
  256. // Returns the # of langauges in the static database
  257. INT16 CHXLang::GetCount()
  258. {
  259. return(sizeof(Languages)/sizeof(HXLangMapping));
  260. }