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.

173 lines
4.4 KiB

  1. <% '==================================================
  2. ' Microsoft Server Appliance
  3. '
  4. ' Sets language based on browser settings
  5. '
  6. ' Copyright (c) 1999 - 2000 Microsoft Corporation. All rights reserved.
  7. '================================================== %>
  8. <%
  9. On Error Resume Next
  10. Dim objLocalMgr
  11. Dim iBrowserLangID
  12. Dim arrLangDisplayNames,arrLangISONames, arrLangCharSets
  13. Dim arrLangCodePages, arrLangIDs
  14. Const strLANGIDName = "LANGID"
  15. Const ConstDword = 1
  16. set objLocalMgr = Server.CreateObject("ServerAppliance.LocalizationManager")
  17. If Not objLocalMgr.fAutoConfigDone Then
  18. Dim strBrowserLang
  19. Dim iCurLang, iCurLangID
  20. iCurLang = objLocalMgr.GetLanguages(arrLangDisplayNames, arrLangISONames, arrLangCharSets, arrLangCodePages, arrLangIDs)
  21. iCurLangID = arrLangIDs(iCurLang)
  22. 'Err.Clear 'Here getting -2147467259 Error
  23. strBrowserLang = getBroswerLanguage()
  24. iBrowserLangID = isSupportedLanguage(strBrowserLang)
  25. If iBrowserLangID <> 0 Then
  26. 'Browser Language and Current Language "LANGID" are diiferent..
  27. ExecuteTask1(Hex(iBrowserLangID))
  28. End if
  29. End if
  30. '
  31. ' set the code page EVERYTIME
  32. '
  33. Session.CodePage = objLocalMgr.CurrentCodePage
  34. Set objLocalMgr = Nothing
  35. '----------------------------------------------------------------------------
  36. '
  37. ' Function : getBroswerLanguage
  38. '
  39. ' Synopsis : Serves in getting Browser Default Language ID
  40. '
  41. ' Arguments: None
  42. '
  43. ' Returns : LANGID
  44. '
  45. '----------------------------------------------------------------------------
  46. Function getBroswerLanguage
  47. On Error Resume Next
  48. Err.Clear
  49. getBroswerLanguage = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
  50. getBroswerLanguage = Left(getBroswerLanguage, 2)
  51. End Function
  52. '----------------------------------------------------------------------------
  53. '
  54. ' Function : isSupportedLanguage
  55. '
  56. ' Synopsis : checks whether the given language is supported by framework,
  57. ' if yes returns the lang id else returns 0
  58. '
  59. ' Arguments: strBrowserLang(IN) - ISO Name of Language
  60. '
  61. ' Returns : Language ID
  62. '
  63. '----------------------------------------------------------------------------
  64. Function isSupportedLanguage(strBrowserLang)
  65. On Error Resume Next
  66. Err.Clear
  67. Dim name
  68. Dim iIndex
  69. Dim ISOName
  70. iIndex=0
  71. isSupportedLanguage = 0
  72. for each ISOName in arrLangISONames
  73. If ISOName = strBrowserLang Then
  74. isSupportedLanguage = arrLangIDs(iIndex)
  75. Exit for
  76. End if
  77. iIndex = iIndex + 1
  78. next
  79. End Function
  80. '----------------------------------------------------------------------------
  81. '
  82. ' Function : ExecuteTask1
  83. '
  84. ' Synopsis : Executes the ChangeLanguage task
  85. '
  86. ' Arguments: strLangID(IN) - The LANGID as a string
  87. '
  88. ' Returns : true/false for success/failure
  89. '
  90. '----------------------------------------------------------------------------
  91. Function ExecuteTask1(strLangID)
  92. On Error Resume Next
  93. Err.Clear
  94. Dim objTaskContext,objAS,rc
  95. Const strMethodName = "ChangeLanguage"
  96. Set objTaskContext = CreateObject("Taskctx.TaskContext")
  97. If Err.Number <> 0 Then
  98. ExecuteTask1 = FALSE
  99. Exit Function
  100. End If
  101. Set objAS = CreateObject("Appsrvcs.ApplianceServices")
  102. If Err.Number <> 0 Then
  103. ExecuteTask1 = FALSE
  104. Exit Function
  105. End If
  106. objTaskContext.SetParameter "Method Name", strMethodName
  107. objTaskContext.SetParameter "LanguageID", strLANGID
  108. objTaskContext.SetParameter "AutoConfig", "y"
  109. If Err.Number <> 0 Then
  110. ExecuteTask1 = FALSE
  111. Exit Function
  112. End If
  113. objAS.Initialize()
  114. If Err.Number <> 0 Then
  115. ExecuteTask1 = FALSE
  116. Exit Function
  117. End If
  118. rc = objAS.ExecuteTask("ChangeLanguage", objTaskContext)
  119. If Err.Number <> 0 Then
  120. ExecuteTask1 = FALSE
  121. Exit Function
  122. End If
  123. objAS.Shutdown
  124. If Err.Number <> 0 Then
  125. If Err.Number <> 438 Then 'error 438 shutdown is not supported..
  126. ExecuteTask1 = FALSE
  127. Exit Function
  128. End if
  129. End If
  130. Set objAS = Nothing
  131. Set objTaskContext = Nothing
  132. ExecuteTask1 = TRUE
  133. End Function
  134. %>