Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

570 lines
14 KiB

  1. <% '==================================================
  2. ' Microsoft Server Appliance
  3. '
  4. ' Sets language based on browser settings
  5. '
  6. ' Copyright (c) Microsoft Corporation. All rights reserved.
  7. '================================================== %>
  8. <%
  9. Dim objLocalMgr
  10. Dim iBrowserLangID
  11. Dim arrLangDisplayNames,arrLangISONames, arrLangCharSets
  12. Dim arrLangCodePages, arrLangIDs
  13. Const strLANGIDName = "LANGID"
  14. Const ConstDword = 1
  15. on error resume next
  16. set objLocalMgr = Server.CreateObject("ServerAppliance.LocalizationManager")
  17. If Err.number <> 0 Then
  18. If ( Err.number = &H800401F3 ) Then
  19. Response.Write("Unable to locate a software component on the Server Appliance. ")
  20. Response.Write("The Server Appliance core software components do not appear to be installed correctly.")
  21. Else
  22. Response.Write("Server.CreateObject(ServerAppliance.LocalizationManager) failed with error code: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  23. End If
  24. Call SA_TraceOut("SH_TASK", "Server.CreateObject(ServerAppliance.LocalizationManager) failed with error code: " + CStr(Hex(Err.Number)) )
  25. Response.End
  26. End If
  27. '
  28. ' set the locale EVERYTIME
  29. ' This can cause an error if the LCID is not available, in that case we don't touch the locale
  30. Call SetLCID()
  31. on error goto 0
  32. If Not objLocalMgr.fAutoConfigDone Then
  33. Dim strBrowserLang
  34. Dim iCurLang, iCurLangID
  35. on error resume next
  36. iCurLang = objLocalMgr.GetLanguages(arrLangDisplayNames, arrLangISONames, arrLangCharSets, arrLangCodePages, arrLangIDs)
  37. iCurLangID = arrLangIDs(iCurLang)
  38. 'Err.Clear 'Here getting -2147467259 Error
  39. strBrowserLang = getBrowserLanguage()
  40. iBrowserLangID = isSupportedLanguage(strBrowserLang)
  41. If iBrowserLangID <> 0 Then
  42. 'Browser Language and Current Language "LANGID" might be diiferent..
  43. Call ExecuteTask1(Hex(iBrowserLangID), Hex(iCurLangID))
  44. End if
  45. If SA_IsDebugEnabled() Then
  46. on error goto 0
  47. End If
  48. End if
  49. '
  50. ' set the code page EVERYTIME
  51. '
  52. 'Session.CodePage = objLocalMgr.CurrentCodePage
  53. ' Hard coded for Unicode (UTF-8) codepage
  54. Session.CodePage = 65001
  55. Set objLocalMgr = Nothing
  56. '----------------------------------------------------------------------------
  57. '
  58. ' Function : getBroswerLanguage
  59. '
  60. ' Synopsis : Serves in getting Browser Default Language ID
  61. '
  62. ' Arguments: None
  63. '
  64. ' Returns : ISO 693 name
  65. '
  66. '----------------------------------------------------------------------------
  67. Function getBrowserLanguage
  68. Err.Clear
  69. Dim strAcceptLanguage
  70. Dim iPos
  71. strAcceptLanguage = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
  72. iPos = InStr(1, strAcceptLanguage, ",")
  73. If iPos > 0 Then
  74. strAcceptLanguage = Left(strAcceptLanguage, iPos - 1)
  75. End If
  76. getBrowserLanguage = LCase(strAcceptLanguage)
  77. End Function
  78. '----------------------------------------------------------------------------
  79. '
  80. ' Function : isSupportedLanguage
  81. '
  82. ' Synopsis : checks whether the given language is supported by framework,
  83. ' if yes returns the lang id else returns 0
  84. '
  85. ' Arguments: strBrowserLang(IN) - ISO Name of Language
  86. '
  87. ' Returns : Language ID
  88. '
  89. '----------------------------------------------------------------------------
  90. Function isSupportedLanguage(strBrowserLang)
  91. Err.Clear
  92. Dim name
  93. Dim iIndex
  94. Dim ISOName
  95. Dim iLangID
  96. iIndex=0
  97. iLangID = 0
  98. '
  99. ' Chinese Hong Kong or Macau selects Chinese traditional
  100. '
  101. If ("zh-hk" = strBrowserLang) Or ("zh-mo" = strBrowserLang) Then
  102. strBrowserLang = "zh-tw"
  103. End If
  104. for each ISOName in arrLangISONames
  105. If ISOName = strBrowserLang Then
  106. iLangID = arrLangIDs(iIndex)
  107. Exit for
  108. End if
  109. iIndex = iIndex + 1
  110. next
  111. ' If we did not get a match for the full name try the short name
  112. If ((0 = iLangID) AND (Len(strBrowserLang) > 2)) Then
  113. iIndex=0
  114. strBrowserLang = Left(strBrowserLang, 2)
  115. for each ISOName in arrLangISONames
  116. If ISOName = strBrowserLang Then
  117. iLangID = arrLangIDs(iIndex)
  118. Exit for
  119. End if
  120. iIndex = iIndex + 1
  121. next
  122. End If
  123. isSupportedLanguage = iLangID
  124. End Function
  125. '----------------------------------------------------------------------------
  126. '
  127. ' Function : ExecuteTask1
  128. '
  129. ' Synopsis : Executes the ChangeLanguage task
  130. '
  131. ' Arguments: strLangID(IN) - The LANGID as a string
  132. ' strCurrentLangID(IN) - The current LANGID as a string
  133. '
  134. ' Returns : true/false for success/failure
  135. '
  136. '----------------------------------------------------------------------------
  137. Function ExecuteTask1(ByVal strLangID, ByVal strCurrentLangID)
  138. Err.Clear
  139. on error resume next
  140. Dim objTaskContext,objAS,rc
  141. Dim objSL
  142. Dim sReturnURL
  143. Dim sURL
  144. Const strMethodName = "ChangeLanguage"
  145. Set objTaskContext = CreateObject("Taskctx.TaskContext")
  146. If Err.Number <> 0 Then
  147. ExecuteTask1 = FALSE
  148. Exit Function
  149. End If
  150. Set objAS = CreateObject("Appsrvcs.ApplianceServices")
  151. If Err.Number <> 0 Then
  152. ExecuteTask1 = FALSE
  153. Exit Function
  154. End If
  155. objTaskContext.SetParameter "Method Name", strMethodName
  156. objTaskContext.SetParameter "LanguageID", strLANGID
  157. objTaskContext.SetParameter "AutoConfig", "y"
  158. If Err.Number <> 0 Then
  159. ExecuteTask1 = FALSE
  160. Exit Function
  161. End If
  162. objAS.Initialize()
  163. If Err.Number <> 0 Then
  164. ExecuteTask1 = FALSE
  165. Exit Function
  166. End If
  167. rc = objAS.ExecuteTask("ChangeLanguage", objTaskContext)
  168. If Err.Number <> 0 Then
  169. ExecuteTask1 = FALSE
  170. Exit Function
  171. End If
  172. 'objAS.Shutdown
  173. 'If Err.Number <> 0 Then
  174. ' If Err.Number <> 438 Then 'error 438 shutdown is not supported..
  175. ' ExecuteTask1 = FALSE
  176. ' Exit Function
  177. ' End if
  178. 'End If
  179. Err.Clear
  180. Set objTaskContext = Nothing
  181. If (strLangID <> strCurrentLangID) Then
  182. Set objSL = Server.CreateObject("SetSystemLocale.SetSystemLocale")
  183. If Err.Number <> 0 Then
  184. 'SA_TraceOut "autoconfiglang.asp", "Create SetSystemLocale.SetSystemLocale failed: " + CStr(Hex(Err.Number))
  185. ExecuteTask1 = FALSE
  186. objAS.Shutdown
  187. Set objAS = Nothing
  188. Exit Function
  189. End If
  190. objSL.SetLocale strLangID
  191. If ( Err.Number <> 0 ) Then
  192. 'SA_TraceOut "autoconfiglang.asp", "objSL.SetLocale failed" + CStr(Hex(Err.Number))
  193. ExecuteTask1 = FALSE
  194. objAS.Shutdown
  195. Set objAS = Nothing
  196. Exit Function
  197. End If
  198. Set objSL = Nothing
  199. Call RaiseLangChangeAlert(objAS)
  200. End If
  201. objAS.Shutdown
  202. Set objAS = Nothing
  203. ExecuteTask1 = TRUE
  204. End Function
  205. Private Function RaiseLangChangeAlert(ByRef oAppServices)
  206. Err.Clear
  207. on error resume next
  208. Const SA_ALERT_CLASS = "Microsoft_SA_Resource"
  209. Const SA_ALERT_DURATION_ETERNAL = 2147483647
  210. Const SA_ALERT_TYPE_WARNING = 0
  211. Const SA_ALERT_TYPE_FAILURE = 1
  212. Const SA_ALERT_TYPE_INFORMATION = 2
  213. Const SA_ALERT_NORMAL = 0
  214. Const SA_ALERT_SINGLETON = 1
  215. Const AUTOLANGCONFIG_LOG = "AutoLangConfig"
  216. Const AUTOLANGCONFIG_ALERT_RestartRequired = 1
  217. Dim rawData
  218. Dim nullRepStrings
  219. '
  220. ' Raise Alert
  221. '
  222. Call oAppServices.RaiseAlertEx(SA_ALERT_TYPE_WARNING, _
  223. AUTOLANGCONFIG_ALERT_RestartRequired, _
  224. AUTOLANGCONFIG_LOG, _
  225. SA_ALERT_CLASS, _
  226. SA_ALERT_DURATION_ETERNAL, _
  227. nullRepStrings, _
  228. rawData, _
  229. SA_ALERT_SINGLETON)
  230. End Function
  231. %>
  232. <SCRIPT Runat=Server Language=VBScript>
  233. Sub SetLCID()
  234. Dim strLCID
  235. Select Case getBrowserLanguage
  236. Case "af"
  237. strLCID = 1078 ' Afrikaans
  238. Case "sq"
  239. strLCID = 1052 ' Albanian
  240. Case "ar-sa"
  241. strLCID = 1025 ' Arabic(Saudi Arabia)
  242. Case "ar-iq"
  243. strLCID = 2049 ' Arabic(Iraq)
  244. Case "ar-eg"
  245. strLCID = 3073 ' Arabic(Egypt)
  246. Case "ar-ly"
  247. strLCID = 4097 ' Arabic(Libya)
  248. Case "ar-dz"
  249. strLCID = 5121 ' Arabic(Algeria)
  250. Case "ar-ma"
  251. strLCID = 6145 ' Arabic(Morocco)
  252. Case "ar-tn"
  253. strLCID = 7169 ' Arabic(Tunisia)
  254. Case "ar-om"
  255. strLCID = 8193 ' Arabic(Oman)
  256. Case "ar-ye"
  257. strLCID = 9217 ' Arabic(Yemen)
  258. Case "ar-sy"
  259. strLCID = 10241 ' Arabic(Syria)
  260. Case "ar-jo"
  261. strLCID = 11265 ' Arabic(Jordan)
  262. Case "ar-lb"
  263. strLCID = 12289 ' Arabic(Lebanon)
  264. Case "ar-kw"
  265. strLCID = 13313 ' Arabic(Kuwait)
  266. Case "ar-ae"
  267. strLCID = 14337 ' Arabic(U.A.E.)
  268. Case "ar-bh"
  269. strLCID = 15361 ' Arabic(Bahrain)
  270. Case "ar-qa"
  271. strLCID = 16385 ' Arabic(Qatar)
  272. Case "eu"
  273. strLCID = 1069 ' Basque
  274. Case "bg"
  275. strLCID = 1026 ' Bulgarian
  276. Case "be"
  277. strLCID = 1059 ' Belarusian
  278. Case "ca"
  279. strLCID = 1027 ' Catalan
  280. Case "zh-tw"
  281. strLCID = 1028 ' Chinese(Taiwan)
  282. Case "zh-cn"
  283. strLCID = 2052 ' Chinese(PRC)
  284. Case "zh-hk"
  285. strLCID = 3076 ' Chinese(Hong Kong)
  286. Case "zh-sg"
  287. strLCID = 4100 ' Chinese(Singapore)
  288. Case "hr"
  289. strLCID = 1050 ' Croatian
  290. Case "cs"
  291. strLCID = 1029 ' Czech
  292. Case "da"
  293. strLCID = 1030 ' Danish
  294. Case "n"
  295. strLCID = 1043 ' Dutch(Standard)
  296. Case "nl-be"
  297. strLCID = 2067 ' Dutch(Belgian)
  298. Case "en"
  299. strLCID = 1033 ' English
  300. Case "en-us"
  301. strLCID = 1033 ' English(United States)
  302. Case "en-gb"
  303. strLCID = 2057 ' English(British)
  304. Case "en-au"
  305. strLCID = 3081 ' English(Australian)
  306. Case "en-ca"
  307. strLCID = 4105 ' English(Canadian)
  308. Case "en-nz"
  309. strLCID = 5129 ' English(New Zealand)
  310. Case "en-ie"
  311. strLCID = 6153 ' English(Ireland)
  312. Case "en-za"
  313. strLCID = 7177 ' English(South Africa)
  314. Case "en-jm"
  315. strLCID = 8201 ' English(Jamaica)
  316. Case "en"
  317. strLCID = 9225 ' English(Caribbean)
  318. Case "en-bz"
  319. strLCID = 10249 ' English(Belize)
  320. Case "en-tt"
  321. strLCID = 11273 ' English(Trinidad)
  322. Case "et"
  323. strLCID = 1061 ' Estonian
  324. Case "fo"
  325. strLCID = 1080 ' Faeroese
  326. Case "fa"
  327. strLCID = 1065 ' Farsi
  328. Case "fi"
  329. strLCID = 1035 ' Finnish
  330. Case "fr"
  331. strLCID = 1036 ' French(Standard)
  332. Case "fr-be"
  333. strLCID = 2060 ' French(Belgian)
  334. Case "fr-ca"
  335. strLCID = 3084 ' French(Canadian)
  336. Case "fr-ch"
  337. strLCID = 4108 ' French(Swiss)
  338. Case "fr-lu"
  339. strLCID = 5132 ' French(Luxembourg)
  340. Case "gd"
  341. strLCID = 1084 ' Gaelic(Scots)
  342. Case "gd-ie"
  343. strLCID = 2108 ' Gaelic(Irish)
  344. Case "de"
  345. strLCID = 1031 ' German(Standard)
  346. Case "de-ch"
  347. strLCID = 2055 ' German(Swiss)
  348. Case "de-at"
  349. strLCID = 3079 ' German(Austrian)
  350. Case "de-lu"
  351. strLCID = 4103 ' German(Luxembourg)
  352. Case "de-li"
  353. strLCID = 5127 ' German(Liechtenstein)
  354. Case "e"
  355. strLCID = 1032 ' Greek
  356. Case "he"
  357. strLCID = 1037 ' Hebrew
  358. Case "hi"
  359. strLCID = 1081 ' Hindi
  360. Case "hu"
  361. strLCID = 1038 ' Hungarian
  362. Case "is"
  363. strLCID = 1039 ' Icelandic
  364. Case "in"
  365. strLCID = 1057 ' Indonesian
  366. Case "it"
  367. strLCID = 1040 ' Italian(Standard)
  368. Case "it-ch"
  369. strLCID = 2064 ' Italian(Swiss)
  370. Case "ja"
  371. strLCID = 1041 ' Japanese
  372. Case "ko"
  373. strLCID = 1042 ' Korean
  374. Case "ko"
  375. strLCID = 2066 ' Korean(Johab)
  376. Case "lv"
  377. strLCID = 1062 ' Latvian
  378. Case "lt"
  379. strLCID = 1063 ' Lithuanian
  380. Case "mk"
  381. strLCID = 1071 ' Macedonian
  382. Case "ms"
  383. strLCID = 1086 ' Malaysian
  384. Case "mt"
  385. strLCID = 1082 ' Maltese
  386. Case "no"
  387. strLCID = 1044 ' Norwegian(Bokmal)
  388. Case "no"
  389. strLCID = 2068 ' Norwegian(Nynorsk)
  390. Case "p"
  391. strLCID = 1045 ' Polish
  392. Case "pt-br"
  393. strLCID = 1046 ' Portuguese(Brazilian)
  394. Case "pt"
  395. strLCID = 2070 ' Portuguese(Standard)
  396. Case "rm"
  397. strLCID = 1047 ' Rhaeto-Romanic
  398. Case "ro"
  399. strLCID = 1048 ' Romanian
  400. Case "ro-mo"
  401. strLCID = 2072 ' Romanian(Moldavia)
  402. Case "ru"
  403. strLCID = 1049 ' Russian
  404. Case "ru-mo"
  405. strLCID = 2073 ' Russian(Moldavia)
  406. Case "sz"
  407. strLCID = 1083 ' Sami(Lappish)
  408. Case "sr"
  409. strLCID = 3098 ' Serbian(Cyrillic)
  410. Case "sr"
  411. strLCID = 2074 ' Serbian(Latin)
  412. Case "sk"
  413. strLCID = 1051 ' Slovak
  414. Case "s"
  415. strLCID = 1060 ' Slovenian
  416. Case "sb"
  417. strLCID = 1070 ' Sorbian
  418. Case "es"
  419. strLCID = 1034 ' Spanish(Spain - Traditional Sort)
  420. Case "es-mx"
  421. strLCID = 2058 ' Spanish(Mexican)
  422. Case "es"
  423. strLCID = 3082 ' Spanish(Spain - Modern Sort)
  424. Case "es-gt"
  425. strLCID = 4106 ' Spanish(Guatemala)
  426. Case "es-cr"
  427. strLCID = 5130 ' Spanish(Costa Rica)
  428. Case "es-pa"
  429. strLCID = 6154 ' Spanish(Panama)
  430. Case "es-do"
  431. strLCID = 7178 ' Spanish(Dominican Republic)
  432. Case "es-ve"
  433. strLCID = 8202 ' Spanish(Venezuela)
  434. Case "es-co"
  435. strLCID = 9226 ' Spanish(Colombia)
  436. Case "es-pe"
  437. strLCID = 10250 ' Spanish(Peru)
  438. Case "es-ar"
  439. strLCID = 11274 ' Spanish(Argentina)
  440. Case "es-ec"
  441. strLCID = 12298 ' Spanish(Ecuador)
  442. Case "es-c"
  443. strLCID = 13322 ' Spanish(Chile)
  444. Case "es-uy"
  445. strLCID = 14346 ' Spanish(Uruguay)
  446. Case "es-py"
  447. strLCID = 15370 ' Spanish(Paraguay)
  448. Case "es-bo"
  449. strLCID = 16394 ' Spanish(Bolivia)
  450. Case "es-sv"
  451. strLCID = 17418 ' Spanish(El Salvador)
  452. Case "es-hn"
  453. strLCID = 18442 ' Spanish(Honduras)
  454. Case "es-ni"
  455. strLCID = 19466 ' Spanish(Nicaragua)
  456. Case "es-pr"
  457. strLCID = 20490 ' Spanish(Puerto Rico)
  458. Case "sx"
  459. strLCID = 1072 ' Sutu
  460. Case "sv"
  461. strLCID = 1053 ' Swedish
  462. Case "sv-fi"
  463. strLCID = 2077 ' Swedish(Finland)
  464. Case "th"
  465. strLCID = 1054 ' Thai
  466. Case "ts"
  467. strLCID = 1073 ' Tsonga
  468. Case "tn"
  469. strLCID = 1074 ' Tswana
  470. Case "tr"
  471. strLCID = 1055 ' Turkish
  472. Case "uk"
  473. strLCID = 1058 ' Ukrainian
  474. Case "ur"
  475. strLCID = 1056 ' Urdu
  476. Case "ve"
  477. strLCID = 1075 ' Venda
  478. Case "vi"
  479. strLCID = 1066 ' Vietnamese
  480. Case "xh"
  481. strLCID = 1076 ' Xhosa
  482. Case "ji"
  483. strLCID = 1085 ' Yiddish
  484. Case "zu"
  485. strLCID = 1077 ' Zulu
  486. Case Else
  487. strLCID = 2048 ' default
  488. End Select
  489. Session.LCID = strLCID
  490. End Sub
  491. </SCRIPT>